Skip to content

Commit

Permalink
feat: 본인 프로필 이미지 수정 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchef1 committed Nov 26, 2024
1 parent 9468ba0 commit 2fc2d49
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
3 changes: 2 additions & 1 deletion apps/server/src/account/account.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { RefreshTokenGuard } from '@/account/guard/refreshToken.guard';
import { AuthService } from '@/account/auth.service';
import { Account } from '@/account/entity/account.entity';
import { UserService } from './user.service';
import { UserController } from './user.controller';

@Module({
imports: [JwtModule.register({ global: true }), TypeOrmModule.forFeature([Account])],
controllers: [AuthController],
controllers: [AuthController, UserController],
providers: [
AuthService,
UserService,
Expand Down
7 changes: 7 additions & 0 deletions apps/server/src/account/dto/update-profile-image.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IsNotEmpty, IsString } from 'class-validator';

export class UpdateProfileImageRequest {
@IsNotEmpty()
@IsString()
profileImage: string;
}
21 changes: 21 additions & 0 deletions apps/server/src/account/user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Body, Controller, Patch, UseGuards } from '@nestjs/common';
import { UserDto } from '@/account/dto/user.dto';
import { ResponseMessage } from '@/common/decorator/response-message.decorator';
import { AccessTokenGuard } from './guard/accessToken.guard';
import { UserService } from './user.service';
import { UpdateProfileImageRequest } from './dto/update-profile-image.dto';
import { AuthUser } from './decorator/authUser.decorator';
import { Account } from './entity/account.entity';

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

@Patch('profile-image')
@ResponseMessage('사용자 프로필 이미지 수정에 성공했습니다.')
async updateProfileImage(@AuthUser() user: Account, @Body() body: UpdateProfileImageRequest) {
const updatedUser = await this.userService.updateProfileImage(user.id, body.profileImage);
return new UserDto(updatedUser);
}
}
32 changes: 19 additions & 13 deletions apps/server/src/account/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Account } from './entity/account.entity';

@Injectable()
export class UserService {
constructor(@InjectRepository(Account) private userRepository: Repository<Account>) {}

async getOne(id: number) {
return this.userRepository.findOneBy({ id });
}
}
import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Account } from './entity/account.entity';

@Injectable()
export class UserService {
constructor(@InjectRepository(Account) private userRepository: Repository<Account>) {}

async getOne(id: number) {
return await this.userRepository.findOneBy({ id });
}

async updateProfileImage(id: number, profileImage: string) {
const user = await this.userRepository.findOneBy({ id });
user.profileImage = profileImage;
return this.userRepository.save(user);
}
}

0 comments on commit 2fc2d49

Please sign in to comment.