Skip to content

Commit

Permalink
merge :: apply friend api (#14)
Browse files Browse the repository at this point in the history
* add :: apply friend api

* chore :: delete log
  • Loading branch information
jyk1029 authored Feb 29, 2024
1 parent a1dfbde commit 855430e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/application/domain/user/controller/user.controller.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}
23 changes: 23 additions & 0 deletions src/application/domain/user/service/user.service.ts
Original file line number Diff line number Diff line change
@@ -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<FriendApplyEntity>
) {
}

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)
}
}
6 changes: 4 additions & 2 deletions src/infrastructure/global/module/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 855430e

Please sign in to comment.