-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define medium model, media repository
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||