Skip to content

Commit

Permalink
Merge pull request #163 from 9oormthon-univ/fix/storeDetail
Browse files Browse the repository at this point in the history
Fix/store detail
  • Loading branch information
HyunWoo9930 authored Nov 27, 2024
2 parents d52f7c2 + 4167458 commit 15a94cf
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -15,7 +14,6 @@
import org.springframework.web.bind.annotation.RestController;

import com.jangburich.domain.menu.domain.MenuCreateRequestDTO;
import com.jangburich.domain.menu.domain.MenuGetResponseDTO;
import com.jangburich.domain.menu.domain.MenuResponse;
import com.jangburich.domain.menu.domain.MenuUpdateRequestDTO;
import com.jangburich.domain.menu.service.MenuService;
Expand Down Expand Up @@ -58,9 +56,8 @@ public ResponseCustom<Message> deleteMenu(
}

@GetMapping("")
public ResponseCustom<Page<MenuResponse>> getMenu(
Authentication authentication, Pageable pageable) {
Page<MenuResponse> menu = menuService.getMenu(AuthenticationParser.parseUserId(authentication), pageable);
public ResponseCustom<List<MenuResponse>> getMenu(Authentication authentication) {
List<MenuResponse> menu = menuService.getMenu(AuthenticationParser.parseUserId(authentication));
return ResponseCustom.OK(menu);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.data.jpa.repository.Query;

public interface MenuRepository extends JpaRepository<Menu, Long> {
Page<MenuResponse> findAllByStore(Store store, Pageable pageable);
List<MenuResponse> findAllByStore(Store store);

@Query("SELECT m.id, m.price FROM Menu m WHERE m.id IN :menuIds")
List<Object[]> findPricesByMenuIds(List<Long> menuIds);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jangburich.domain.menu.service;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -74,7 +76,7 @@ public void deleteMenu(String customOAuthUser, Long id) {
menuRepository.delete(menu);
}

public Page<MenuResponse> getMenu(String customOAuthUser, Pageable pageable) {
public List<MenuResponse> getMenu(String customOAuthUser) {
User user = userRepository.findByProviderId(customOAuthUser)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));

Expand All @@ -84,6 +86,6 @@ public Page<MenuResponse> getMenu(String customOAuthUser, Pageable pageable) {
Store store = storeRepository.findByOwner(owner)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_STORE_ID));

return menuRepository.findAllByStore(store, pageable);
return menuRepository.findAllByStore(store);
}
}
20 changes: 15 additions & 5 deletions src/main/java/com/jangburich/domain/store/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.DayOfWeek;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
Expand Down Expand Up @@ -99,7 +100,9 @@ public static Store create(Owner owner) {
return newOwner;
}

