Skip to content

Commit

Permalink
feat : 추가 정보 저장 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunWoo9930 committed Nov 18, 2024
1 parent c251610 commit a71c951
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
4 changes: 0 additions & 4 deletions src/main/java/com/jangburich/domain/store/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a71c951

Please sign in to comment.