Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.3.1",
"@nestjs/mapped-types": "*",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.2.0",
"@nestjs/typeorm": "^10.0.1",
Expand All @@ -34,9 +35,9 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"jsonwebtoken": "^9.0.2",
"mysql2": "^3.9.0",
"multer": "^1.4.5-lts.1",
"multer-s3": "^3.0.1",
"mysql2": "^3.8.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"typeorm": "^0.3.20",
Expand Down
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PlaceModule } from './place/place.module';
import { JourneyModule } from './journey/journey.module';
import { SignatureModule } from './signature/signature.module';
import { RuleModule } from './rule/rule.module';

import { CommentModule } from './comment/comment.module';
import { DetailScheduleModule } from './detail-schedule/detail-schedule.module';
import { S3Module } from './utils/S3.module';

Expand All @@ -31,6 +31,7 @@ import { S3Module } from './utils/S3.module';
JourneyModule,
SignatureModule,
RuleModule,
CommentModule,
S3Module,
],
controllers: [AppController],
Expand Down
36 changes: 36 additions & 0 deletions src/comment/comment.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Controller, Post, Body, Req, UseGuards, Param } from '@nestjs/common';
import { CommentService } from './comment.service';
import { CreateCommentDto } from './dto/create-comment.dto';
import { ResponseCode } from '../response/response-code.enum';
import { ResponseDto } from '../response/response.dto';
// import { UserGuard } from 'src/user/user.guard';

// @UseGuards(UserGuard)
@Controller('mate/rule')
export class CommentController {
constructor(
private readonly commentService: CommentService,
) {}

// 여행 규칙 코멘트 생성
@Post('/:ruleId')
async createComment(@Body() createCommentDto: CreateCommentDto, @Param('ruleId') ruleId: number): Promise<ResponseDto<any>> {
const result = await this.commentService.createComment(createCommentDto, ruleId);

if(!result){
return new ResponseDto(
ResponseCode.COMMENT_CREATION_FAIL,
false,
"여행 규칙 코멘트 생성 실패",
null);

}
else{
return new ResponseDto(
ResponseCode.COMMENT_CREATED,
true,
"여행 규칙 코멘트 생성 성공",
result);
}
}
}
23 changes: 23 additions & 0 deletions src/comment/comment.converter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Injectable } from '@nestjs/common';
import { CommentEntity } from './domain/comment.entity';
import { RuleMainEntity } from 'src/rule/domain/rule.main.entity';
import { UserEntity } from 'src/user/user.entity';
import { CreateCommentDto } from './dto/create-comment.dto';

@Injectable()
export class CommentConverter {

async toEntity(dto: CreateCommentDto, ruleId:number): Promise<CommentEntity> {
const comment = new CommentEntity();

comment.content = dto.content;
console.log(comment.content);
const rule = await RuleMainEntity.findOneOrFail({ where: { id: ruleId } });
comment.rule = rule;
console.log(comment.rule);
const user = await UserEntity.findOneOrFail({ where: { id: dto.userId } });
comment.user = user;

return comment;
}
}
10 changes: 10 additions & 0 deletions src/comment/comment.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { CommentService } from './comment.service';
import { CommentController } from './comment.controller';
import { CommentConverter } from './comment.converter';

@Module({
controllers: [CommentController],
providers: [CommentService, CommentConverter],
})
export class CommentModule {}
19 changes: 19 additions & 0 deletions src/comment/comment.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from '@nestjs/common';
import { CreateCommentDto } from './dto/create-comment.dto';
import { CommentConverter } from './comment.converter';
import { CommentEntity } from './domain/comment.entity';

@Injectable()
export class CommentService {
constructor(
private commentConverter: CommentConverter
) {}

async createComment(createCommentDto: CreateCommentDto, ruleId: number): Promise<number> {
const comment = await this.commentConverter.toEntity(createCommentDto, ruleId);

const savedComment = await CommentEntity.save(comment);

return savedComment.id;
}
}
29 changes: 29 additions & 0 deletions src/comment/domain/comment.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { RuleMainEntity } from 'src/rule/domain/rule.main.entity';
import { UserEntity } from 'src/user/user.entity';

@Entity()
export class CommentEntity extends BaseEntity {
@PrimaryGeneratedColumn({ type: 'bigint' })
id: number;

@Column({ type: 'varchar', length: 255 })
content: string;

@ManyToOne(() => RuleMainEntity, ruleMain => ruleMain.comments)
@JoinColumn({ name: 'rule_id'})
rule: RuleMainEntity;

@ManyToOne(() => UserEntity, user => user.comments)
@JoinColumn({ name: 'user_id'})
user: UserEntity;

@CreateDateColumn({ type: 'timestamp' })
created: Date;

@UpdateDateColumn({ type: 'timestamp' })
updated: Date;

@Column({ type: 'timestamp', nullable: true })
deleted: Date;
}
11 changes: 11 additions & 0 deletions src/comment/dto/create-comment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';

