All checks were successful
Frontend CI / build (push) Successful in 1m6s
### Description - Change the format of color response ```json { "red": 0, "green": 255, "blue": 128, "alpha": 255 } ``` - The relationship between the label's background color and its highlight color is calculated. The method involves first converting the RGB color value to HSL, then decreasing the L (lightness) component, and finally converting it back to RGB. ### Package Changes ```json { "zod": "^4.0.5" } ``` ### Screenshots |Desktop|Mobile| |-|-| ||| ### Reference Resolves #44 ### Checklist - [x] A milestone is set - [x] The related issuse has been linked to this branch Reviewed-on: #64 Co-authored-by: SquidSpirit <squid@squidspirit.com> Co-committed-by: SquidSpirit <squid@squidspirit.com>
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { LabelResponseDto, LabelResponseSchema } from '$lib/post/adapter/gateway/labelResponseDto';
|
|
import { PostInfo } from '$lib/post/domain/entity/postInfo';
|
|
import z from 'zod';
|
|
|
|
export const PostInfoResponseSchema = z.object({
|
|
id: z.int32(),
|
|
title: z.string(),
|
|
description: z.string(),
|
|
preview_image_url: z.url(),
|
|
labels: z.array(LabelResponseSchema),
|
|
published_time: z.number().int()
|
|
});
|
|
|
|
export class PostInfoResponseDto {
|
|
readonly id: number;
|
|
readonly title: string;
|
|
readonly description: string;
|
|
readonly previewImageUrl: URL;
|
|
readonly labels: readonly LabelResponseDto[];
|
|
readonly publishedTime: Date;
|
|
|
|
private constructor(props: {
|
|
id: number;
|
|
title: string;
|
|
description: string;
|
|
previewImageUrl: URL;
|
|
labels: LabelResponseDto[];
|
|
publishedTime: Date;
|
|
}) {
|
|
this.id = props.id;
|
|
this.title = props.title;
|
|
this.description = props.description;
|
|
this.previewImageUrl = props.previewImageUrl;
|
|
this.labels = props.labels;
|
|
this.publishedTime = props.publishedTime;
|
|
}
|
|
|
|
static fromJson(json: unknown): PostInfoResponseDto {
|
|
const parsedJson = PostInfoResponseSchema.parse(json);
|
|
return new PostInfoResponseDto({
|
|
id: parsedJson.id,
|
|
title: parsedJson.title,
|
|
description: parsedJson.description,
|
|
previewImageUrl: new URL(parsedJson.preview_image_url),
|
|
labels: parsedJson.labels.map((label) => LabelResponseDto.fromJson(label)),
|
|
publishedTime: new Date(parsedJson.published_time / 1000)
|
|
});
|
|
}
|
|
|
|
toEntity(): PostInfo {
|
|
return new PostInfo({
|
|
id: this.id,
|
|
title: this.title,
|
|
description: this.description,
|
|
previewImageUrl: this.previewImageUrl,
|
|
labels: this.labels.map((label) => label.toEntity()),
|
|
publishedTime: this.publishedTime
|
|
});
|
|
}
|
|
}
|