-
Notifications
You must be signed in to change notification settings - Fork 2
[Refactor] 아이템 수정사항 - 미소유 아이템 카테고리별 조회, 기본 아이템 회원가입 시 기본 장착 #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| package TtattaBackend.ttatta.domain.enums; | ||
|
|
||
| public enum BodyPart { | ||
| HEAD, TORSO | ||
| HEAD, EYES, TORSO | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,21 @@ | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @Repository | ||||||||||||||||||||||||||||||||||||||
| public interface ItemRepository extends JpaRepository<Items, Long> { | ||||||||||||||||||||||||||||||||||||||
| @Query("SELECT i FROM Items i " + | ||||||||||||||||||||||||||||||||||||||
| "WHERE i.bodyPart = :bodyPart " + | ||||||||||||||||||||||||||||||||||||||
| "AND NOT EXISTS (SELECT o FROM OwnedItems o WHERE o.users = :user AND o.items.id = i.id)") | ||||||||||||||||||||||||||||||||||||||
| List<Items> getShopItemByBodyPartHead(@Param("user") Users user, @Param("bodyPart") Optional<BodyPart> bodyPart); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @Query("SELECT i FROM Items i " + | ||||||||||||||||||||||||||||||||||||||
| "WHERE i.bodyPart = :bodyPart " + | ||||||||||||||||||||||||||||||||||||||
| "AND NOT EXISTS (SELECT o FROM OwnedItems o WHERE o.users = :user AND o.items.id = i.id)") | ||||||||||||||||||||||||||||||||||||||
| List<Items> getShopItemByBodyPartEyes(@Param("user") Users user, @Param("bodyPart") Optional<BodyPart> bodyPart); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @Query("SELECT i FROM Items i " + | ||||||||||||||||||||||||||||||||||||||
| "WHERE i.bodyPart = :bodyPart " + | ||||||||||||||||||||||||||||||||||||||
| "AND NOT EXISTS (SELECT o FROM OwnedItems o WHERE o.users = :user AND o.items.id = i.id)") | ||||||||||||||||||||||||||||||||||||||
| List<Items> getShopItemByBodyPartTorso(@Param("user") Users user, @Param("bodyPart") Optional<BodyPart> bodyPart); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 거의 동일한 쿼리를 사용하는
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @Query("SELECT i FROM Items i " + | ||||||||||||||||||||||||||||||||||||||
| "WHERE NOT EXISTS (SELECT o FROM OwnedItems o WHERE o.users = :user AND o.items.id = i.id)") | ||||||||||||||||||||||||||||||||||||||
| List<Items> getShopItem(@Param("user") Users user); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| package TtattaBackend.ttatta.service.ItemService; | ||
|
|
||
| import TtattaBackend.ttatta.domain.Items; | ||
| import TtattaBackend.ttatta.domain.enums.BodyPart; | ||
| import TtattaBackend.ttatta.domain.mapping.OwnedItems; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public interface ItemQueryService { | ||
| List<Items> getShopItem(); | ||
| List<Items> getShopItem(Optional<BodyPart> bodyPart); | ||
| List<OwnedItems> getMyItem(); | ||
| List<OwnedItems> getEquippedItem(); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| package TtattaBackend.ttatta.service.ItemService; | ||
|
|
||
| import TtattaBackend.ttatta.apiPayload.code.status.ErrorStatus; | ||
| import TtattaBackend.ttatta.apiPayload.exception.handler.ExceptionHandler; | ||
| import TtattaBackend.ttatta.config.security.SecurityUtil; | ||
| import TtattaBackend.ttatta.domain.Items; | ||
| import TtattaBackend.ttatta.domain.Users; | ||
| import TtattaBackend.ttatta.domain.enums.BodyPart; | ||
| import TtattaBackend.ttatta.domain.mapping.OwnedItems; | ||
| import TtattaBackend.ttatta.repository.ItemRepository; | ||
| import TtattaBackend.ttatta.repository.OwnedItemRepository; | ||
|
|
@@ -13,27 +15,40 @@ | |
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import static TtattaBackend.ttatta.apiPayload.code.status.ErrorStatus.USER_NOT_FOUND; | ||
| import static TtattaBackend.ttatta.domain.enums.BodyPart.*; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class ItemQueryServiceImpl implements ItemQueryService{ | ||
|
|
||
| private final UserRepository userRepository; | ||
|
|
||
| private final ItemRepository itemRepository; | ||
|
|
||
| private final OwnedItemRepository ownedItemRepository; | ||
|
|
||
| @Override | ||
| public List<Items> getShopItem() { | ||
| public List<Items> getShopItem(Optional<BodyPart> bodyPart) { | ||
| Long userId = SecurityUtil.getCurrentUserId(); | ||
| Users user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new ExceptionHandler(USER_NOT_FOUND)); | ||
|
|
||
| return itemRepository.getShopItem(user); | ||
| // bodyPart에 따른 아이템 조회 | ||
| if (bodyPart.isPresent()) { | ||
| if (bodyPart.get() == HEAD) | ||
| return itemRepository.getShopItemByBodyPartHead(user, bodyPart); | ||
| else if (bodyPart.get() == EYES) | ||
| return itemRepository.getShopItemByBodyPartEyes(user, bodyPart); | ||
| else if (bodyPart.get() == TORSO) | ||
| return itemRepository.getShopItemByBodyPartTorso(user, bodyPart); | ||
| else if (bodyPart.get() == null) | ||
| return itemRepository.getShopItem(user); | ||
| else | ||
| throw new ExceptionHandler(ErrorStatus.ITEM_BODYPART_QUERY_STRING_INVALID); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 방어적인 코드인건가요? |
||
| } else | ||
| return itemRepository.getShopItem(user); | ||
| } | ||
|
Comment on lines
+38
to
52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
// bodyPart에 따른 아이템 조회
if (bodyPart.isPresent()) {
return itemRepository.getShopItemByBodyPart(user, bodyPart.get());
} else {
return itemRepository.getShopItem(user);
}
} |
||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,12 +11,10 @@ | |||||
| import TtattaBackend.ttatta.domain.Users; | ||||||
| import TtattaBackend.ttatta.domain.UsersWithdrawals; | ||||||
| import TtattaBackend.ttatta.domain.enums.*; | ||||||
| import TtattaBackend.ttatta.domain.mapping.OwnedItems; | ||||||
| import TtattaBackend.ttatta.jwt.JwtUtils; | ||||||
| import TtattaBackend.ttatta.oidc.*; | ||||||
| import TtattaBackend.ttatta.repository.DiaryCategoryRepository; | ||||||
| import TtattaBackend.ttatta.repository.DiaryRepository; | ||||||
| import TtattaBackend.ttatta.repository.UserRepository; | ||||||
| import TtattaBackend.ttatta.repository.UserWithdrawalRepository; | ||||||
| import TtattaBackend.ttatta.repository.*; | ||||||
| import TtattaBackend.ttatta.web.dto.DiaryCategoryRequestDTO; | ||||||
| import TtattaBackend.ttatta.web.dto.UserRequestDTO; | ||||||
| import TtattaBackend.ttatta.web.dto.UserResponseDTO; | ||||||
|
|
@@ -40,9 +38,7 @@ | |||||
| import java.time.LocalDate; | ||||||
| import java.time.LocalDateTime; | ||||||
| import java.time.temporal.ChronoUnit; | ||||||
| import java.util.Collections; | ||||||
| import java.util.Map; | ||||||
| import java.util.Optional; | ||||||
| import java.util.*; | ||||||
| import java.util.concurrent.TimeUnit; | ||||||
|
|
||||||
| import static TtattaBackend.ttatta.apiPayload.code.status.ErrorStatus.*; | ||||||
|
|
@@ -52,19 +48,14 @@ | |||||
| @Slf4j | ||||||
| public class UserCommandServiceImpl implements UserCommandService { | ||||||
|
|
||||||
| private final OauthOIDCHelper oauthOIDCHelper; | ||||||
| private final JwtAuthenticationFilter jwtAuthenticationFilter; | ||||||
| @Value("${jwt.ACCESS_EXP_TIME}") | ||||||
| private int accessExpTime; | ||||||
| @Value("${jwt.REFRESH_EXP_TIME}") | ||||||
| private int refreshExpTime; | ||||||
|
|
||||||
| @Value("${oidc.iss}") | ||||||
| private String iss; | ||||||
|
|
||||||
| @Value("${oidc.aud}") | ||||||
| private String aud; | ||||||
|
|
||||||
| private final UserRepository userRepository; | ||||||
| private final DiaryRepository diaryRepository; | ||||||
| private final DiaryCategoryRepository diaryCategoryRepository; | ||||||
|
|
@@ -79,6 +70,10 @@ public class UserCommandServiceImpl implements UserCommandService { | |||||
| private final KakaoOauthHelper kakaoOauthHelper; | ||||||
| private final JwtOIDCProvider jwtOIDCProvider; | ||||||
| private final AmazonS3Manager s3Manager; | ||||||
| private final OauthOIDCHelper oauthOIDCHelper; | ||||||
| private final JwtAuthenticationFilter jwtAuthenticationFilter; | ||||||
| private final ItemRepository itemRepository; | ||||||
| private final OwnedItemRepository ownedItemRepository; | ||||||
|
|
||||||
| @Override | ||||||
| public Users createTestUser() { | ||||||
|
|
@@ -101,19 +96,40 @@ public Users createTestUser() { | |||||
| @Override | ||||||
| @Transactional // ??? | ||||||
| public Users signUp(UserRequestDTO.SignUpRequestDTO request) { | ||||||
| // 아이디 중복 확인 | ||||||
| Users newUser = UserConverter.toUsers(request); | ||||||
| IsAvailable usernameAvailable = verifyUsernameOverlap(request.getUsername()); | ||||||
|
|
||||||
| // 아이디 중복 확인 | ||||||
| if (usernameAvailable.equals(IsAvailable.UNAVAILABLE)) { | ||||||
| throw new ExceptionHandler(ErrorStatus.USERNAME_ALREADY_EXIST); | ||||||
| } | ||||||
|
|
||||||
| Users newUser = UserConverter.toUsers(request); | ||||||
| newUser.encodePassword(passwordEncoder.encode(request.getPassword())); | ||||||
| // 일상 카테고리 생성 | ||||||
| createDefaultCategory(newUser); | ||||||
| // 기본 아이템 착용 | ||||||
| saveAndEquipDefaultOwnedItems(newUser); | ||||||
|
|
||||||
| return userRepository.save(newUser); | ||||||
| } | ||||||
|
|
||||||
| private void saveAndEquipDefaultOwnedItems(Users newUser) { | ||||||
| List<OwnedItems> ownedItemsList = new ArrayList<>(); | ||||||
|
|
||||||
| ownedItemsList.add(createDefaultOwnedItems(newUser, 1L)); | ||||||
| ownedItemsList.add(createDefaultOwnedItems(newUser, 4L)); | ||||||
| ownedItemsList.add(createDefaultOwnedItems(newUser, 7L)); | ||||||
| ownedItemsList.add(createDefaultOwnedItems(newUser, 9L)); | ||||||
|
Comment on lines
+118
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| ownedItemRepository.saveAll(ownedItemsList); | ||||||
| } | ||||||
|
|
||||||
| private OwnedItems createDefaultOwnedItems(Users newUser, Long itemId) { | ||||||
| return OwnedItems.builder() | ||||||
| .users(newUser) | ||||||
| .items(itemRepository.findById(itemId).get()) // 머리 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| .isEquipped(true) | ||||||
| .build(); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| @Transactional | ||||||
| public UserResponseDTO.IsPendingResultDTO checkIsPending() { | ||||||
|
|
@@ -182,18 +198,20 @@ public UserResponseDTO.KaKaoFinalSignUpResultDTO kakaoSignUp(UserRequestDTO.Sign | |||||
| Long userId = SecurityUtil.getCurrentUserId(); | ||||||
| Users savedUser = userRepository.findById(userId) | ||||||
| .orElseThrow(() -> new ExceptionHandler(ErrorStatus.USER_NOT_FOUND)); | ||||||
| // 액세스 토큰 및 리프레시 토큰 생성 | ||||||
| String key = "users:" + savedUser.getId().toString(); | ||||||
| String accessToken = generateAccessToken(savedUser.getId(), accessExpTime); | ||||||
| String refreshToken = generateAndSaveRefreshToken(key, refreshExpTime); | ||||||
|
|
||||||
| // 해당 닉네임을 업데이트 | ||||||
| savedUser.updateNickname(request.getNickname()); | ||||||
| // 유저의 상태 pending -> activate 업데이트 | ||||||
| savedUser.updateStatus(UserStatus.ACTIVE); | ||||||
| // 일상 카테고리 생성 | ||||||
| createDefaultCategory(savedUser); | ||||||
| // 기본 아이템 착용 | ||||||
| saveAndEquipDefaultOwnedItems(savedUser); | ||||||
|
|
||||||
| // 액세스 토큰 및 리프레시 토큰 생성 | ||||||
| String key = "users:" + savedUser.getId().toString(); | ||||||
| String accessToken = generateAccessToken(savedUser.getId(), accessExpTime); | ||||||
| String refreshToken = generateAndSaveRefreshToken(key, refreshExpTime); | ||||||
| return UserConverter.toUserKaKaoFinalSignUpResultDTO(accessToken, refreshToken, savedUser); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3개의 쿼리 형태가 동일하고 메소드명만 다른데 굳이 이렇게 구분한 이유가 있나요?