Skip to content

Commit

Permalink
이름 변경 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimmoongi0320 committed Aug 31, 2024
1 parent e510ca5 commit c723e5f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.github.winkathon.lingo.common.api.dto.response.ApiResponse;
import com.github.winkathon.lingo.common.security.util.UserContext;
import com.github.winkathon.lingo.domain.user.dto.request.ChangeNameRequest;
import com.github.winkathon.lingo.domain.user.dto.response.UserListResponse;
import com.github.winkathon.lingo.domain.user.dto.response.UserResponse;
import com.github.winkathon.lingo.domain.user.schema.User;
Expand Down Expand Up @@ -47,4 +49,13 @@ public ApiResponse<Void> uploadAvatar(MultipartFile file) {

return ApiResponse.ok();
}

@PutMapping("/name")
public ApiResponse<Void> changeName(@RequestBody ChangeNameRequest request) {

User user = UserContext.getUser();
userService.changeName(user, request);

return ApiResponse.ok();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.winkathon.lingo.domain.user.dto.request;

public record ChangeNameRequest(

String name
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.github.winkathon.lingo.domain.upload.schema.Image;
import com.github.winkathon.lingo.domain.upload.util.UploadUtil;
import com.github.winkathon.lingo.domain.user.dto.request.ChangeNameRequest;
import com.github.winkathon.lingo.domain.user.dto.response.UserListResponse;
import com.github.winkathon.lingo.domain.user.dto.response.UserResponse;
import com.github.winkathon.lingo.domain.user.exception.UserNotFoundException;
Expand Down Expand Up @@ -46,5 +47,17 @@ public void uploadAvatar(User user, MultipartFile file) {
Image image = uploadUtil.upload(user, file);

user.setAvatar(image);
userRepository.save(user);
}

public void changeName(User user, ChangeNameRequest dto) {

String newName = dto.name();

User updateUser = userRepository.findById(user.getId())
.orElseThrow(UserNotFoundException::new);

updateUser.setName(newName);
userRepository.save(updateUser);
}
}

0 comments on commit c723e5f

Please sign in to comment.