Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
wellbeing-dough committed Oct 19, 2023
2 parents 43692ce + 73a1c9c commit ee4510e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import co.kr.jurumarble.comment.enums.Region;
import co.kr.jurumarble.drink.controller.request.*;
import co.kr.jurumarble.drink.controller.response.GetDrinkResponse;
import co.kr.jurumarble.drink.controller.response.GetEnjoyedResponse;
import co.kr.jurumarble.drink.controller.response.GetHotDrinksResponse;
import co.kr.jurumarble.drink.controller.response.GetMapInDrinksResponse;
import co.kr.jurumarble.drink.controller.response.*;
import co.kr.jurumarble.drink.service.DrinkService;
import co.kr.jurumarble.drink.service.response.GetDrinkServiceResponse;
import co.kr.jurumarble.vote.enums.SortByType;
Expand Down Expand Up @@ -60,9 +57,9 @@ public ResponseEntity<Slice<DrinkData>> getDrinks(@RequestParam(required = false

@Operation(summary = "즐긴 술 리스트 조회", description = "파라미터에 keyeword, sortBy, page, size, category 보내주시면 됩니다. 검색이 아니면 keyword = 에 값 없이 보내주시고, 필터로 지역을 추가해서 조회 가능하고 지역없이 조회하면 전체 전통주 이름순으로 나옵니다.")
@GetMapping("/enjoys")
public ResponseEntity<Slice<DrinkData>> getEnjoyDrinks(@RequestAttribute Long userId, @RequestParam(required = false) Region region, @RequestParam int page, @RequestParam int size) {
public ResponseEntity<UsersEnjoyDrinks> getEnjoyDrinks(@RequestAttribute Long userId, @RequestParam(required = false) Region region, @RequestParam int page, @RequestParam int size) {
String regionName = (region != null) ? region.getName() : null;
Slice<DrinkData> drinkList = drinkService.getEnjoyDrinks(userId, regionName, page, size);
UsersEnjoyDrinks drinkList = drinkService.getEnjoyDrinks(userId, regionName, page, size);
return ResponseEntity.status(HttpStatus.OK)
.body(drinkList);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package co.kr.jurumarble.drink.controller.response;

import co.kr.jurumarble.drink.controller.request.DrinkData;
import lombok.Getter;
import org.springframework.data.domain.Slice;

@Getter
public class UsersEnjoyDrinks {
private Long enjoyedDrinkCount;
private Slice<DrinkData> drinkData;

public UsersEnjoyDrinks(Long enjoyedDrinkCount, Slice<DrinkData> drinkData) {
this.enjoyedDrinkCount = enjoyedDrinkCount;
this.drinkData = drinkData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public interface EnjoyDrinkRepository extends JpaRepository<EnjoyDrink, Long>, E

long countByDrinkId(Long drinkId);

Long countByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import co.kr.jurumarble.drink.controller.request.UpdateDrink;
import co.kr.jurumarble.drink.controller.response.GetHotDrinksResponse;
import co.kr.jurumarble.drink.controller.response.GetMapInDrinksResponse;
import co.kr.jurumarble.drink.controller.response.UsersEnjoyDrinks;
import co.kr.jurumarble.drink.domain.dto.MapInDrinkData;
import co.kr.jurumarble.drink.domain.entity.Drink;
import co.kr.jurumarble.drink.domain.entity.EnjoyDrink;
Expand Down Expand Up @@ -121,9 +122,11 @@ public Slice<DrinkData> getDrinks(String keyword, String region, SortByType sort
throw new SortByNotFountException();
}

public Slice<DrinkData> getEnjoyDrinks(Long userId, String regionName, int pageNum, int pageSize) {
public UsersEnjoyDrinks getEnjoyDrinks(Long userId, String regionName, int pageNum, int pageSize) {
List<DrinkData> drinksByEnjoyed = enjoyDrinkRepository.findDrinksByUserId(userId, regionName, pageNum, pageSize);
return pageableConverter.convertListToSlice(drinksByEnjoyed, pageNum, pageSize);
Slice<DrinkData> data = pageableConverter.convertListToSlice(drinksByEnjoyed, pageNum, pageSize);
Long enjoyedDrinksTotalCount = enjoyDrinkRepository.countByUserId(userId);
return new UsersEnjoyDrinks(enjoyedDrinksTotalCount, data);
}

public boolean checkEnjoyed(Long drinkId, Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public List<VoteCommonData> findVoteCommonDataByTime(String keyword, Pageable pa
vote.filteredGender,
vote.filteredAge,
vote.filteredMbti,
voteResult.count().as("voteCount"),
voteResult.id.count().as("votedCount"),
vote.voteType,
vote.createdDate.as("createdAt")
)
Expand Down Expand Up @@ -148,7 +148,7 @@ public List<VoteCommonData> findVoteCommonDataByTimeAndUserId(Long userId, Strin
vote.filteredGender,
vote.filteredAge,
vote.filteredMbti,
voteResult.count().as("voteCount"),
voteResult.id.count().as("votedCount"),
vote.voteType,
vote.createdDate.as("createdAt")
))
Expand Down

0 comments on commit ee4510e

Please sign in to comment.