Skip to content

Commit

Permalink
feat: define medium model, media repository (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
laminne authored May 29, 2024
1 parent 794a861 commit ec973a5
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;
}
}
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>();

0 comments on commit ec973a5

Please sign in to comment.