Skip to content

Commit

Permalink
feat : 초대장 id 조회, 초대장 상세 조회 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
kangjuhyup committed Nov 6, 2024
1 parent 44e40f3 commit a6c93e0
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 50 deletions.
44 changes: 0 additions & 44 deletions packages/server/src/domain/letter/dto/response/get.detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,40 +93,6 @@ class Image {
ang: number;
}

class Text {
@ApiProperty({
description: '텍스트 본문',
example: 'MOCK',
})
@IsNotEmpty()
@IsString()
body: string;

@ApiProperty({
description: '텍스트 크기',
example: 18,
})
@IsNotEmpty()
@IsNumber()
size: number;

@ApiProperty({
description: '텍스트의 X 좌표',
example: 200,
})
@IsNotEmpty()
@IsNumber()
x: number;

@ApiProperty({
description: '텍스트의 Y 좌표',
example: 600,
})
@IsNotEmpty()
@IsNumber()
y: number;
}

export class GetLetterDetailResponse {
@IsNotEmpty()
@IsString()
Expand Down Expand Up @@ -154,14 +120,4 @@ export class GetLetterDetailResponse {
@ValidateNested({ each: true })
@Type(() => Image)
components?: Image[];

@ApiPropertyOptional({
description: '텍스트 정보 배열',
type: [Text],
})
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => Text)
text?: Text[];
}
65 changes: 65 additions & 0 deletions packages/server/src/domain/letter/dto/response/get.letter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsNotEmpty, IsNumber, IsString, ValidateNested } from "class-validator";

class Letter {
@ApiProperty({
description: '이미지 경로',
example: 'https://example.com/img.png',
})
@IsNotEmpty()
@IsString()
path: string;

@ApiProperty({
description: '이미지 너비',
example: 100,
})
@IsNotEmpty()
@IsNumber()
width: number;

@ApiProperty({
description: '이미지 높이',
example: 80,
})
@IsNotEmpty()
@IsNumber()
height: number;

}

class Comment {
@IsNotEmpty()
@IsString()
name : string
@IsNotEmpty()
@IsString()
body : string
}

export class GetLetterResponse {
@ApiProperty({
description : '초대장 ID',
})
@IsNotEmpty()
@IsNumber()
letterId : number;
@ApiProperty({
description: '배경 이미지 정보',
type: Letter,
})
@ValidateNested()
@Type(() => Letter)
@IsNotEmpty()
letter : Letter

@ApiProperty({
description : '댓글 목록',
type : Array<Comment>
})
@ValidateNested({each:true})
@Type(() => Comment)
@IsNotEmpty()
comments : Array<Comment>
}
26 changes: 21 additions & 5 deletions packages/server/src/domain/letter/letter.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import { GetLetterPageRequest } from './dto/request/get.page';
import { GetLetterPageResponse } from './dto/response/get.page';
import { LetterService } from './service/letter.service';
import { PrepareResponse } from './dto/response/prepare';
import { MetaDefault, MetaDetail, PrepareRequest } from './dto/request/prepare';
import { PrepareRequest } from './dto/request/prepare';
import { AddLetterRequest } from './dto/request/add.letter';
import { AddLetterResponse } from './dto/response/add.letter';
import { GetLetterDetailRequest } from './dto/request/get.detail';
import { GetLetterDetailResponse } from './dto/response/get.detail';
import { ResponseValidationInterceptor } from '@app/interceptor/response.validation';
import { UserGuard } from '@app/jwt/guard/user.guard';
import { GetLetterResponse } from './dto/response/get.letter';

@Controller('letter')
export class LetterController {
Expand Down Expand Up @@ -91,10 +92,7 @@ export class LetterController {
};
}

@Get('share/:id')
@ApiOperation({ summary: '공유된 초대장 페이지' })
// @UseInterceptors(new ResponseValidationInterceptor(ShareLetterResponse))
@Get(':id')
@Get('detail/:id')
@ApiOperation({ summary: '초대장 상세 정보 조회' })
@ApiOkResponse({
status: 200,
Expand All @@ -110,4 +108,22 @@ export class LetterController {
data: await this.letterService.getLetterDetail(dto.id),
};
}

@Get(':id')
@ApiOperation({ summary: '공유된 초대장 페이지' })
@ApiOkResponse({
status : 200,
description : '성공',
type : GetLetterPageResponse
})
@UseInterceptors(new ResponseValidationInterceptor(GetLetterResponse))
async getLetter(
@Param() dto : GetLetterDetailRequest
): Promise<HttpResponse<GetLetterResponse>> {
return {
result : true,
data : await this.letterService.getLetter(dto.id)
}
}

}
17 changes: 16 additions & 1 deletion packages/server/src/domain/letter/service/letter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { AddLetterResponse } from '../dto/response/add.letter';
import { InsertLetterTransaction } from '../transaction/insert.letter';
import { GetLetterPageRequest } from '../dto/request/get.page';
import { GetLetterPageResponse } from '../dto/response/get.page';
import { GetLetterDetailRequest } from '../dto/request/get.detail';
import { GetLetterDetailResponse } from '../dto/response/get.detail';
import { LetterBaseService } from './letter.base.service';
import { LetterAttachmentService } from './letter.attachment.service';
Expand All @@ -18,6 +17,7 @@ import { StorageService } from '@app/storage/storage.service';
import { LetterAttachmentCode } from '@app/util/attachment';
import { randomString } from '@app/util/random';
import { booleanToYN } from '@app/util/yn';
import { GetLetterResponse } from '../dto/response/get.letter';

@Injectable()
export class LetterService extends LetterBaseService {
Expand Down Expand Up @@ -54,6 +54,21 @@ export class LetterService extends LetterBaseService {
};
}

async getLetter(id:number) : Promise<GetLetterResponse> {
const letter = await this.letterRepository.selectLetterFromId({letterId:id})
const lt = letter.letterAttachment.find((la) => la.attachmentCode === LetterAttachmentCode.LETTER);

return {
letterId : letter.letterId,
letter : {
path : lt.attachment.attachmentPath,
width : lt.width,
height : lt.height
},
comments : []
}
}

async getLetterDetail(id: number): Promise<GetLetterDetailResponse> {
const letter = await this.letterRepository.selectLetterFromId({
letterId: id,
Expand Down

0 comments on commit a6c93e0

Please sign in to comment.