public static Store of(Owner owner, StoreCreateRequestDTO storeCreateRequestDTO) {
public static Store of(Owner owner, StoreCreateRequestDTO storeCreateRequestDTO, List<DayOfWeek> dayOfWeeks) {
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");

Store newStore = new Store();
newStore.setOwner(owner);
newStore.setName(storeCreateRequestDTO.getStoreName());
Expand All @@ -108,11 +111,18 @@ public static Store of(Owner owner, StoreCreateRequestDTO storeCreateRequestDTO)
newStore.setLatitude(storeCreateRequestDTO.getLatitude());
newStore.setLongitude(storeCreateRequestDTO.getLongitude());
newStore.setAddress(storeCreateRequestDTO.getAddress());
newStore.setAddress(storeCreateRequestDTO.getAddress());
newStore.setLocation(storeCreateRequestDTO.getLocation());
newStore.setWorkDays(storeCreateRequestDTO.getDayOfWeek());
newStore.setOpenTime(storeCreateRequestDTO.getOpenTime());
newStore.setCloseTime(storeCreateRequestDTO.getCloseTime());
newStore.setWorkDays(dayOfWeeks);
newStore.setOpenTime(
storeCreateRequestDTO.getOpenTime() != null
? LocalTime.parse(storeCreateRequestDTO.getOpenTime(), timeFormatter)
: null
);
newStore.setCloseTime(
storeCreateRequestDTO.getCloseTime() != null
? LocalTime.parse(storeCreateRequestDTO.getCloseTime(), timeFormatter)
: null
);
newStore.setContactNumber(storeCreateRequestDTO.getPhoneNumber());
newStore.setReservationAvailable(storeCreateRequestDTO.getReservationAvailable());
newStore.setMaxReservation(storeCreateRequestDTO.getMaxReservation());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jangburich.domain.store.domain;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import com.jangburich.domain.menu.domain.MenuCreateRequestDTO;
Expand All @@ -17,6 +17,7 @@
@Setter
@RequiredArgsConstructor
public class StoreCreateRequestDTO {

private String storeName;
private String phoneNumber;
private String businessName;
Expand All @@ -30,21 +31,32 @@ public class StoreCreateRequestDTO {
@Enumerated(EnumType.STRING)
private Category category;

// address
private Double latitude;
private Double longitude;
private String address;
private String location;

// business hour
private List<DayOfWeek> dayOfWeek;
private LocalTime openTime;
private LocalTime closeTime;
private String dayOfWeek;
private String openTime;
private String closeTime;

private List<MenuCreateRequestDTO> menuCreateRequestDTOS;

private Long minPrepayment;
private Long prepaymentDuration;
private Boolean reservationAvailable;
private Long maxReservation;

private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm");

public void setOpenTime(LocalTime openTime) {
this.openTime = openTime != null ? openTime.format(TIME_FORMATTER) : null;
}

public void setCloseTime(LocalTime closeTime) {
this.closeTime = closeTime != null ? closeTime.format(TIME_FORMATTER) : null;
}
}



Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.jangburich.domain.store.domain;

import java.time.DayOfWeek;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;

import com.jangburich.domain.menu.domain.MenuResponse;

import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
Expand Down Expand Up @@ -31,16 +34,19 @@ public class StoreGetResponseDTO {
private Double longitude;
private String address;
private String location;
private List<DayOfWeek> dayOfWeek;
private LocalTime openTime;
private LocalTime closeTime;
private String dayOfWeek;
private String openTime;
private String closeTime;
private List<MenuResponse> menuResponses;

private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm");

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, List<DayOfWeek> dayOfWeek,
LocalTime openTime,
LocalTime closeTime) {
Double latitude, Double longitude, String address, String location, String dayOfWeek,
String openTime,
String closeTime, List<MenuResponse> menuResponses) {
this.id = id;
this.ownerId = ownerId;
this.name = name;
Expand All @@ -58,9 +64,27 @@ public StoreGetResponseDTO(Long id, String ownerId, String name, Category catego
this.dayOfWeek = dayOfWeek;
this.openTime = openTime;
this.closeTime = closeTime;
this.menuResponses = menuResponses;
}

public StoreGetResponseDTO of(Store store) {
private String convertDayOfWeekToKorean(DayOfWeek dayOfWeek) {
return switch (dayOfWeek) {
case MONDAY -> "์›”";
case TUESDAY -> "ํ™”";
case WEDNESDAY -> "์ˆ˜";
case THURSDAY -> "๋ชฉ";
case FRIDAY -> "๊ธˆ";
case SATURDAY -> "ํ† ";
case SUNDAY -> "์ผ";
default -> throw new IllegalArgumentException("Invalid DayOfWeek");
};
}

public StoreGetResponseDTO of(Store store, List<MenuResponse> menuResponses) {
String dayOfWeekString = store.getWorkDays().stream()
.map(this::convertDayOfWeekToKorean)
.collect(Collectors.joining(", "));

return new StoreGetResponseDTO(
store.getId(),
store.getOwner().getUser().getProviderId(),
Expand All @@ -76,9 +100,10 @@ public StoreGetResponseDTO of(Store store) {
store.getLongitude(),
store.getAddress(),
store.getLocation(),
store.getWorkDays(),
store.getOpenTime(),
store.getCloseTime()
dayOfWeekString,
store.getOpenTime().format(TIME_FORMATTER),
store.getCloseTime().format(TIME_FORMATTER),
menuResponses
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jangburich.domain.store.service;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
Expand All @@ -13,6 +14,7 @@

import com.jangburich.domain.menu.domain.Menu;
import com.jangburich.domain.menu.domain.MenuCreateRequestDTO;
import com.jangburich.domain.menu.domain.MenuResponse;
import com.jangburich.domain.menu.repository.MenuRepository;
import com.jangburich.domain.order.domain.Cart;
import com.jangburich.domain.order.domain.OrderResponse;
Expand Down Expand Up @@ -49,6 +51,7 @@
import com.jangburich.global.config.s3.S3Service;
import com.jangburich.global.error.DefaultNullPointerException;
import com.jangburich.global.payload.ErrorCode;
import com.jangburich.utils.DayOfWeekConverter;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -79,7 +82,9 @@ public void createStore(String authentication, StoreCreateRequestDTO storeCreate
Owner owner = ownerRepository.findByUser(user)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));

Store store = storeRepository.save(Store.of(owner, storeCreateRequestDTO));
List<DayOfWeek> dayOfWeekList = DayOfWeekConverter.convertStringToDayOfWeekList(storeCreateRequestDTO.getDayOfWeek());

Store store = storeRepository.save(Store.of(owner, storeCreateRequestDTO, dayOfWeekList));

store.setRepresentativeImage(s3Service.uploadImageToS3(image));

Expand All @@ -104,7 +109,6 @@ public void createStore(String authentication, StoreCreateRequestDTO storeCreate
}
}
}

}

@Transactional
Expand Down Expand Up @@ -206,7 +210,9 @@ public StoreGetResponseDTO getStoreInfo(String authentication) {
throw new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION);
}

return new StoreGetResponseDTO().of(store);
List<MenuResponse> menus = menuRepository.findAllByStore(store);

return new StoreGetResponseDTO().of(store, menus);
}

public List<com.jangburich.domain.store.dto.StoreTeamResponse> getPaymentGroup(String userId) {
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/jangburich/utils/DayOfWeekConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.jangburich.utils;

import java.time.DayOfWeek;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class DayOfWeekConverter {

public static DayOfWeek convertKoreanToDayOfWeek(String koreanDay) {
return switch (koreanDay.trim()) {
case "์›”" -> DayOfWeek.MONDAY;
case "ํ™”" -> DayOfWeek.TUESDAY;
case "์ˆ˜" -> DayOfWeek.WEDNESDAY;
case "๋ชฉ" -> DayOfWeek.THURSDAY;
case "๊ธˆ" -> DayOfWeek.FRIDAY;
case "ํ† " -> DayOfWeek.SATURDAY;
case "์ผ" -> DayOfWeek.SUNDAY;
default -> throw new IllegalArgumentException("Invalid day: " + koreanDay);
};
}

public static List<DayOfWeek> convertStringToDayOfWeekList(String daysString) {
return Arrays.stream(daysString.split(","))
.map(DayOfWeekConverter::convertKoreanToDayOfWeek)
.collect(Collectors.toList());
}
}

0 comments on commit 15a94cf

Please sign in to comment.