diff --git a/src/main/java/com/jangburich/domain/user/controller/UserController.java b/src/main/java/com/jangburich/domain/user/controller/UserController.java index 25798c3..cbff6cf 100644 --- a/src/main/java/com/jangburich/domain/user/controller/UserController.java +++ b/src/main/java/com/jangburich/domain/user/controller/UserController.java @@ -12,17 +12,21 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.GetMapping; 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.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; +import com.jangburich.domain.user.domain.AdditionalInfoCreateDTO; import com.jangburich.domain.user.domain.KakaoApiResponseDTO; import com.jangburich.domain.user.domain.TokenResponseDTO; import com.jangburich.domain.user.service.UserService; +import com.jangburich.global.payload.Message; import com.jangburich.global.payload.ResponseCustom; import com.jangburich.utils.parser.AuthenticationParser; +import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; @RestController @@ -33,29 +37,25 @@ public class UserController { private final UserService userService; @PostMapping("/login") - public ResponseCustom login( - @RequestParam String authorizationHeader) { + public ResponseCustom login(@RequestParam String authorizationHeader) { TokenResponseDTO login = userService.login(authorizationHeader); return ResponseCustom.OK(login); } @GetMapping("/user-info") - public ResponseEntity getUserInfo( - Authentication authentication) { + public ResponseEntity getUserInfo(Authentication authentication) { KakaoApiResponseDTO userInfo = userService.getUserInfo(AuthenticationParser.parseUserId(authentication)); return ResponseEntity.ok(userInfo); } @PostMapping("/join/user") - public ResponseCustom joinUser( - @RequestParam String authorizationHeader) { + public ResponseCustom joinUser(@RequestParam String authorizationHeader) { return ResponseCustom.OK(userService.joinUser(authorizationHeader)); } @PostMapping("/join/owner") - public ResponseCustom joinOwner( - @RequestParam String authorizationHeader) { + public ResponseCustom joinOwner(@RequestParam String authorizationHeader) { return ResponseCustom.OK(userService.joinOwner(authorizationHeader)); } @@ -91,4 +91,12 @@ public ResponseEntity> getAccessToken(@RequestParam("code") return ResponseEntity.ok(response.getBody()); } + @Operation(summary = "유저 추가정보 저장", description = "유저 추가정보 저장합니다.") + @PostMapping("/additionalInfo") + public ResponseCustom saveAdditionalInfo(Authentication authentication, + @RequestBody AdditionalInfoCreateDTO additionalInfoCreateDTO) { + userService.additionalInfo(AuthenticationParser.parseUserId(authentication), additionalInfoCreateDTO); + return ResponseCustom.OK(Message.builder().message("success").build()); + } + } diff --git a/src/main/java/com/jangburich/domain/user/domain/AdditionalInfoCreateDTO.java b/src/main/java/com/jangburich/domain/user/domain/AdditionalInfoCreateDTO.java new file mode 100644 index 0000000..60017c1 --- /dev/null +++ b/src/main/java/com/jangburich/domain/user/domain/AdditionalInfoCreateDTO.java @@ -0,0 +1,13 @@ +package com.jangburich.domain.user.domain; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class AdditionalInfoCreateDTO { + private String name; + private String phoneNum; + private Boolean agreeMarketing; + private Boolean agreeAdvertisement; +} diff --git a/src/main/java/com/jangburich/domain/user/domain/User.java b/src/main/java/com/jangburich/domain/user/domain/User.java index 8a39769..3ccfa44 100644 --- a/src/main/java/com/jangburich/domain/user/domain/User.java +++ b/src/main/java/com/jangburich/domain/user/domain/User.java @@ -38,6 +38,9 @@ public class User extends BaseEntity { @Column(name = "nickname", nullable = false, unique = true) private String nickname; + @Column(name = "name") + private String name; + @Column(name = "profile_image_url") private String profileImageUrl; @@ -50,6 +53,12 @@ public class User extends BaseEntity { @Column(name = "refresh_token") private String refreshToken; + @Column(name = "agree_marketing") + private Boolean agreeMarketing; + + @Column(name = "agree_advertisement") + private Boolean agreeAdvertisement; + public void updateRefreshToken(String refreshToken) { this.refreshToken = refreshToken; } diff --git a/src/main/java/com/jangburich/domain/user/service/UserService.java b/src/main/java/com/jangburich/domain/user/service/UserService.java index 2ff94f2..6259e6f 100644 --- a/src/main/java/com/jangburich/domain/user/service/UserService.java +++ b/src/main/java/com/jangburich/domain/user/service/UserService.java @@ -13,10 +13,13 @@ import com.jangburich.domain.owner.domain.repository.OwnerRepository; import com.jangburich.domain.store.domain.Store; import com.jangburich.domain.store.domain.repository.StoreRepository; +import com.jangburich.domain.user.domain.AdditionalInfoCreateDTO; import com.jangburich.domain.user.domain.KakaoApiResponseDTO; import com.jangburich.domain.user.domain.TokenResponseDTO; import com.jangburich.domain.user.domain.User; import com.jangburich.domain.user.repository.UserRepository; +import com.jangburich.global.error.DefaultNullPointerException; +import com.jangburich.global.payload.ErrorCode; import com.jangburich.utils.JwtUtil; import lombok.RequiredArgsConstructor; @@ -81,9 +84,8 @@ public TokenResponseDTO joinOwner(String kakaoAccessToken) { User user = userRepository.findByProviderId("kakao_" + userInfo.getId()).orElse(null); if (user == null) { - user = userRepository.save( - User.create("kakao_" + userInfo.getId(), userInfo.getProperties().getNickname(), - userInfo.getKakaoAccount().getEmail(), userInfo.getProperties().getProfileImage(), "ROLE_OWNER")); + user = userRepository.save(User.create("kakao_" + userInfo.getId(), userInfo.getProperties().getNickname(), + userInfo.getKakaoAccount().getEmail(), userInfo.getProperties().getProfileImage(), "ROLE_OWNER")); Owner newOwner = ownerRepository.save(Owner.create(user)); storeRepository.save(Store.create(newOwner)); } @@ -137,4 +139,15 @@ public String reissueAccessToken(String refreshToken) { return jwtUtil.createAccessToken(user.getProviderId(), user.getRole()); } + @Transactional + public void additionalInfo(String userId, AdditionalInfoCreateDTO additionalInfoCreateDTO) { + User user = userRepository.findByProviderId(userId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + user.setName(additionalInfoCreateDTO.getName()); + user.setPhoneNumber(additionalInfoCreateDTO.getPhoneNum()); + user.setAgreeAdvertisement(additionalInfoCreateDTO.getAgreeAdvertisement()); + user.setAgreeMarketing(additionalInfoCreateDTO.getAgreeMarketing()); + } + }