From ba8331b72e04f09f1ecc661e94643b0827aaac6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=ED=98=81?= Date: Mon, 18 Nov 2024 22:42:13 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20Team=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EC=9D=BC=EA=B8=89=20?= =?UTF-8?q?=EC=BB=AC=EB=A0=89=EC=85=98=ED=99=94=20(#18)=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 결제 기능 요구사항 반영 * feat: Team 도메인 수정 및 일급 컬렉션화 (#3) --- .../domain/team/application/TeamService.java | 13 ++++++++ .../jangburich/domain/team/domain/Team.java | 16 ++++++++++ .../domain/team/domain/TeamLeader.java | 23 ++++++++++++++ .../domain/team/domain/TeamType.java | 22 ++++++++++++++ .../team/dto/request/RegisterTeamRequest.java | 4 +++ .../team/presentation/TeamController.java | 30 +++++++++++++++++++ 6 files changed, 108 insertions(+) create mode 100644 src/main/java/com/jangburich/domain/team/application/TeamService.java create mode 100644 src/main/java/com/jangburich/domain/team/domain/TeamLeader.java create mode 100644 src/main/java/com/jangburich/domain/team/domain/TeamType.java create mode 100644 src/main/java/com/jangburich/domain/team/dto/request/RegisterTeamRequest.java create mode 100644 src/main/java/com/jangburich/domain/team/presentation/TeamController.java diff --git a/src/main/java/com/jangburich/domain/team/application/TeamService.java b/src/main/java/com/jangburich/domain/team/application/TeamService.java new file mode 100644 index 0000000..af234d1 --- /dev/null +++ b/src/main/java/com/jangburich/domain/team/application/TeamService.java @@ -0,0 +1,13 @@ +package com.jangburich.domain.team.application; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class TeamService { + + +} diff --git a/src/main/java/com/jangburich/domain/team/domain/Team.java b/src/main/java/com/jangburich/domain/team/domain/Team.java index 3634cb6..621a694 100644 --- a/src/main/java/com/jangburich/domain/team/domain/Team.java +++ b/src/main/java/com/jangburich/domain/team/domain/Team.java @@ -1,5 +1,8 @@ package com.jangburich.domain.team.domain; +import jakarta.persistence.Embedded; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import java.util.HashSet; import java.util.Set; @@ -29,12 +32,25 @@ public class Team extends BaseEntity { @Column(name = "name") private String name; + @Column(name = "description") + private String description; + + @Column(name = "secret_code") + private String secretCode; + + @Embedded + private TeamLeader teamLeader; + @Column(name = "point") private Integer point; @Column(name = "member_limit") private Integer memberLimit; + @Enumerated(EnumType.STRING) + @Column(name = "team_type") + private TeamType teamType; + @ManyToMany(mappedBy = "teams") private Set users = new HashSet<>(); diff --git a/src/main/java/com/jangburich/domain/team/domain/TeamLeader.java b/src/main/java/com/jangburich/domain/team/domain/TeamLeader.java new file mode 100644 index 0000000..1bdba9c --- /dev/null +++ b/src/main/java/com/jangburich/domain/team/domain/TeamLeader.java @@ -0,0 +1,23 @@ +package com.jangburich.domain.team.domain; + +import jakarta.persistence.Embeddable; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; + +@Embeddable +@Getter +@NoArgsConstructor +public class TeamLeader { + private Long user_id; + private String accountNumber; + + public TeamLeader(Long user_id, String accountNumber) { + this.user_id = user_id; + this.accountNumber = accountNumber; + } + + public boolean isSameLeader(Long userId) { + return this.user_id.equals(userId); + } +} diff --git a/src/main/java/com/jangburich/domain/team/domain/TeamType.java b/src/main/java/com/jangburich/domain/team/domain/TeamType.java new file mode 100644 index 0000000..552f16d --- /dev/null +++ b/src/main/java/com/jangburich/domain/team/domain/TeamType.java @@ -0,0 +1,22 @@ +package com.jangburich.domain.team.domain; + +public enum TeamType { + INDIVIDUAL("개인"), + GATHERING("모임"), + FAMILY("가족"), + COMPANY("회사"), + CLUB("동아리"), + ALUMNI("동호회"), + STUDENT_ASSOCIATION("학생회"), + OTHER("기타"); + + private final String description; + + TeamType(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } +} diff --git a/src/main/java/com/jangburich/domain/team/dto/request/RegisterTeamRequest.java b/src/main/java/com/jangburich/domain/team/dto/request/RegisterTeamRequest.java new file mode 100644 index 0000000..993d7c4 --- /dev/null +++ b/src/main/java/com/jangburich/domain/team/dto/request/RegisterTeamRequest.java @@ -0,0 +1,4 @@ +package com.jangburich.domain.team.dto.request; + +public record RegisterTeamRequest() { +} diff --git a/src/main/java/com/jangburich/domain/team/presentation/TeamController.java b/src/main/java/com/jangburich/domain/team/presentation/TeamController.java new file mode 100644 index 0000000..5a51616 --- /dev/null +++ b/src/main/java/com/jangburich/domain/team/presentation/TeamController.java @@ -0,0 +1,30 @@ +package com.jangburich.domain.team.presentation; + +import com.jangburich.domain.team.application.TeamService; +import com.jangburich.domain.team.dto.request.RegisterTeamRequest; +import com.jangburich.global.payload.Message; +import com.jangburich.global.payload.ResponseCustom; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.Authentication; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "Team", description = "Team API") +@RestController +@RequiredArgsConstructor +@RequestMapping("/teams") +public class TeamController { + + private final TeamService teamService; + + @PostMapping + public ResponseCustom registerTeam( + Authentication authentication, + @RequestBody RegisterTeamRequest registerTeamRequest + ) { + return ResponseCustom.OK(); + } +} From c251610a34101ea7f182db70f270800c92dbdbe1 Mon Sep 17 00:00:00 2001 From: HyunWoo9930 Date: Mon, 18 Nov 2024 23:49:19 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix=20:=20dayOfWeek=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/OAuthUserService.java | 2 +- .../jangburich/domain/store/domain/Store.java | 20 ++- .../StoreAdditionalInfoCreateRequestDTO.java | 2 + .../store/domain/StoreCreateRequestDTO.java | 10 +- .../store/domain/StoreGetResponseDTO.java | 17 +- .../store/domain/StoreUpdateRequestDTO.java | 10 +- .../domain/controller/StoreController.java | 6 +- .../store/domain/service/StoreService.java | 159 +++++++++--------- 8 files changed, 128 insertions(+), 98 deletions(-) create mode 100644 src/main/java/com/jangburich/domain/store/domain/StoreAdditionalInfoCreateRequestDTO.java 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..857835b 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; @@ -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()); 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..9dbb717 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/domain/StoreAdditionalInfoCreateRequestDTO.java @@ -0,0 +1,2 @@ +package com.jangburich.domain.store.domain;public class StoreAdditionalInfoCreateRequestDTO { +} 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..cfbeeaf 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; @@ -31,7 +35,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..9adc069 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 @@ -51,9 +51,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..0b4b0d7 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,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; @@ -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); + } } From a71c951c68dd7832f231f436a67562b210ac849a Mon Sep 17 00:00:00 2001 From: HyunWoo9930 Date: Mon, 18 Nov 2024 23:55:29 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat=20:=20=EC=B6=94=EA=B0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A0=80=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jangburich/domain/store/domain/Store.java | 4 ---- .../StoreAdditionalInfoCreateRequestDTO.java | 15 ++++++++++++- .../store/domain/StoreCreateRequestDTO.java | 4 ---- .../domain/controller/StoreController.java | 12 +++++++++++ .../store/domain/service/StoreService.java | 21 +++++++++++++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) 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 857835b..3dbc358 100644 --- a/src/main/java/com/jangburich/domain/store/domain/Store.java +++ b/src/main/java/com/jangburich/domain/store/domain/Store.java @@ -99,10 +99,6 @@ 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()); diff --git a/src/main/java/com/jangburich/domain/store/domain/StoreAdditionalInfoCreateRequestDTO.java b/src/main/java/com/jangburich/domain/store/domain/StoreAdditionalInfoCreateRequestDTO.java index 9dbb717..e87e09b 100644 --- a/src/main/java/com/jangburich/domain/store/domain/StoreAdditionalInfoCreateRequestDTO.java +++ b/src/main/java/com/jangburich/domain/store/domain/StoreAdditionalInfoCreateRequestDTO.java @@ -1,2 +1,15 @@ -package com.jangburich.domain.store.domain;public class StoreAdditionalInfoCreateRequestDTO { +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 cfbeeaf..0ff8a97 100644 --- a/src/main/java/com/jangburich/domain/store/domain/StoreCreateRequestDTO.java +++ b/src/main/java/com/jangburich/domain/store/domain/StoreCreateRequestDTO.java @@ -21,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; 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 9adc069..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 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 0b4b0d7..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 @@ -7,6 +7,7 @@ import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; 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; @@ -37,6 +38,26 @@ public void CreateStore(CustomOAuthUser customOAuth2User, StoreCreateRequestDTO 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) {