Skip to content

Commit

Permalink
[feat] 온보딩 동기 API
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryeolee committed Nov 1, 2023
1 parent 5e6b3b4 commit 55d6884
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public interface UserRepository extends JpaRepository<User, Long> {
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);







Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;


@Transactional
@Slf4j
@Service
public class UserService {
Expand All @@ -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");
Expand Down Expand Up @@ -72,7 +73,7 @@ public ProfileImageResponseDto selectProfileImage(Long userId){
return profileImageResponseDto;
}

@Transactional

public ResponseDto deleteUser(Long userId){

userRepository.deleteUser(userId);
Expand All @@ -87,7 +88,7 @@ public ResponseDto deleteUser(Long userId){
}


@Transactional

public ResponseDto emitNickname(Long userId, String nickName){

userRepository.updateUserNickname(nickName, userId);
Expand Down

0 comments on commit 55d6884

Please sign in to comment.