Skip to content

Commit

Permalink
[feat] 카테고리에 해당하는 모임 조회 API 구현
Browse files Browse the repository at this point in the history
[feat] 카테고리에 해당하는 모임 조회 API 구현
  • Loading branch information
lreowy authored Jul 12, 2024
2 parents b8ca8c7 + ab20909 commit 679d006
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;

@RestController
Expand Down Expand Up @@ -47,4 +48,10 @@ public ApiResponseDto<SubmittedMoimResponse> getSubmittedMoimDetail(@PathVariabl
return ApiResponseDto.success(SuccessCode.SUBMITTED_MOIM_DETAIL_GET_SUCCESS,
moimQueryService.getSubmittedMoimDetail(moimId));
}

@GetMapping("/v1/moim-list")
public ApiResponseDto getMoimListByCategory(@RequestParam String category) {
return ApiResponseDto.success(SuccessCode.MOIM_LIST_BY_CATEGORY_GET_SUCCESS,
moimQueryService.getMoimListByCategory(category));
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/pickple/server/api/moim/domain/Moim.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Moim extends BaseTimeEntity {
private Host host;

@JdbcTypeCode(SqlTypes.JSON)
private CategoryInfo category;
private CategoryInfo categoryList;

private boolean isOffline;

Expand Down Expand Up @@ -82,7 +82,7 @@ public class Moim extends BaseTimeEntity {
@Builder
public Moim(
final Host host,
final CategoryInfo category,
final CategoryInfo categoryList,
final boolean isOffline,
final String spot,
final DateInfo dateList,
Expand All @@ -96,7 +96,7 @@ public Moim(
final MoimState moimState
) {
this.host = host;
this.category = category;
this.categoryList = categoryList;
this.isOffline = isOffline;
this.spot = spot;
this.dateList = dateList;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pickple.server.api.moim.dto.response;

import com.pickple.server.api.moim.domain.DateInfo;
import lombok.Builder;

@Builder
public record MoimByCategoryResponse(
Long moimId,
int dayOfDay,
String title,
String hostNickName,
DateInfo dateList,
String moimImageUrl,
String hostImageUrl
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import com.pickple.server.api.moim.domain.Moim;
import com.pickple.server.global.exception.CustomException;
import com.pickple.server.global.response.enums.ErrorCode;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MoimRepository extends JpaRepository<Moim, Long> {
Optional<Moim> findMoimById(Long id);
Expand All @@ -13,4 +16,10 @@ default Moim findMoimByIdOrThrow(Long id) {
return findMoimById(id)
.orElseThrow(() -> new CustomException(ErrorCode.MOIM_NOT_FOUND));
}

@Query(value = "SELECT * FROM moims WHERE EXISTS (" +
"SELECT 1 FROM jsonb_each_text(category_list) AS categories " +
"WHERE categories.value = :category)",
nativeQuery = true)
List<Moim> findMoimListByCategory(@Param("category") String category);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void createMoim(Long hostId, MoimCreateRequest request) {
Host host = hostRepository.findHostByIdOrThrow(hostId);
Moim moim = Moim.builder()
.host(host)
.category(request.categoryList())
.categoryList(request.categoryList())
.isOffline(request.isOffline())
.spot(request.spot())
.dateList(request.dateList())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.pickple.server.api.moim.service;

import com.pickple.server.api.moim.domain.Moim;
import com.pickple.server.api.moim.dto.response.MoimByCategoryResponse;
import com.pickple.server.api.moim.dto.response.MoimDetailResponse;
import com.pickple.server.api.moim.dto.response.SubmittedMoimResponse;
import com.pickple.server.api.moim.repository.MoimRepository;
import com.pickple.server.global.util.DateUtil;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -44,4 +47,19 @@ public SubmittedMoimResponse getSubmittedMoimDetail(final Long moimId) {
.moimImageUrl(moim.getImageList().getImageUrl1())
.build();
}

public List<MoimByCategoryResponse> getMoimListByCategory(final String category) {
List<Moim> moimList = moimRepository.findMoimListByCategory(category);
return moimList.stream()
.map(oneMoim -> MoimByCategoryResponse.builder()
.moimId(oneMoim.getId())
.dayOfDay(DateUtil.calculateDayOfDay(oneMoim.getDateList().getDate()))
.title(oneMoim.getTitle())
.hostNickName(oneMoim.getHost().getNickname())
.dateList(oneMoim.getDateList())
.moimImageUrl(oneMoim.getImageList().getImageUrl1())
.hostImageUrl(oneMoim.getHost().getImageUrl())
.build())
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum SuccessCode {
PRESIGNED_URL_GET_SUCCESS(20008, HttpStatus.OK, "presigned url 발급 성공"),
SUBMITTED_MOIM_DETAIL_GET_SUCCESS(20008, HttpStatus.OK, "신청한 모임 상세 정보 조회 성공"),
HOST_POST_SUCCESS(20009, HttpStatus.OK, "공지사항 작성 성공"),

MOIM_LIST_BY_CATEGORY_GET_SUCCESS(20010, HttpStatus.OK, "카테고리에 해당하는 모임 조회 성공"),

//201 Created
MOIM_CREATE_SUCCESS(20100, HttpStatus.CREATED, "모임 개설 성공");

Expand Down

0 comments on commit 679d006

Please sign in to comment.