Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' of github.com:Here-You/here-you-backend into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
moonyaeyoon committed Feb 11, 2024
2 parents e3621cf + b68efbb commit 77aa877
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/mate/cursor-page/cursor-page-option.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// cursor-page.options.ts
// cursor-page.options.dto.ts

import { Type } from "class-transformer";
import { IsEnum, IsOptional } from "class-validator";
Expand Down
2 changes: 2 additions & 0 deletions src/response/response-code.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum ResponseCode {
COMMENT_UPDATE_SUCCESS = 'OK',
COMMENT_DELETE_SUCCESS = 'OK',
FOLLOW_SUCCESS = 'OK',
GET_COMMENT_DETAIL_SUCCESS = 'OK',



Expand Down Expand Up @@ -84,6 +85,7 @@ export enum ResponseCode {
GET_USER_PROFILE_FAIL = 'BAD_REQUEST',
COMMENT_UPDATE_FAIL = 'BAD_REQUEST',
COMMENT_DELETE_FAIL = 'BAD_REQUEST',
GET_COMMENT_DETAIL_FAIL = 'BAD_REQUEST',



Expand Down
19 changes: 0 additions & 19 deletions src/rule/dto/comment-pair.dto.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/rule/dto/cursor-page-options-parameter.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CursorPageOptionsDto } from "./cursor-page.options.dto";

export interface CursorPageMetaDtoParameters {
cursorPageOptionsDto: CursorPageOptionsDto;
total: number;
hasNextData: boolean;
cursor: number;
}
4 changes: 4 additions & 0 deletions src/rule/dto/cursor-page-order.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum Order {
ASC = "asc",
DESC = "desc"
}
15 changes: 15 additions & 0 deletions src/rule/dto/cursor-page.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IsArray } from "class-validator";
import { CursorPageMetaDto } from "./cursor-page.meta.dto";

export class CursorPageDto<T> {

@IsArray()
readonly data: T[];

readonly meta: CursorPageMetaDto;

constructor(data: T[], meta: CursorPageMetaDto) {
this.data = data;
this.meta = meta;
}
}
16 changes: 16 additions & 0 deletions src/rule/dto/cursor-page.meta.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { CursorPageMetaDtoParameters } from "./cursor-page-options-parameter.interface";

export class CursorPageMetaDto {

readonly total: number;
readonly take: number;
readonly hasNextData: boolean;
readonly cursor: number;

constructor({cursorPageOptionsDto, total, hasNextData, cursor}: CursorPageMetaDtoParameters) {
this.take = cursorPageOptionsDto.take;
this.total = total;
this.hasNextData = hasNextData;
this.cursor = cursor;
}
}
19 changes: 19 additions & 0 deletions src/rule/dto/cursor-page.options.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Type } from "class-transformer";
import { IsEnum, IsOptional } from "class-validator";
import { Order } from "./cursor-page-order.enum";

export class CursorPageOptionsDto {

@Type(() => String)
@IsEnum(Order)
@IsOptional()
readonly sort?: Order = Order.DESC;

@Type(() => Number)
@IsOptional()
readonly take?: number = 5;

@Type(() => String)
@IsOptional()
readonly cursorId?: number = "" as any;
}
15 changes: 15 additions & 0 deletions src/rule/dto/cursot-page-order.enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IsArray } from "class-validator";
import { CursorPageMetaDto } from "./cursor-page.meta.dto";

export class CursorPageDto<T> {

@IsArray()
readonly data: T[];

readonly meta: CursorPageMetaDto;

constructor(data: T[], meta: CursorPageMetaDto) {
this.data = data;
this.meta = meta;
}
}
11 changes: 0 additions & 11 deletions src/rule/dto/detail-comment.dto.ts

This file was deleted.

23 changes: 23 additions & 0 deletions src/rule/dto/get-comment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {IsDate, IsNotEmpty, IsNumber, IsOptional, IsString} from 'class-validator';

export class GetCommentDto {
@IsNotEmpty()
@IsNumber()
id: number;

@IsNotEmpty()
@IsString()
content: string;

@IsNotEmpty()
@IsDate()
updated: Date;

@IsNotEmpty()
@IsString()
name: string;

@IsOptional()
@IsString()
image: string;
}
40 changes: 33 additions & 7 deletions src/rule/rule.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { ResponseCode } from '../response/response-code.enum';
import { ResponseDto } from '../response/response.dto';
import { UserGuard } from '../user/user.guard';
import { Request } from 'express';
import {FollowSearchDto} from "../follow/dto/follow.search.dto";
import {GetSearchMemberDto} from "./dto/get.search.member.dto";
import {GetSearchMemberDto} from "./dto/get-search-member.dto";
import { UpdateRuleDto } from "./dto/update-rule.dto";
import {CursorPageOptionsDto} from "./dto/cursor-page.options.dto";

@Controller('mate/rule')
export class RuleController {
Expand Down Expand Up @@ -36,7 +36,33 @@ export class RuleController {
}
}

// [2] 여행 규칙 상세 페이지 조회 (게시글)
// [2] 여행 규칙 상세 페이지 조회 (댓글) - 페이지네이션
@Get('/detail/:ruleId')
@UseGuards(UserGuard)
async getComment(@Req() req: Request,
@Param('ruleId') ruleId: number,
@Query() cursorPageOptionsDto: CursorPageOptionsDto
): Promise<ResponseDto<any>> {
try {
const result = await this.ruleService.getComment(cursorPageOptionsDto, ruleId);

return new ResponseDto(
ResponseCode.GET_COMMENT_DETAIL_SUCCESS,
true,
"여행 규칙 상세 페이지 (댓글) 조회 성공",
result
);
} catch (e) {
return new ResponseDto(
ResponseCode.GET_COMMENT_DETAIL_FAIL,
false,
"여행 규칙 상세 페이지 (댓글) 조회 실패",
null
);
}
}

