Skip to content

Commit

Permalink
feat: define medium model, media repository
Browse files Browse the repository at this point in the history
  • Loading branch information
laminne committed May 29, 2024
1 parent 794a861 commit 832d1a4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
77 changes: 77 additions & 0 deletions pkg/drive/model/medium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { AccountID } from '../../accounts/model/account.js';
import type { ID } from '../../id/type.js';

export type MediumID = string;

export interface CreateMediumArgs {
id: ID<MediumID>;
name: string;
authorID: ID<AccountID>;
hash: string;
mime: string;
nsfw: boolean;
url: string;
thumbnailURL: string;
}

export class Medium {
private constructor(arg: CreateMediumArgs) {
this.id = arg.id;
this.name = arg.name;
this.authorID = arg.authorID;
this.hash = arg.hash;
this.mime = arg.mime;
this.nsfw = arg.nsfw;
this.url = arg.url;
this.thumbnailURL = arg.thumbnailURL;
}

public static new(arg: CreateMediumArgs): Medium {
return new Medium(arg);
}

public static reconstruct(arg: CreateMediumArgs): Medium {
return new Medium(arg);
}

private readonly id: ID<MediumID>;

getID(): ID<MediumID> {
return this.id;
}
private readonly name: string;

getName(): string {
return this.name;
}
private readonly authorID: ID<AccountID>;

getAuthorID(): ID<AccountID> {
return this.authorID;
}
private readonly hash: string;

getHash(): string {
return this.hash;
}
private readonly mime: string;

getMime(): string {
return this.mime;
}
private readonly nsfw: boolean;

isNSFW(): boolean {
return this.nsfw;
}
private readonly url: string;

getURL(): string {
return this.url;
}
private readonly thumbnailURL: string;

getThumbnailURL(): string {
return this.thumbnailURL;
}
}

Check warning on line 77 in pkg/drive/model/medium.ts

View check run for this annotation

Codecov / codecov/patch

pkg/drive/model/medium.ts#L1-L77

Added lines #L1 - L77 were not covered by tests
12 changes: 12 additions & 0 deletions pkg/drive/model/repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Ether, type Option, type Result } from '@mikuroxina/mini-fn';

import type { AccountID } from '../../accounts/model/account.js';
import type { ID } from '../../id/type.js';
import type { Medium, MediumID } from './medium.js';

export interface MediaRepository {
create(medium: Medium): Promise<Result.Result<Error, void>>;
findByID(id: ID<MediumID>): Promise<Option.Option<Medium>>;
findByAuthor(authorID: ID<AccountID>): Promise<Option.Option<Medium[]>>;
}
export const mediaRepoSymbol = Ether.newEtherSymbol<MediaRepository>();

Check warning on line 12 in pkg/drive/model/repository.ts

View check run for this annotation

Codecov / codecov/patch

pkg/drive/model/repository.ts#L1-L12

Added lines #L1 - L12 were not covered by tests

0 comments on commit 832d1a4

Please sign in to comment.