From 55d6884612ef9acae217e66657e7d040bf0400aa Mon Sep 17 00:00:00 2001 From: seungryeol Date: Thu, 2 Nov 2023 03:35:39 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=98=A8=EB=B3=B4=EB=94=A9=20?= =?UTF-8?q?=EB=8F=99=EA=B8=B0=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/OnBoardingController.java | 40 +++++++++++++++++++ .../request/OnBoardingMotivationRequest.java | 17 ++++++++ .../user/repository/UserRepository.java | 7 ++++ .../user/service/OnBoardingService.java | 36 +++++++++++++++++ .../farmususer/user/service/UserService.java | 7 ++-- 5 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java new file mode 100644 index 0000000..3c65d7f --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java @@ -0,0 +1,40 @@ +package modernfarmer.server.farmususer.user.controller; + + +import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.user.dto.request.OnBoardingMotivationRequest; +import modernfarmer.server.farmususer.user.dto.response.ResponseDto; +import modernfarmer.server.farmususer.user.service.OnBoardingService; +import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletRequest; + +@Slf4j +@RestController +@RequestMapping("/api/user") +public class OnBoardingController { + + private final JwtTokenProvider jwtTokenProvider; + private final OnBoardingService onBoardingService; + + @Autowired + public OnBoardingController( JwtTokenProvider jwtTokenProvider,OnBoardingService onBoardingService){ + this.jwtTokenProvider = jwtTokenProvider; + this.onBoardingService = onBoardingService; + } + + @PostMapping(value = "/motivation") + public ResponseDto onBoardingMotivation(HttpServletRequest request, @Validated @RequestBody OnBoardingMotivationRequest onBoardingMotivationRequest) { + + String userId = jwtTokenProvider.getUserId(request); + + ResponseDto responseDto = onBoardingService.onBoardingMotivation(Long.valueOf(userId), onBoardingMotivationRequest.getMotivation()); + + return responseDto; + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java new file mode 100644 index 0000000..34796c5 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java @@ -0,0 +1,17 @@ +package modernfarmer.server.farmususer.user.dto.request; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import javax.validation.constraints.NotNull; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class OnBoardingMotivationRequest { + + + @NotNull(message = "null 값을 가지면 안됩니다.") + private String motivation; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 6bbbf0d..c4a8f87 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -30,6 +30,13 @@ public interface UserRepository extends JpaRepository { void emitUserProfileImage(@Param("userId") Long userId, @Param("profileImage") String profileImage); + @Modifying + @Query("update User as u set u.motivation= :motivation where u.id = :userId") + void insertUserMotivation(@Param("userId") Long userId, @Param("motivation") String motivation); + + + + diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java new file mode 100644 index 0000000..7a9278c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -0,0 +1,36 @@ +package modernfarmer.server.farmususer.user.service; + + +import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.user.dto.response.ResponseDto; +import modernfarmer.server.farmususer.user.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +import javax.transaction.Transactional; + +@Transactional +@Slf4j +@Service +public class OnBoardingService { + public UserRepository userRepository; + + @Autowired + public OnBoardingService(UserRepository userRepository) { + this.userRepository = userRepository; + } + + public ResponseDto onBoardingMotivation(Long userId, String motivation){ + + userRepository.insertUserMotivation(userId, motivation); + + ResponseDto responseDto = ResponseDto.builder() + .message("OK") + .code(200) + .build(); + + return responseDto; + } + +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 6cec29c..32d1407 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -18,6 +18,7 @@ import java.io.IOException; +@Transactional @Slf4j @Service public class UserService { @@ -39,7 +40,7 @@ public UserService(UserRepository userRepository, JwtTokenProvider jwtTokenProvi this.s3Uploader = s3Uploader; } - @Transactional + public ResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { String imageUrl = s3Uploader.uploadFiles(multipartFile, "userprofileimage"); @@ -72,7 +73,7 @@ public ProfileImageResponseDto selectProfileImage(Long userId){ return profileImageResponseDto; } - @Transactional + public ResponseDto deleteUser(Long userId){ userRepository.deleteUser(userId); @@ -87,7 +88,7 @@ public ResponseDto deleteUser(Long userId){ } - @Transactional + public ResponseDto emitNickname(Long userId, String nickName){ userRepository.updateUserNickname(nickName, userId);