Skip to content

Commit

Permalink
Merge pull request 9oormthon-univ#39 from 9oormthon-univ/feat/store
Browse files Browse the repository at this point in the history
fix : menu 관련 api 반환 값 변경
  • Loading branch information
HyunWoo9930 authored Nov 19, 2024
2 parents 6ab07cd + 09334c0 commit a9f6131
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -18,6 +17,7 @@
import com.jangburich.domain.menu.domain.MenuUpdateRequestDTO;
import com.jangburich.domain.menu.domain.service.MenuService;
import com.jangburich.domain.oauth.domain.CustomOAuthUser;
import com.jangburich.global.payload.Message;
import com.jangburich.global.payload.ResponseCustom;

import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -32,31 +32,31 @@ public class MenuController {
private final MenuService menuService;

@PostMapping("/register")
public ResponseCustom<String> registerMenu(Authentication authentication,
public ResponseCustom<Message> registerMenu(Authentication authentication,
@RequestBody MenuCreateRequestDTO menuCreateRequestDTO) {
CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal();
menuService.registerMenu(customOAuthUser, menuCreateRequestDTO);
return ResponseCustom.OK("success");
return ResponseCustom.OK(Message.builder().message("success").build());
}

@PatchMapping("/update/{id}")
public ResponseCustom<String> updateMenu(Authentication authentication, @PathVariable Long id,
public ResponseCustom<Message> updateMenu(Authentication authentication, @PathVariable Long id,
@RequestBody MenuUpdateRequestDTO menuUpdateRequestDTO) {
CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal();
menuService.updateMenu(customOAuthUser, id, menuUpdateRequestDTO);
return ResponseCustom.OK("success");
return ResponseCustom.OK(Message.builder().message("success").build());
}

@DeleteMapping("/{id}")
public ResponseCustom<String> deleteMenu(Authentication authentication, @PathVariable Long id) {
public ResponseCustom<Message> deleteMenu(Authentication authentication, @PathVariable Long id) {
CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal();
menuService.deleteMenu(customOAuthUser, id);
return ResponseCustom.OK("success");
return ResponseCustom.OK(Message.builder().message("success").build());
}

@GetMapping("")
public ResponseCustom<List<MenuGetResponseDTO>> getMenu(Authentication authentication) {
CustomOAuthUser customOAuthUser = (CustomOAuthUser) authentication.getPrincipal();
CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal();
List<MenuGetResponseDTO> menu = menuService.getMenu(customOAuthUser);
return ResponseCustom.OK(menu);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package com.jangburich.domain.store.domain;

import com.jangburich.domain.team.domain.Team;
import com.querydsl.core.annotations.QueryProjection;

import lombok.Builder;

@Builder
public record StoreTeamResponseDTO(
Long id,
Integer point,
Integer remainPoint,
Long teamId,
String teamName,
String teamDescription,
Long storeId

) {
@QueryProjection
public StoreTeamResponseDTO(Long id, Integer point, Long teamId, String teamName, Long storeId) {
public StoreTeamResponseDTO(Long id, Integer remainPoint, Long teamId, String teamName, String teamDescription,
Long storeId) {
this.id = id;
this.point = point;
this.remainPoint = remainPoint;
this.teamId = teamId;
this.teamName = teamName;
this.teamDescription = teamDescription;
this.storeId = storeId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ public ResponseCustom<Message> createAdditionalInfo(Authentication authenticatio
}

@Operation(summary = "가게 정보 수정", description = "가게 정보를 수정합니다.")
@PatchMapping("/{storeId}/update")
public ResponseCustom<Message> updateStore(Authentication authentication, @PathVariable Long storeId,
@PatchMapping("/update")
public ResponseCustom<Message> updateStore(Authentication authentication,
@RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO) {
CustomOAuthUser principal = (CustomOAuthUser)authentication.getPrincipal();
storeService.updateStore(principal, storeId, storeUpdateRequestDTO);
storeService.updateStore(AuthenticationParser.parseUserId(authentication), storeUpdateRequestDTO);
return ResponseCustom.OK(Message.builder().message("success").build());
}

Expand Down Expand Up @@ -120,6 +119,7 @@ public ResponseCustom<PaymentGroupDetailResponse> getPaymentGroupDetail(Authenti
@Operation(summary = "결제 내역 조회", description = "가게에서 일어난 결제 내역을 조회합니다.")
@GetMapping("/payment_history")
public ResponseCustom<?> getPaymentHistory(Authentication authentication, Pageable pageable) {
return ResponseCustom.OK(storeService.getPaymentHistory(AuthenticationParser.parseUserId(authentication), pageable));
return ResponseCustom.OK(
storeService.getPaymentHistory(AuthenticationParser.parseUserId(authentication), pageable));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PaymentGroupDetailResponse {
private Integer remainPoint;
private String teamLeaderName;
private String teamLeaderPhoneNum;
// TODO 이거 아니고, order 결제 내역으로 변경해야함.
private Page<TeamChargeHistoryResponse> historyResponses;

public static PaymentGroupDetailResponse create(String teamName, Integer point, Integer remainPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ public void createAdditionalInfo(CustomOAuthUser customOAuthUser,
}

@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())) {
public void updateStore(String userId, StoreUpdateRequestDTO storeUpdateRequestDTO) {
User user = userRepository.findByProviderId(userId)
.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));

if (!store.getOwner().getUser().getProviderId().equals(userId)) {
throw new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION);
}

Expand Down Expand Up @@ -167,11 +173,8 @@ public Page<StoreTeamResponseDTO> getPaymentGroup(String userId, Pageable pageab
return storeTeamRepository.findAllByStore(store, pageable);
}

public Page<SearchStoresResponse> searchByCategory(final Authentication authentication,
final Integer searchRadius,
final Category category,
final StoreSearchCondition storeSearchCondition,
final Pageable pageable) {
public Page<SearchStoresResponse> searchByCategory(final Authentication authentication, final Integer searchRadius,
final Category category, final StoreSearchCondition storeSearchCondition, final Pageable pageable) {
String parsed = AuthenticationParser.parseUserId(authentication);
User user = userRepository.findByProviderId(parsed)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));
Expand All @@ -180,8 +183,7 @@ public Page<SearchStoresResponse> searchByCategory(final Authentication authenti
}

public Page<SearchStoresResponse> searchStores(final Authentication authentication, final String keyword,
final StoreSearchConditionWithType storeSearchConditionWithType,
final Pageable pageable) {
final StoreSearchConditionWithType storeSearchConditionWithType, final Pageable pageable) {
String parsed = AuthenticationParser.parseUserId(authentication);
User user = userRepository.findByProviderId(parsed)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));
Expand Down

0 comments on commit a9f6131

Please sign in to comment.