// [3] 여행 규칙 상세 페이지 조회 (게시글)
@Get('/detail/:ruleId')
@UseGuards(UserGuard)
async getDetail(@Req() req: Request, @Param('ruleId') ruleId: number): Promise<ResponseDto<any>> {
Expand All @@ -61,7 +87,7 @@ export class RuleController {
}
}

// [2] 여행 규칙 수정
// [4] 여행 규칙 수정
@Patch('/detail/:ruleId')
@UseGuards(UserGuard)
async updateRule(@Body() updateRuleDto: UpdateRuleDto, @Req() req: Request, @Param('ruleId') ruleId: number): Promise<ResponseDto<any>> {
Expand All @@ -86,7 +112,7 @@ export class RuleController {
}
}

// [3] 여행 규칙 전체 리스트 조회
// [5] 여행 규칙 전체 리스트 조회
@Get('list')
@UseGuards(UserGuard)
async getRuleList(@Req() req: Request): Promise<ResponseDto<any>> {
Expand All @@ -109,7 +135,7 @@ export class RuleController {
}
}

// [3] 여행 규칙 생성
// [6] 여행 규칙 생성
@Post('/write')
@UseGuards(UserGuard)
async createRule(@Req() req: Request, @Body() createRuleDto: CreateRuleDto): Promise<ResponseDto<any>> {
Expand All @@ -132,7 +158,7 @@ export class RuleController {
}
}

// [4] 여행 규칙 참여 멤버로 초대할 메이트 검색 결과
// [7] 여행 규칙 참여 멤버로 초대할 메이트 검색 결과
@Get('/write/search/:ruleId')
@UseGuards(UserGuard)
async getSearchMember(
Expand Down
65 changes: 61 additions & 4 deletions src/rule/rule.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Injectable, HttpException, BadRequestException} from '@nestjs/common';
import {Injectable, HttpException, BadRequestException, HttpStatus} from '@nestjs/common';
import { CreateRuleDto } from './dto/create-rule.dto';
import { RuleMainEntity } from './domain/rule.main.entity';
import { RuleSubEntity } from './domain/rule.sub.entity';
Expand All @@ -9,10 +9,14 @@ import { S3UtilService} from "../utils/S3.service";
import { GetMemberListDto} from "./dto/get-member-list.dto";
import {UserService} from "../user/user.service";
import {GetRuleListDto, MemberPairDto} from "./dto/get-rule-list.dto";
import {Like} from "typeorm";
import {GetSearchMemberDto} from "./dto/get.search.member.dto";
import {LessThan, Like} from "typeorm";
import {GetSearchMemberDto} from "./dto/get-search-member.dto";
import {UpdateRuleDto} from "./dto/update-rule.dto";
import {FollowSearchDto} from "../follow/dto/follow.search.dto";
import {CursorPageOptionsDto} from "../mate/cursor-page/cursor-page-option.dto";
import {CommentEntity} from "../comment/domain/comment.entity";
import {GetCommentDto } from "./dto/get-comment.dto";
import {CursorPageDto} from "./dto/cursor-page.dto";
import {CursorPageMetaDto} from "./dto/cursor-page.meta.dto";

@Injectable()
export class RuleService {
Expand Down Expand Up @@ -108,6 +112,59 @@ export class RuleService {
return dto;
};

// [3] 여행 규칙 상세 페이지 조회 (댓글) - 페이지네이션
async getComment(cursorPageOptionsDto: CursorPageOptionsDto, ruleId: number): Promise<CursorPageDto<GetCommentDto>> {
// (1) 데이터 조회
const [comments, total] = await CommentEntity.findAndCount({
take: cursorPageOptionsDto.take,
where: {
rule: { id: ruleId },
id: cursorPageOptionsDto.cursorId ? LessThan(cursorPageOptionsDto.cursorId) : null,
},
relations: {user:{profileImage: true}},
order: {
id: cursorPageOptionsDto.sort.toUpperCase() as any,
},
});

const result = await Promise.all(comments.map(async (comment) => {
const getCommentDto = new GetCommentDto();

getCommentDto.id = comment.id;
getCommentDto.name = comment.user.name;
getCommentDto.content = comment.content;
getCommentDto.updated = comment.updated;

// 사용자 프로필 이미지
const image = comment.user.profileImage;
if(image == null) getCommentDto.image = null;
else {
const userImageKey = image.imageKey;
getCommentDto.image = await this.s3Service.getImageUrl(userImageKey);
}

return getCommentDto;
}));

// (2) 페이징 및 정렬 기준 설정
const takePerPage = cursorPageOptionsDto.take;
const isLastPage = total <= takePerPage;

let hasNextData = true;
let cursor: number;

if (isLastPage || result.length <= 0) {
hasNextData = false;
cursor = null;
} else {
cursor = result[result.length - 1].id;
}

const cursorPageMetaDto = new CursorPageMetaDto({ cursorPageOptionsDto, total, hasNextData, cursor });

return new CursorPageDto(result, cursorPageMetaDto);
}

// [3] 여행 규칙 나가기
// -1) 초대 받은 팀원 -> 초대 삭제
async deleteInvitation(ruleId: number, userId: number): Promise<RuleInvitationEntity> {
Expand Down

0 comments on commit 77aa877

Please sign in to comment.