Skip to content

Commit

Permalink
feat : 즐긴 술 리스트 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jonghyunhub committed Sep 4, 2023
1 parent eadb3c8 commit ab27dd9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,26 @@ public ResponseEntity<List<GetHotDrinksResponse>> getHotDrinks() {

@Operation(summary = "전통주 리스트 조회", description = "파라미터에 keyeword, sortBy, page, size, category 보내주시면 됩니다. 검색이 아니면 keyword = 에 값 없이 보내주시고, 필터로 지역을 추가해서 조회 가능하고 지역없이 조회하면 전체 전통주 이름순으로 나옵니다.")
@GetMapping("")
public ResponseEntity<Slice<DrinkData>> getDrinkList(@RequestParam(required = false) String keyword, @RequestParam(required = false) Region region, @RequestParam int page, @RequestParam int size) {
public ResponseEntity<Slice<DrinkData>> getDrinks(@RequestParam(required = false) String keyword, @RequestParam(required = false) Region region, @RequestParam int page, @RequestParam int size) {
String regionName = (region != null) ? region.getName() : null;
Slice<DrinkData> drinkList = drinkService.getDrinkList(keyword, regionName, page, size);
Slice<DrinkData> drinkList = drinkService.getDrinks(keyword, regionName, page, size);
return ResponseEntity.status(HttpStatus.OK)
.body(drinkList);
}

@Operation(summary = "즐긴 술 리스트 조회", description = "파라미터에 keyeword, sortBy, page, size, category 보내주시면 됩니다. 검색이 아니면 keyword = 에 값 없이 보내주시고, 필터로 지역을 추가해서 조회 가능하고 지역없이 조회하면 전체 전통주 이름순으로 나옵니다.")
@GetMapping("/enjoys")
public ResponseEntity<Slice<DrinkData>> getEnjoyDrinks(@RequestAttribute Long userId ,@RequestParam int page, @RequestParam int size) {
Slice<DrinkData> drinkList = drinkService.getEnjoyDrinks(userId, page, size);
return ResponseEntity.status(HttpStatus.OK)
.body(drinkList);
}


@Operation(summary = "전통주 지도 조회", description = "요청시 쿼리 파라미터로 좌측상단 좌표, 우측상단 좌표 보내주세요")
@GetMapping("/map")
public ResponseEntity<Slice<GetMapInDrinksResponse>> getMapInDrinks(@RequestParam Double startX, @RequestParam Double startY, @RequestParam Double endX, @RequestParam Double endY, @RequestParam int page, @RequestParam int size) {
Slice<GetMapInDrinksResponse> drinks = drinkService.getMapInDrinks(startX, startY, endX, endY, page, size);
return new ResponseEntity(drinks, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.kr.jurumarble.drink.controller.request;

import co.kr.jurumarble.drink.domain.entity.Drink;
import lombok.*;

@Getter
Expand All @@ -21,4 +22,20 @@ public class DrinkData {
private String image;
private Double latitude;
private Double longitude;

public DrinkData(Drink drink) {
this.id = drink.getId();
this.name = drink.getName();
this.type = drink.getType();
this.productName = drink.getProductName();
this.alcoholicBeverage = drink.getAlcoholicBeverage();
this.rawMaterial = drink.getRawMaterial();
this.capacity = drink.getCapacity();
this.manufactureAddress = drink.getManufactureAddress();
this.region = drink.getRegion();
this.price = drink.getPrice();
this.image = drink.getImage();
this.latitude = drink.getLatitude();
this.longitude = drink.getLongitude();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import co.kr.jurumarble.drink.domain.entity.EnjoyDrink;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface EnjoyDrinkRepository extends JpaRepository<EnjoyDrink, Long> {

Optional<EnjoyDrink> findByUserIdAndDrinkId(Long userId, Long drinkId);

List<EnjoyDrink> findByUserId(Long userId);
}
21 changes: 20 additions & 1 deletion src/main/java/co/kr/jurumarble/drink/service/DrinkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,27 @@ private List<GetMapInDrinksResponse> getGetMapInDrinksResponses(Slice<MapInDrink
.collect(Collectors.toList());
}

public Slice<DrinkData> getDrinkList(String keyword, String region, int pageNum, int pageSize) {
public Slice<DrinkData> getDrinks(String keyword, String region, int pageNum, int pageSize) {
List<DrinkData> drinks = drinkRepository.getDrinks(keyword, region, pageNum, pageSize);
return pageableConverter.convertListToSlice(drinks, pageNum, pageSize);
}

public Slice<DrinkData> getEnjoyDrinks(Long userId, int pageNum, int pageSize) {
List<EnjoyDrink> enjoyDrinks = enjoyDrinkRepository.findByUserId(userId);
List<Long> drinkIds = extractDrinkIds(enjoyDrinks);
List<DrinkData> drinksByEnjoyed = findDrinksByDrinkIds(drinkIds);
return pageableConverter.convertListToSlice(drinksByEnjoyed, pageNum, pageSize);
}

private List<Long> extractDrinkIds(List<EnjoyDrink> enjoyDrinks) {
return enjoyDrinks.stream()
.map(EnjoyDrink::getDrinkId)
.collect(Collectors.toList());
}

private List<DrinkData> findDrinksByDrinkIds(List<Long> drinkIds) {
return drinkRepository.findDrinksByIdIn(drinkIds).stream()
.map(DrinkData::new)
.collect(Collectors.toList());
}
}

0 comments on commit ab27dd9

Please sign in to comment.