Skip to content

Commit

Permalink
fix : dayOfWeek 타입 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunWoo9930 committed Nov 18, 2024
1 parent 4b95a7a commit c251610
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/jangburich/domain/store/domain/Store.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<DayOfWeek> 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;
Expand All @@ -97,7 +109,7 @@ public static Store of(Owner owner, StoreCreateRequestDTO storeCreateRequestDTO)
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package com.jangburich.domain.store.domain;public class StoreAdditionalInfoCreateRequestDTO {
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,7 +35,7 @@ public class StoreCreateRequestDTO {
private String location;

// business hour
private String dayOfWeek;
private String openTime;
private String closeTime;
private List<DayOfWeek> dayOfWeek;
private LocalTime openTime;
private LocalTime closeTime;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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> 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> dayOfWeek,
LocalTime openTime,
LocalTime closeTime) {
this.id = id;
this.ownerId = ownerId;
this.name = name;
Expand Down Expand Up @@ -71,7 +76,7 @@ public StoreGetResponseDTO of(Store store) {
store.getLongitude(),
store.getAddress(),
store.getLocation(),
store.getDayOfWeek(),
store.getWorkDays(),
store.getOpenTime(),
store.getCloseTime()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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> dayOfWeek;
private LocalTime openTime;
private LocalTime closeTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public ResponseCustom<Message> updateStore(Authentication authentication, @PathV
}

@Operation(summary = "가게 정보 조회", description = "가게 상세 정보를 조회합니다.")
@GetMapping("/{storeId}")
public ResponseCustom<StoreGetResponseDTO> getStoreInfo(Authentication authentication, @PathVariable Long storeId) {
@GetMapping("")
public ResponseCustom<StoreGetResponseDTO> getStoreInfo(Authentication authentication) {
CustomOAuthUser customOAuth2User = (CustomOAuthUser)authentication.getPrincipal();
return ResponseCustom.OK(storeService.getStoreInfo(customOAuth2User, storeId));
return ResponseCustom.OK(storeService.getStoreInfo(customOAuth2User));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
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.StoreCreateRequestDTO;
import com.jangburich.domain.store.domain.StoreGetResponseDTO;
Expand All @@ -25,88 +22,94 @@
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class StoreService {
private final StoreRepository storeRepository;
private final OwnerRepository ownerRepository;
private final UserRepository userRepository;
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));
@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));
Owner owner = ownerRepository.findByUser(user)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));

storeRepository.save(Store.of(owner, storeCreateRequestDTO));
}
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);
}
@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));
}
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;
}
@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, Long storeId) {
Store store = storeRepository.findById(storeId)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_PARAMETER));
public StoreGetResponseDTO getStoreInfo(CustomOAuthUser customOAuth2User) {
User user = userRepository.findByProviderId(customOAuth2User.getUserId())
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));

if (!store.getOwner().getUser().getProviderId().equals(customOAuth2User.getUserId())) {
throw new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION);
}
Owner owner = ownerRepository.findByUser(user)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));

return new StoreGetResponseDTO().of(store);
}
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);
}
}

0 comments on commit c251610

Please sign in to comment.