From 855430e98c1c93570696e22b2ee237248c7058e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A3=BC=EC=98=81?= <103026521+jyk1029@users.noreply.github.com> Date: Thu, 29 Feb 2024 14:45:49 +0900 Subject: [PATCH] merge :: apply friend api (#14) * add :: apply friend api * chore :: delete log --- .../domain/user/controller/user.controller.ts | 19 +++++++++++++++ .../domain/user/service/user.service.ts | 23 +++++++++++++++++++ .../global/module/user.module.ts | 6 +++-- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/application/domain/user/controller/user.controller.ts create mode 100644 src/application/domain/user/service/user.service.ts diff --git a/src/application/domain/user/controller/user.controller.ts b/src/application/domain/user/controller/user.controller.ts new file mode 100644 index 0000000..8f3df36 --- /dev/null +++ b/src/application/domain/user/controller/user.controller.ts @@ -0,0 +1,19 @@ +import { Controller, Param, Post, Req, UseFilters, UseGuards } from "@nestjs/common"; +import { GlobalExceptionFilter } from "../../../../infrastructure/global/filter/global.exception.filter"; +import { UserService } from "../service/user.service"; +import { AuthGuard } from "@nestjs/passport"; + +@UseFilters(GlobalExceptionFilter) +@Controller('user') +export class UserController { + constructor( + private userService: UserService + ) { + } + + @UseGuards(AuthGuard()) + @Post('apply/:id') + async applyFriend(@Req() req) { + await this.userService.applyFriend(req) + } +} \ No newline at end of file diff --git a/src/application/domain/user/service/user.service.ts b/src/application/domain/user/service/user.service.ts new file mode 100644 index 0000000..c10fb80 --- /dev/null +++ b/src/application/domain/user/service/user.service.ts @@ -0,0 +1,23 @@ +import { HttpException, Injectable } from "@nestjs/common"; +import { InjectRepository } from "@nestjs/typeorm"; +import { Repository } from "typeorm"; +import { FriendApplyEntity } from "../../../../infrastructure/domain/user/persistence/friend.apply.entity"; + +@Injectable() +export class UserService { + constructor( + @InjectRepository(FriendApplyEntity) + private friendApplyRepository: Repository + ) { + } + + async applyFriend(req) { + let friendApply = new FriendApplyEntity(); + + friendApply.status = 'WAIT' + friendApply.requestUserId = req.authInfo.id + friendApply.receiveUserId = req.user.id + + await this.friendApplyRepository.save(friendApply) + } +} \ No newline at end of file diff --git a/src/infrastructure/global/module/user.module.ts b/src/infrastructure/global/module/user.module.ts index 0caf3ed..96e3f71 100644 --- a/src/infrastructure/global/module/user.module.ts +++ b/src/infrastructure/global/module/user.module.ts @@ -3,14 +3,16 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { UserEntity } from '../../domain/user/persistence/user.entity'; import { FriendApplyEntity } from "../../domain/user/persistence/friend.apply.entity"; import { FriendEntity } from "../../domain/user/persistence/friend.entity"; +import { UserController } from "../../../application/domain/user/controller/user.controller"; +import { UserService } from "../../../application/domain/user/service/user.service"; const USER_REPOSITORY = TypeOrmModule.forFeature([ UserEntity, FriendApplyEntity, FriendEntity ]); @Global() @Module({ imports: [ USER_REPOSITORY ], - controllers: [], - providers: [], + controllers: [ UserController ], + providers: [ UserService ], exports: [ USER_REPOSITORY ] }) export class UserModule {