-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
252 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
src/main/java/com/dnd/accompany/domain/auth/oauth/dto/LoginRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
package com.dnd.accompany.domain.auth.oauth.dto; | ||
|
||
import com.dnd.accompany.domain.auth.oauth.service.OAuthProvider; | ||
|
||
public record LoginRequest( | ||
OAuthProvider provider, | ||
String provider, | ||
String accessToken | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/dnd/accompany/domain/user/api/UserProfileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.dnd.accompany.domain.user.api; | ||
|
||
import com.dnd.accompany.domain.auth.dto.jwt.JwtAuthentication; | ||
import com.dnd.accompany.domain.user.dto.CreateUserProfileRequest; | ||
import com.dnd.accompany.domain.user.service.UserProfileService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
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.RestController; | ||
|
||
@Tag(name = "Onboarding") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/profiles") | ||
public class UserProfileController { | ||
|
||
private final UserProfileService userProfileService; | ||
|
||
@Operation(summary = "온보딩 정보 저장") | ||
@PostMapping | ||
public void createUserProfile(@AuthenticationPrincipal JwtAuthentication user, | ||
@RequestBody @Valid CreateUserProfileRequest createUserProfileRequest | ||
) { | ||
userProfileService.createUserProfile(user.getId(), createUserProfileRequest); | ||
} | ||
|
||
@Operation(summary = "온보딩 여부 조회") | ||
@GetMapping("/exist") | ||
public ResponseEntity<Boolean> existUserProfile(@AuthenticationPrincipal JwtAuthentication user) { | ||
boolean result = userProfileService.existByUserId(user.getId()); | ||
return ResponseEntity.ok(result); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/dnd/accompany/domain/user/dto/CreateUserProfileRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.dnd.accompany.domain.user.dto; | ||
|
||
import com.dnd.accompany.domain.user.entity.enums.FoodPreference; | ||
import com.dnd.accompany.domain.user.entity.enums.Gender; | ||
import com.dnd.accompany.domain.user.entity.enums.TravelPreference; | ||
import com.dnd.accompany.domain.user.entity.enums.TravelStyle; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public record CreateUserProfileRequest( | ||
int birthYear, | ||
|
||
@NotNull | ||
Gender gender, | ||
|
||
@NotEmpty | ||
List<TravelPreference> travelPreferences, | ||
|
||
@NotEmpty | ||
List<TravelStyle> travelStyles, | ||
|
||
@NotEmpty | ||
List<FoodPreference> foodPreferences | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/dnd/accompany/domain/user/exception/UserProfileAlreadyExistsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.dnd.accompany.domain.user.exception; | ||
|
||
import com.dnd.accompany.global.common.exception.BusinessException; | ||
import com.dnd.accompany.global.common.response.ErrorCode; | ||
|
||
public class UserProfileAlreadyExistsException extends BusinessException { | ||
public UserProfileAlreadyExistsException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/dnd/accompany/domain/user/service/UserProfileService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.dnd.accompany.domain.user.service; | ||
|
||
import com.dnd.accompany.domain.user.dto.CreateUserProfileRequest; | ||
import com.dnd.accompany.domain.user.entity.UserProfile; | ||
import com.dnd.accompany.domain.user.exception.UserProfileAlreadyExistsException; | ||
import com.dnd.accompany.domain.user.infrastructure.UserProfileRepository; | ||
import com.dnd.accompany.global.common.response.ErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserProfileService { | ||
|
||
private final UserProfileRepository userProfileRepository; | ||
|
||
@Transactional | ||
public void createUserProfile(Long userId, CreateUserProfileRequest createUserProfileRequest) { | ||
validateDuplicateProfile(userId); | ||
|
||
UserProfile userProfile = UserProfile.builder() | ||
.userId(userId) | ||
.birthYear(createUserProfileRequest.birthYear()) | ||
.gender(createUserProfileRequest.gender()) | ||
.travelPreferences(createUserProfileRequest.travelPreferences()) | ||
.travelStyles(createUserProfileRequest.travelStyles()) | ||
.foodPreferences(createUserProfileRequest.foodPreferences()) | ||
.build(); | ||
|
||
userProfileRepository.save(userProfile); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public boolean existByUserId(Long userId) { | ||
return userProfileRepository.existsById(userId); | ||
} | ||
|
||
private void validateDuplicateProfile(Long userId) { | ||
if (userProfileRepository.existsById(userId)) { | ||
throw new UserProfileAlreadyExistsException(ErrorCode.PROFILE_ALREADY_EXISTS); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.