Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] User API 수정 #55

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
26 changes: 13 additions & 13 deletions apps/api-gateway/src/api/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Body, Controller, Delete, Get, Patch, Query, Res, Session } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Body, Controller, Delete, Get, Patch, Res } from '@nestjs/common';
import { UserService } from './user.service';
import { Response } from 'express';
import { AuthInfo } from '../../common/decorators/auth-info.decorator';
import { IAuthInfo } from '../../common/interfaces/auth.interface';

@Controller('users')
export class UserController {
constructor(private readonly userService: UserService) {}

@Get()
async findUser(@Session() session, @Res() res: Response) {
const user = session.user;
async findUser(@AuthInfo() authInfo: IAuthInfo, @Res() res: Response) {
const { userId } = authInfo;
const userInfo = await this.userService.findUser(userId);

const findData = await this.userService.findUser(user);

return res.send(user);
return res.send(userInfo);
}

@Patch()
async modifyUser(@Body('username') username: string, @Session() session, @Res() res: Response) {
const user = session.user;
async modifyUser(@Body('username') username: string, @AuthInfo() authInfo: IAuthInfo, @Res() res: Response) {
const { userId } = authInfo;

const modifyData = await this.userService.modifyUser(username, user);
const modifyData = await this.userService.modifyUser(username, userId);

return res.status(204).send({
message: '사용자 이름 변경 완료',
Expand All @@ -29,10 +29,10 @@ export class UserController {
}

@Delete()
async removeUser(@Session() session, @Res() res: Response) {
const user = session.user;
async removeUser(@AuthInfo() authInfo: IAuthInfo, @Res() res: Response) {
const { userId } = authInfo;

const removeData = await this.userService.removeUser(user);
const removeData = await this.userService.removeUser(userId);

return res.status(204).send({
message: '사용자 정보 삭제 완료',
Expand Down
7 changes: 5 additions & 2 deletions apps/api-gateway/src/api/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Inject, Injectable } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { lastValueFrom } from 'rxjs';

@Injectable()
export class UserService {
Expand All @@ -8,9 +9,11 @@ export class UserService {
private readonly userClient: ClientProxy,
) {}

async findUser(user) {}
async findUser(userId: string) {
return await lastValueFrom(this.userClient.send({ cmd: 'find-user' }, userId));
}

async modifyUser(username: string, user) {}
async modifyUser(username: string, userId: string) {}

async removeUser(user) {}
}
8 changes: 4 additions & 4 deletions apps/user/src/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class UserController {
return await this.userService.createGuestUser(username);
}

// @MessagePattern({ cmd: 'find-user' })
// async findUser(userId: string) {
// return await this.userService.findUser(userId);
// }
@MessagePattern({ cmd: 'find-user' })
async findUser(userId: string) {
return await this.userService.findUser(userId);
}
}
16 changes: 8 additions & 8 deletions apps/user/src/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export class UserService {
return await this.userRepository.save(guestUserInfo);
}

// async findUser(userId: string) {
// const userInfo: User = await this.userRepository.findOne({
// where: {
// id: userId,
// },
// });
// return userInfo;
// }
async findUser(userId: string) {
const userInfo: User = await this.userRepository.findOne({
where: {
id: userId,
},
});
return userInfo;
}
}
Loading