Skip to content

Commit

Permalink
Merge pull request #22 from 9oormthon-univ/feat/store
Browse files Browse the repository at this point in the history
Feat/store
  • Loading branch information
HyunWoo9930 authored Nov 18, 2024
2 parents 0a5b3f0 + a71c951 commit 2c51360
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 115 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
24 changes: 16 additions & 8 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 @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
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 @@ -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;

Expand All @@ -31,7 +31,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 @@ -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;
Expand Down Expand Up @@ -39,6 +40,17 @@ public ResponseCustom<Message> createStore(Authentication authentication,
.build());
}

@Operation(summary = "๊ฐ€๊ฒŒ ์ถ”๊ฐ€์ •๋ณด ์ €์žฅ", description = "์˜ˆ์•ฝ ๊ฐ€๋Šฅ ์—ฌ๋ถ€, ์ตœ์†Œ ์„ ๊ฒฐ์ œ ๊ธˆ์•ก, ์„ ๊ฒฐ์ œ ์‚ฌ์šฉ ๊ธฐ๊ฐ„์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.")
@PostMapping("/create/additionalInfo")
public ResponseCustom<Message> 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<Message> updateStore(Authentication authentication, @PathVariable Long storeId, @RequestBody
Expand All @@ -51,9 +63,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));
}
}
Loading

0 comments on commit 2c51360

Please sign in to comment.