export class CreateCommentDto {
@IsNotEmpty()
@IsNumber()
userId: number;

@IsNotEmpty()
@IsString()
content: string;
}
4 changes: 4 additions & 0 deletions src/response/response-code.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export enum ResponseCode {
GET_SIGNATURE_DETAIL_SUCCESS = 'OK',
DELETE_LIKE_ON_SIGNATURE_SUCCESS = 'OK',
UPDATE_PROFILE_SUCCESS = 'OK',
GET_RULE_DETAIL_SUCCESS = 'OK',


/* 201 CREATED : 요청 성공, 자원 생성 */
SIGNUP_SUCCESS = 'CREATED',
SIGNATURE_CREATED = 'CREATED',
RULE_CREATED = 'CREATED',
LIKE_ON_SIGNATURE_CREATED = 'CREATED',
COMMENT_CREATED = 'CREATED',


/* 400 BAD_REQUEST : 잘못된 요청 */
Expand All @@ -25,6 +27,8 @@ export enum ResponseCode {
SIGNATURE_CREATION_FAIL = 'BAD_REQUEST',
RULE_CREATION_FAIL = 'BAD_REQUEST',
GET_MY_SIGNATURE_FAIL = 'BAD_REQUEST',
COMMENT_CREATION_FAIL = 'BAD_REQUEST',
GET_RULE_DETAIL_FAIL = 'BAD_REQUEST',


/* 401 UNAUTHORIZED : 인증되지 않은 사용자 */
Expand Down
Empty file.
12 changes: 11 additions & 1 deletion src/rule/domain/rule.invitation.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ export class RuleInvitationEntity extends BaseEntity {
@JoinColumn({name: 'rule_id'})
rule: RuleMainEntity;

@ManyToOne(() => UserEntity, user => user.invitationsSent)
@ManyToOne(() => UserEntity, user => user.invitationsSent) @JoinColumn({name: 'inviter_id'})
@JoinColumn({name: 'inviter_id'})
inviter: UserEntity;

@ManyToOne(() => UserEntity, user => user.invitationsReceived)
@JoinColumn({name: 'invited_id'})
invited: UserEntity;

static async findNameById(inviterId: number): Promise<{ memberId : number, name : string }> {
const userEntity : UserEntity = await UserEntity.findOne({
where: { id: inviterId }
});
const memberId = inviterId;
const name = userEntity.name;

return { memberId, name };
}
}
13 changes: 13 additions & 0 deletions src/rule/domain/rule.main.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn, OneToMany } from 'typeorm';
import { RuleSubEntity } from './rule.sub.entity';
import { RuleInvitationEntity } from './rule.invitation.entity'
import { CommentEntity } from 'src/comment/domain/comment.entity';

@Entity()
export class RuleMainEntity extends BaseEntity {
Expand All @@ -24,4 +25,16 @@ export class RuleMainEntity extends BaseEntity {

@OneToMany(() => RuleInvitationEntity, ruleInvitation => ruleInvitation.rule)
invitations: RuleInvitationEntity[];

@OneToMany(() => CommentEntity, comment => comment.rule)
comments: CommentEntity[];

static async findMainById(ruleId: number): Promise<RuleMainEntity> {
const ruleMain : RuleMainEntity = await RuleMainEntity.findOne({
where: { id: ruleId },
relations: ['rules', 'invitations', 'comments']
});

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

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

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

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

@IsNotEmpty()
@IsDate()
created: Date;
}
11 changes: 11 additions & 0 deletions src/rule/dto/detail-comment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IsArray, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
import { CommentPairDto } from './comment-pair.dto';

export class DetailCommentDto {
@IsArray()
@ValidateNested({ each: true })
@Type(() => CommentPairDto)
commentPairs: CommentPairDto[];
}

10 changes: 10 additions & 0 deletions src/rule/dto/detail-member.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IsArray, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
import { MemberPairDto } from './member-pair.dto';

export class DetailMemberDto {
@IsArray()
@ValidateNested({ each: true })
@Type(() => MemberPairDto)
memberPairs: MemberPairDto[];
}
12 changes: 12 additions & 0 deletions src/rule/dto/detail-page.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DetailRuleDto } from './detail-rule.dto';
import { DetailMemberDto } from './detail-member.dto';
import { DetailCommentDto } from './detail-comment.dto';
import { MetaToBackDto } from './meta-to-back.dto';


export class DetailPageDto {
rule: DetailRuleDto;
member: DetailMemberDto;
comment: DetailCommentDto[];
// metaBack: MetaToBackDto;
}
Loading