Skip to content

Commit

Permalink
feature: 리베이스 머지 (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJejune committed Jul 17, 2023
1 parent a82cd57 commit 856597f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
package com.depromeet.oversweet.drink.controller;


import static org.springframework.http.HttpStatus.OK;

import java.time.LocalDate;
import java.util.List;

import com.depromeet.oversweet.search.dto.response.DrinkAllInfoResponse;
import com.depromeet.oversweet.search.service.DrinkSearchService;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.depromeet.oversweet.annotation.SecurityExclusion;
import com.depromeet.oversweet.domain.franchise.entity.FranchiseEntity;
import com.depromeet.oversweet.drink.dto.request.DrinkInfoRequest;
import com.depromeet.oversweet.drink.dto.request.DrinkWeeklySugarDateRequest;
import com.depromeet.oversweet.drink.dto.response.DrinkAllInfoResponse;
import com.depromeet.oversweet.drink.dto.response.DrinkDailySugarStatisticsResponse;
import com.depromeet.oversweet.drink.dto.response.DrinkDetailInfoResponse;
import com.depromeet.oversweet.drink.dto.response.DrinkRecommendResponse;
import com.depromeet.oversweet.drink.dto.response.DrinkRedisInfo;
import com.depromeet.oversweet.drink.dto.response.DrinkWeeklySugarStatisticsResponse;
import com.depromeet.oversweet.drink.service.DrinkDailyStatisticsService;
import com.depromeet.oversweet.drink.service.DrinkDetailSearchService;
import com.depromeet.oversweet.drink.service.DrinkRecommendService;
import com.depromeet.oversweet.drink.service.DrinkRedisService;
import com.depromeet.oversweet.drink.service.DrinkSearchService;
import com.depromeet.oversweet.drink.service.DrinkWeeklyStatisticsService;
import com.depromeet.oversweet.response.DataResponse;
import com.depromeet.oversweet.security.service.CustomUserDetails;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static org.springframework.http.HttpStatus.OK;

@Tag(name = "음료", description = "음료 관련 API")
@RestController
Expand All @@ -50,6 +53,7 @@ public class DrinkController {
private final DrinkWeeklyStatisticsService drinkWeeklyStatisticsService;
private final DrinkDetailSearchService drinkDetailSearchService;
private final DrinkRedisService drinkRedisService;
private final DrinkRecommendService drinkRecommendService;
private final DrinkSearchService drinkSearchService;

/**
Expand Down Expand Up @@ -77,10 +81,11 @@ public ResponseEntity<DataResponse<DrinkDailySugarStatisticsResponse>> retrieveU
@SecurityRequirement(name = "accessToken")
@GetMapping("/statistics/weekly")
public ResponseEntity<DataResponse<DrinkWeeklySugarStatisticsResponse>> retrieveUserWeeklySugarStatistics(
@RequestBody @Valid final DrinkWeeklySugarDateRequest request,
@RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
@RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
@AuthenticationPrincipal CustomUserDetails userDetails
) {
final DrinkWeeklySugarStatisticsResponse response = drinkWeeklyStatisticsService.retrieveUserWeeklySugarStatistics(userDetails.getId(), request);
final DrinkWeeklySugarStatisticsResponse response = drinkWeeklyStatisticsService.retrieveUserWeeklySugarStatistics(userDetails.getId(), startDate, endDate);
return ResponseEntity.ok()
.body(DataResponse.of(HttpStatus.OK, "유저가 먹은 주간 당 통계 조회 성공", response));
}
Expand All @@ -93,10 +98,11 @@ public ResponseEntity<DataResponse<DrinkWeeklySugarStatisticsResponse>> retrieve
@SecurityRequirement(name = "accessToken")
@GetMapping("/detail")
public ResponseEntity<DataResponse<DrinkDetailInfoResponse>> retrieveDrinkDetail(
@RequestBody @Valid final DrinkInfoRequest request,
@RequestParam @Valid @NotNull(message = "필수 값 입니다.") Long franchiseId,
@RequestParam @Valid @NotEmpty(message = "필수 값 입니다.") String drinkName,
@AuthenticationPrincipal CustomUserDetails userDetails
) {
DrinkDetailInfoResponse response = drinkDetailSearchService.retrieveDrinkDetail(userDetails.getId(), request);
DrinkDetailInfoResponse response = drinkDetailSearchService.retrieveDrinkDetail(userDetails.getId(), franchiseId, drinkName);
return ResponseEntity.ok().body(DataResponse.of(HttpStatus.OK, "음료 상세 조회 성공", response));
}

Expand All @@ -110,15 +116,17 @@ public ResponseEntity<DataResponse<List<DrinkRedisInfo>>> getOrCreateDrinkAtRedi
.body(DataResponse.of(OK, "레디스에 저장된 음료 목록 조회 성공", drinks));
}

@Operation(summary = "해당 프랜차이즈의 음료 목록을 키워드로 조회합니다.", description = "해당 프랜차이즈의 키워드에 매칭되는 음료 조회 API")
@ApiResponses(@ApiResponse(responseCode = "200", description = "해당 프랜차이즈의 키워드에 매칭되는 음료 조회 성공"))
@GetMapping("/{franchiseId}/search")
public ResponseEntity<DataResponse<List<DrinkAllInfoResponse>>> getDrinksByKeywordAndFranchise(
@PathVariable @Parameter(description = "프랜차이즈 Id") final Long franchiseId,
@RequestParam @Parameter(description = "프랜차이즈 검색을 위한 키워드") final String keyword) {
final List<DrinkAllInfoResponse> drinks = drinkSearchService.getDrinksByKeywordAndFranchise(franchiseId, keyword);
return ResponseEntity.ok()
.body(DataResponse.of(OK, "해당 프랜차이즈의 키워드에 매칭되는 음료 조회 성공", drinks));

/**
* 음료 사이즈 기준으로 당 성분이 비슷한 음료 추천
*/
@Operation(summary = "음료 사이즈 기준으로 당 성분이 비슷한 음료 추천", description = "음료 사이즈 기준으로 당 성분이 비슷한 음료 추천")
@ApiResponses(@ApiResponse(responseCode = "200", description = "음료 사이즈 기준으로 당 성분이 비슷한 음료 추천"))
@SecurityExclusion
@GetMapping("/recommend/{drinkId}")
public ResponseEntity<DataResponse<DrinkRecommendResponse>> recommendDrink(@PathVariable Long drinkId) {
DrinkRecommendResponse response = drinkRecommendService.recommendDrink(drinkId);
return ResponseEntity.ok().body(DataResponse.of(OK, "음료 사이즈 기준으로 당 성분이 비슷한 음료 추천 성공", response));
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.depromeet.oversweet.common.dto.response.FranchiseInfo;
import com.depromeet.oversweet.search.dto.response.DrinkAllInfoResponse;
import com.depromeet.oversweet.search.dto.response.SearchInfoResponse;
import com.depromeet.oversweet.search.service.DrinkSearchService;
import com.depromeet.oversweet.response.DataResponse;
import com.depromeet.oversweet.search.service.DrinkSearchService;
import com.depromeet.oversweet.search.service.FranchiseSearchService;
import com.depromeet.oversweet.search.service.SearchService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -14,7 +14,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.depromeet.oversweet.drink.service;
package com.depromeet.oversweet.search.service;


import com.depromeet.oversweet.domain.drink.entity.DrinkEntity;
import com.depromeet.oversweet.domain.drink.repository.FindDrinksByFranchiseAndCategoryRepository;
import com.depromeet.oversweet.domain.drink.repository.FindDrinksByFranchiseAndKeywordRepository;
import com.depromeet.oversweet.domain.drink.repository.FindDrinksSearchRepository;
import com.depromeet.oversweet.domain.franchise.entity.FranchiseEntity;
import com.depromeet.oversweet.domain.franchise.repository.FindFranchiseRepository;
import com.depromeet.oversweet.drink.dto.response.DrinkAllInfoResponse;
import com.depromeet.oversweet.drink.vo.DrinkSameNameInfo;
import com.depromeet.oversweet.search.dto.response.DrinkAllInfoResponse;
import com.depromeet.oversweet.search.vo.DrinkSameNameInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -27,15 +27,15 @@
public class DrinkSearchService {

private final FindFranchiseRepository findFranchiseRepository;
private final FindDrinksByFranchiseAndKeywordRepository findDrinksByFranchiseAndKeywordRepository;
private final FindDrinksSearchRepository findDrinksSearchRepository;
private final FindDrinksByFranchiseAndCategoryRepository findDrinksByFranchiseAndCategoryRepository;

public List<DrinkAllInfoResponse> getDrinksByKeywordAndFranchise(final Long franchiseId, final String keyword) {
// 프랜차이즈 존재 여부 확인
final FranchiseEntity findFranchise = findFranchiseRepository.findFranchiseById(franchiseId);

// 해당 프랜차이즈의 키워드로 검색 되는 음료 검색
final List<DrinkEntity> findDrinks = findDrinksByFranchiseAndKeywordRepository.findDrinksByFranchiseAndKeyword(findFranchise.getId(), keyword);
final List<DrinkEntity> findDrinks = findDrinksSearchRepository.findDrinksByFranchiseAndKeyword(findFranchise.getId(), keyword);

// 키워드로 검색된 음료 목록 중 이름이 같은 것들로 묶어주기
// 묶은 목록 중 IsMiniMun 찾기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.depromeet.oversweet.domain.drink.entity.DrinkEntity;
import com.depromeet.oversweet.domain.drink.repository.FindDrinksByFranchiseAndCategoryRepository;
import com.depromeet.oversweet.domain.franchise.entity.FranchiseEntity;
import com.depromeet.oversweet.drink.dto.response.DrinkAllInfoResponse;
import com.depromeet.oversweet.search.dto.response.DrinkAllInfoResponse;
import com.depromeet.oversweet.search.service.DrinkSearchService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down

0 comments on commit 856597f

Please sign in to comment.