Skip to content

Commit

Permalink
Merge pull request 9oormthon-univ#60 from 9oormthon-univ/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
HyunWoo9930 authored Nov 20, 2024
2 parents a8ece0b + e74ebe9 commit 52ed7e8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,29 +37,25 @@ public class UserController {
private final UserService userService;

@PostMapping("/login")
public ResponseCustom<TokenResponseDTO> login(
@RequestParam String authorizationHeader) {
public ResponseCustom<TokenResponseDTO> login(@RequestParam String authorizationHeader) {
TokenResponseDTO login = userService.login(authorizationHeader);
return ResponseCustom.OK(login);
}

@GetMapping("/user-info")
public ResponseEntity<KakaoApiResponseDTO> getUserInfo(
Authentication authentication) {
public ResponseEntity<KakaoApiResponseDTO> getUserInfo(Authentication authentication) {
KakaoApiResponseDTO userInfo = userService.getUserInfo(AuthenticationParser.parseUserId(authentication));

return ResponseEntity.ok(userInfo);
}

@PostMapping("/join/user")
public ResponseCustom<TokenResponseDTO> joinUser(
@RequestParam String authorizationHeader) {
public ResponseCustom<TokenResponseDTO> joinUser(@RequestParam String authorizationHeader) {
return ResponseCustom.OK(userService.joinUser(authorizationHeader));
}

@PostMapping("/join/owner")
public ResponseCustom<TokenResponseDTO> joinOwner(
@RequestParam String authorizationHeader) {
public ResponseCustom<TokenResponseDTO> joinOwner(@RequestParam String authorizationHeader) {
return ResponseCustom.OK(userService.joinOwner(authorizationHeader));
}

Expand Down Expand Up @@ -91,4 +91,12 @@ public ResponseEntity<Map<String, Object>> 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());
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 9 additions & 0 deletions src/main/java/com/jangburich/domain/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/com/jangburich/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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());
}

}

0 comments on commit 52ed7e8

Please sign in to comment.