some change
This commit is contained in:
parent
d4a1492d56
commit
313f1def49
38 changed files with 475 additions and 401 deletions
49
src/app/feed/posts/posts.ts
Normal file
49
src/app/feed/posts/posts.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { Temporal } from '@js-temporal/polyfill'
|
||||
import { components } from '../../api/schema.ts'
|
||||
|
||||
export class Post {
|
||||
public readonly postId: string
|
||||
public readonly content: string
|
||||
public readonly media: PostMedia[]
|
||||
public readonly createdAt: Temporal.Instant
|
||||
public readonly authorName: string
|
||||
|
||||
constructor(
|
||||
postId: string,
|
||||
content: string,
|
||||
media: PostMedia[],
|
||||
createdAt: string | Temporal.Instant,
|
||||
authorName: string,
|
||||
) {
|
||||
this.postId = postId
|
||||
this.content = content
|
||||
this.media = media
|
||||
this.createdAt = Temporal.Instant.from(createdAt)
|
||||
this.authorName = authorName
|
||||
}
|
||||
|
||||
public static fromDto(dto: components['schemas']['PublicPostDto']): Post {
|
||||
console.debug('make post', dto)
|
||||
return new Post(
|
||||
dto.postId,
|
||||
dto.content,
|
||||
dto.media.map((m) => new PostMediaImpl(new URL(m.url), m.width, m.height)),
|
||||
Temporal.Instant.from(dto.createdAt),
|
||||
dto.author.username,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export interface PostMedia {
|
||||
readonly url: URL
|
||||
readonly width: number | null
|
||||
readonly height: number | null
|
||||
}
|
||||
|
||||
class PostMediaImpl implements PostMedia {
|
||||
constructor(
|
||||
readonly url: URL,
|
||||
readonly width: number | null,
|
||||
readonly height: number | null,
|
||||
) {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue