Skip to content

Commit

Permalink
Merge pull request #193 from boostcampwm2023/server/feature/7
Browse files Browse the repository at this point in the history
사용자 정보 불러오기
  • Loading branch information
khw3754 authored Nov 28, 2023
2 parents 8c20172 + eb43982 commit a7a2671
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AuthGuard } from '@nestjs/passport';
import { Music } from 'src/entity/music.entity';
import { CatchyException } from 'src/config/catchyException';
import { ERROR_CODE } from 'src/config/errorCode.enum';
import { User } from 'src/entity/user.entity';

@Controller('users')
export class UserController {
Expand Down Expand Up @@ -58,4 +59,12 @@ export class UserController {
user_id: await this.userService.updateUserImage(user_id, image_url),
};
}

@Get('my-info')
@UseGuards(AuthGuard())
@HttpCode(HTTP_STATUS_CODE.SUCCESS)
async getMyInformation(@Req() req): Promise<User> {
const user_id = req.user.userId;
return this.userService.getUserInformation(user_id);
}
}
14 changes: 14 additions & 0 deletions server/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,18 @@ export class UserService {
);
}
}

async getUserInformation(user_id: string): Promise<User> {
try {
return await this.userRepository.findOne({
where: { user_id },
});
} catch {
throw new CatchyException(
'SERVER_ERROR',
HTTP_STATUS_CODE.SERVER_ERROR,
ERROR_CODE.SERVICE_ERROR,
);
}
}
}

0 comments on commit a7a2671

Please sign in to comment.