diff --git a/src/main/java/com/jangburich/domain/oauth/domain/service/OAuthUserService.java b/src/main/java/com/jangburich/domain/oauth/domain/service/OAuthUserService.java index c28a24f..7049e72 100644 --- a/src/main/java/com/jangburich/domain/oauth/domain/service/OAuthUserService.java +++ b/src/main/java/com/jangburich/domain/oauth/domain/service/OAuthUserService.java @@ -76,7 +76,7 @@ public OAuth2User loadUser(OAuth2UserRequest oAuth2UserRequest) throws OAuth2Aut } } else if ("owner".equals(state)) { User existUser = userRepository.findByProviderId(userId).orElse(null); - if (existUser == null) { + if (existUser == null || !existUser.getRole().equals("ROLE_OWNER")) { User newUser = User.create(userId, oAuth2Response.getNickname(), oAuth2Response.getImage(), "ROLE_OWNER"); userRepository.save(newUser); diff --git a/src/main/java/com/jangburich/domain/store/domain/Store.java b/src/main/java/com/jangburich/domain/store/domain/Store.java index 4de18d8..3dbc358 100644 --- a/src/main/java/com/jangburich/domain/store/domain/Store.java +++ b/src/main/java/com/jangburich/domain/store/domain/Store.java @@ -1,8 +1,15 @@ package com.jangburich.domain.store.domain; +import java.time.DayOfWeek; +import java.time.LocalTime; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonFormat; import com.jangburich.domain.owner.domain.Owner; +import jakarta.persistence.CollectionTable; import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -69,14 +76,19 @@ public class Store { @Column(name = "location") private String location; + @ElementCollection(targetClass = DayOfWeek.class) + @Enumerated(EnumType.STRING) + @CollectionTable(name = "work_days", joinColumns = @JoinColumn(name = "work_schedule_id")) @Column(name = "day_of_week") - private String dayOfWeek; + private List workDays; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss") @Column(name = "open_time") - private String openTime; + private LocalTime openTime; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss") @Column(name = "close_time") - private String closeTime; + private LocalTime closeTime; @Column(name = "contact_number") private String contactNumber; @@ -87,17 +99,13 @@ public static Store of(Owner owner, StoreCreateRequestDTO storeCreateRequestDTO) newStore.setName(storeCreateRequestDTO.getName()); newStore.setCategory(storeCreateRequestDTO.getCategory()); newStore.setRepresentativeImage(storeCreateRequestDTO.getRepresentativeImage()); - newStore.setReservationAvailable(storeCreateRequestDTO.getReservationAvailable()); - newStore.setMaxReservation(storeCreateRequestDTO.getMaxReservation()); - newStore.setMinPrepayment(storeCreateRequestDTO.getMinPrepayment()); - newStore.setPrepaymentDuration(storeCreateRequestDTO.getPrepaymentDuration()); newStore.setIntroduction(storeCreateRequestDTO.getIntroduction()); newStore.setLatitude(storeCreateRequestDTO.getLatitude()); newStore.setLongitude(storeCreateRequestDTO.getLongitude()); newStore.setAddress(storeCreateRequestDTO.getAddress()); newStore.setAddress(storeCreateRequestDTO.getAddress()); newStore.setLocation(storeCreateRequestDTO.getLocation()); - newStore.setDayOfWeek(storeCreateRequestDTO.getDayOfWeek()); + newStore.setWorkDays(storeCreateRequestDTO.getDayOfWeek()); newStore.setOpenTime(storeCreateRequestDTO.getOpenTime()); newStore.setCloseTime(storeCreateRequestDTO.getCloseTime()); newStore.setContactNumber(storeCreateRequestDTO.getContactNumber()); diff --git a/src/main/java/com/jangburich/domain/store/domain/StoreAdditionalInfoCreateRequestDTO.java b/src/main/java/com/jangburich/domain/store/domain/StoreAdditionalInfoCreateRequestDTO.java new file mode 100644 index 0000000..e87e09b --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/domain/StoreAdditionalInfoCreateRequestDTO.java @@ -0,0 +1,15 @@ +package com.jangburich.domain.store.domain; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class StoreAdditionalInfoCreateRequestDTO { + private Boolean reservationAvailable; + private Long maxReservation; + private Long minPrepayment; + private Long prepaymentDuration; +} diff --git a/src/main/java/com/jangburich/domain/store/domain/StoreCreateRequestDTO.java b/src/main/java/com/jangburich/domain/store/domain/StoreCreateRequestDTO.java index 37d5d0c..0ff8a97 100644 --- a/src/main/java/com/jangburich/domain/store/domain/StoreCreateRequestDTO.java +++ b/src/main/java/com/jangburich/domain/store/domain/StoreCreateRequestDTO.java @@ -1,5 +1,9 @@ package com.jangburich.domain.store.domain; +import java.time.DayOfWeek; +import java.time.LocalTime; +import java.util.List; + import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import lombok.Getter; @@ -17,10 +21,6 @@ public class StoreCreateRequestDTO { private Category category; private String representativeImage; - private Boolean reservationAvailable; - private Long maxReservation; - private Long minPrepayment; - private Long prepaymentDuration; private String introduction; private String contactNumber; @@ -31,7 +31,7 @@ public class StoreCreateRequestDTO { private String location; // business hour - private String dayOfWeek; - private String openTime; - private String closeTime; + private List dayOfWeek; + private LocalTime openTime; + private LocalTime closeTime; } diff --git a/src/main/java/com/jangburich/domain/store/domain/StoreGetResponseDTO.java b/src/main/java/com/jangburich/domain/store/domain/StoreGetResponseDTO.java index d99e4c1..e2a0c13 100644 --- a/src/main/java/com/jangburich/domain/store/domain/StoreGetResponseDTO.java +++ b/src/main/java/com/jangburich/domain/store/domain/StoreGetResponseDTO.java @@ -1,5 +1,9 @@ package com.jangburich.domain.store.domain; +import java.time.DayOfWeek; +import java.time.LocalTime; +import java.util.List; + import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import lombok.Getter; @@ -27,15 +31,16 @@ public class StoreGetResponseDTO { private Double longitude; private String address; private String location; - private String dayOfWeek; - private String openTime; - private String closeTime; + private List dayOfWeek; + private LocalTime openTime; + private LocalTime closeTime; public StoreGetResponseDTO(Long id, String ownerId, String name, Category category, String representativeImage, Boolean reservationAvailable, Long maxReservation, Long minPrepayment, Long prepaymentDuration, String introduction, - Double latitude, Double longitude, String address, String location, String dayOfWeek, String openTime, - String closeTime) { + Double latitude, Double longitude, String address, String location, List dayOfWeek, + LocalTime openTime, + LocalTime closeTime) { this.id = id; this.ownerId = ownerId; this.name = name; @@ -71,7 +76,7 @@ public StoreGetResponseDTO of(Store store) { store.getLongitude(), store.getAddress(), store.getLocation(), - store.getDayOfWeek(), + store.getWorkDays(), store.getOpenTime(), store.getCloseTime() ); diff --git a/src/main/java/com/jangburich/domain/store/domain/StoreUpdateRequestDTO.java b/src/main/java/com/jangburich/domain/store/domain/StoreUpdateRequestDTO.java index 2d2fec2..81f686b 100644 --- a/src/main/java/com/jangburich/domain/store/domain/StoreUpdateRequestDTO.java +++ b/src/main/java/com/jangburich/domain/store/domain/StoreUpdateRequestDTO.java @@ -1,5 +1,9 @@ package com.jangburich.domain.store.domain; +import java.time.DayOfWeek; +import java.time.LocalTime; +import java.util.List; + import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import lombok.Getter; @@ -22,7 +26,7 @@ public class StoreUpdateRequestDTO { private Double longitude; private String address; private String location; - private String dayOfWeek; - private String openTime; - private String closeTime; + private List dayOfWeek; + private LocalTime openTime; + private LocalTime closeTime; } diff --git a/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java b/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java index fde16c4..f588397 100644 --- a/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java +++ b/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RestController; import com.jangburich.domain.oauth.domain.CustomOAuthUser; +import com.jangburich.domain.store.domain.StoreAdditionalInfoCreateRequestDTO; import com.jangburich.domain.store.domain.StoreCreateRequestDTO; import com.jangburich.domain.store.domain.StoreGetResponseDTO; import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; @@ -39,6 +40,17 @@ public ResponseCustom createStore(Authentication authentication, .build()); } + @Operation(summary = "가게 추가정보 저장", description = "예약 가능 여부, 최소 선결제 금액, 선결제 사용 기간을 저장합니다.") + @PostMapping("/create/additionalInfo") + public ResponseCustom createAdditionalInfo(Authentication authentication, @RequestBody + StoreAdditionalInfoCreateRequestDTO storeAdditionalInfoCreateRequestDTO) { + CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal(); + storeService.CreateAdditionalInfo(customOAuthUser, storeAdditionalInfoCreateRequestDTO); + return ResponseCustom.OK(Message.builder() + .message("success") + .build()); + } + @Operation(summary = "가게 정보 수정", description = "가게 정보를 수정합니다.") @PatchMapping("/{storeId}/update") public ResponseCustom updateStore(Authentication authentication, @PathVariable Long storeId, @RequestBody @@ -51,9 +63,9 @@ public ResponseCustom updateStore(Authentication authentication, @PathV } @Operation(summary = "가게 정보 조회", description = "가게 상세 정보를 조회합니다.") - @GetMapping("/{storeId}") - public ResponseCustom getStoreInfo(Authentication authentication, @PathVariable Long storeId) { + @GetMapping("") + public ResponseCustom getStoreInfo(Authentication authentication) { CustomOAuthUser customOAuth2User = (CustomOAuthUser)authentication.getPrincipal(); - return ResponseCustom.OK(storeService.getStoreInfo(customOAuth2User, storeId)); + return ResponseCustom.OK(storeService.getStoreInfo(customOAuth2User)); } } \ No newline at end of file diff --git a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java b/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java index c26ca86..b185b3b 100644 --- a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java +++ b/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java @@ -1,15 +1,13 @@ package com.jangburich.domain.store.domain.service; -import org.springframework.data.domain.Pageable; -import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.jangburich.domain.oauth.domain.CustomOAuthUser; import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; -import com.jangburich.domain.store.domain.Category; import com.jangburich.domain.store.domain.Store; +import com.jangburich.domain.store.domain.StoreAdditionalInfoCreateRequestDTO; import com.jangburich.domain.store.domain.StoreCreateRequestDTO; import com.jangburich.domain.store.domain.StoreGetResponseDTO; import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; @@ -25,88 +23,114 @@ @Transactional(readOnly = true) @RequiredArgsConstructor public class StoreService { - private final StoreRepository storeRepository; - private final OwnerRepository ownerRepository; - private final UserRepository userRepository; - - @Transactional - public void CreateStore(CustomOAuthUser customOAuth2User, StoreCreateRequestDTO storeCreateRequestDTO) { - User user = userRepository.findByProviderId(customOAuth2User.getUserId()) - .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); - - Owner owner = ownerRepository.findByUser(user) - .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); - - storeRepository.save(Store.of(owner, storeCreateRequestDTO)); - } - - @Transactional - public void updateStore(CustomOAuthUser customOAuth2User, Long storeId, - StoreUpdateRequestDTO storeUpdateRequestDTO) { - Store store = storeRepository.findById(storeId) - .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_STORE_ID)); - if (!store.getOwner().getUser().getProviderId().equals(customOAuth2User.getUserId())) { - throw new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION); - } - - storeRepository.save(updateStore(store, storeUpdateRequestDTO)); - } - - @Transactional - public Store updateStore(Store store, StoreUpdateRequestDTO storeUpdateRequestDTO) { - if (storeUpdateRequestDTO.getCategory() != null) { - store.setCategory(storeUpdateRequestDTO.getCategory()); - } - if (storeUpdateRequestDTO.getReservationAvailable() != null) { - store.setReservationAvailable(storeUpdateRequestDTO.getReservationAvailable()); - } - if (storeUpdateRequestDTO.getRepresentativeImage() != null) { - store.setRepresentativeImage(storeUpdateRequestDTO.getRepresentativeImage()); - } - if (storeUpdateRequestDTO.getMaxReservation() != null) { - store.setMaxReservation(storeUpdateRequestDTO.getMaxReservation()); - } - if (storeUpdateRequestDTO.getMinPrepayment() != null) { - store.setMinPrepayment(storeUpdateRequestDTO.getMinPrepayment()); - } - if (storeUpdateRequestDTO.getPrepaymentDuration() != null) { - store.setPrepaymentDuration(storeUpdateRequestDTO.getPrepaymentDuration()); - } - if (storeUpdateRequestDTO.getIntroduction() != null) { - store.setIntroduction(storeUpdateRequestDTO.getIntroduction()); - } - if (storeUpdateRequestDTO.getLatitude() != null) { - store.setLatitude(storeUpdateRequestDTO.getLatitude()); - } - if (storeUpdateRequestDTO.getLongitude() != null) { - store.setLongitude(storeUpdateRequestDTO.getLongitude()); - } - if (storeUpdateRequestDTO.getAddress() != null) { - store.setAddress(storeUpdateRequestDTO.getAddress()); - } - if (storeUpdateRequestDTO.getLocation() != null) { - store.setLocation(storeUpdateRequestDTO.getLocation()); - } - if (storeUpdateRequestDTO.getDayOfWeek() != null) { - store.setDayOfWeek(storeUpdateRequestDTO.getDayOfWeek()); - } - if (storeUpdateRequestDTO.getOpenTime() != null) { - store.setOpenTime(storeUpdateRequestDTO.getOpenTime()); - } - if (storeUpdateRequestDTO.getCloseTime() != null) { - store.setCloseTime(storeUpdateRequestDTO.getCloseTime()); - } - return store; - } - - public StoreGetResponseDTO getStoreInfo(CustomOAuthUser customOAuth2User, Long storeId) { - Store store = storeRepository.findById(storeId) - .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_PARAMETER)); - - if (!store.getOwner().getUser().getProviderId().equals(customOAuth2User.getUserId())) { - throw new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION); - } - - return new StoreGetResponseDTO().of(store); - } + private final StoreRepository storeRepository; + private final OwnerRepository ownerRepository; + private final UserRepository userRepository; + + @Transactional + public void CreateStore(CustomOAuthUser customOAuth2User, StoreCreateRequestDTO storeCreateRequestDTO) { + User user = userRepository.findByProviderId(customOAuth2User.getUserId()) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Owner owner = ownerRepository.findByUser(user) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + storeRepository.save(Store.of(owner, storeCreateRequestDTO)); + } + + @Transactional + public void CreateAdditionalInfo(CustomOAuthUser customOAuthUser, + StoreAdditionalInfoCreateRequestDTO storeAdditionalInfoCreateRequestDTO) { + User user = userRepository.findByProviderId(customOAuthUser.getUserId()) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Owner owner = ownerRepository.findByUser(user) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Store store = storeRepository.findByOwner(owner) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + store.setReservationAvailable(storeAdditionalInfoCreateRequestDTO.getReservationAvailable()); + store.setMinPrepayment(storeAdditionalInfoCreateRequestDTO.getMinPrepayment()); + store.setMaxReservation(storeAdditionalInfoCreateRequestDTO.getMaxReservation()); + store.setPrepaymentDuration(storeAdditionalInfoCreateRequestDTO.getPrepaymentDuration()); + + storeRepository.save(store); + } + + @Transactional + public void updateStore(CustomOAuthUser customOAuth2User, Long storeId, + StoreUpdateRequestDTO storeUpdateRequestDTO) { + Store store = storeRepository.findById(storeId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_STORE_ID)); + if (!store.getOwner().getUser().getProviderId().equals(customOAuth2User.getUserId())) { + throw new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION); + } + + storeRepository.save(updateStore(store, storeUpdateRequestDTO)); + } + + @Transactional + public Store updateStore(Store store, StoreUpdateRequestDTO storeUpdateRequestDTO) { + if (storeUpdateRequestDTO.getCategory() != null) { + store.setCategory(storeUpdateRequestDTO.getCategory()); + } + if (storeUpdateRequestDTO.getReservationAvailable() != null) { + store.setReservationAvailable(storeUpdateRequestDTO.getReservationAvailable()); + } + if (storeUpdateRequestDTO.getRepresentativeImage() != null) { + store.setRepresentativeImage(storeUpdateRequestDTO.getRepresentativeImage()); + } + if (storeUpdateRequestDTO.getMaxReservation() != null) { + store.setMaxReservation(storeUpdateRequestDTO.getMaxReservation()); + } + if (storeUpdateRequestDTO.getMinPrepayment() != null) { + store.setMinPrepayment(storeUpdateRequestDTO.getMinPrepayment()); + } + if (storeUpdateRequestDTO.getPrepaymentDuration() != null) { + store.setPrepaymentDuration(storeUpdateRequestDTO.getPrepaymentDuration()); + } + if (storeUpdateRequestDTO.getIntroduction() != null) { + store.setIntroduction(storeUpdateRequestDTO.getIntroduction()); + } + if (storeUpdateRequestDTO.getLatitude() != null) { + store.setLatitude(storeUpdateRequestDTO.getLatitude()); + } + if (storeUpdateRequestDTO.getLongitude() != null) { + store.setLongitude(storeUpdateRequestDTO.getLongitude()); + } + if (storeUpdateRequestDTO.getAddress() != null) { + store.setAddress(storeUpdateRequestDTO.getAddress()); + } + if (storeUpdateRequestDTO.getLocation() != null) { + store.setLocation(storeUpdateRequestDTO.getLocation()); + } + if (storeUpdateRequestDTO.getDayOfWeek() != null) { + store.setWorkDays(storeUpdateRequestDTO.getDayOfWeek()); + } + if (storeUpdateRequestDTO.getOpenTime() != null) { + store.setOpenTime(storeUpdateRequestDTO.getOpenTime()); + } + if (storeUpdateRequestDTO.getCloseTime() != null) { + store.setCloseTime(storeUpdateRequestDTO.getCloseTime()); + } + return store; + } + + public StoreGetResponseDTO getStoreInfo(CustomOAuthUser customOAuth2User) { + User user = userRepository.findByProviderId(customOAuth2User.getUserId()) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Owner owner = ownerRepository.findByUser(user) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Store store = storeRepository.findByOwner(owner) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_PARAMETER)); + + if (!store.getOwner().getUser().getProviderId().equals(customOAuth2User.getUserId())) { + throw new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION); + } + + return new StoreGetResponseDTO().of(store); + } }