Skip to content

Commit

Permalink
[feat] 모임에 해당하는 호스트 정보 조회 api 구현
Browse files Browse the repository at this point in the history
[feat] 모임에 해당하는 호스트 정보 조회 api 구현
  • Loading branch information
bo-ram-bo-ram authored Jul 12, 2024
2 parents 3166860 + 67dd73f commit 892718d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.pickple.server.global.response.enums.SuccessCode;
import lombok.RequiredArgsConstructor;
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.RestController;

Expand All @@ -20,4 +21,9 @@ public class HostController {
public ApiResponseDto getHost(@HostId Long hostId) {
return ApiResponseDto.success(SuccessCode.HOST_DETAIL_GET_SUCCESS, hostQueryService.getHost(hostId));
}

@GetMapping("/v1/host/{hostId}")
public ApiResponseDto getMoimHost(@PathVariable Long hostId) {
return ApiResponseDto.success(SuccessCode.HOST_BY_MOIM_GET_SUCCESS, hostQueryService.getHostByMoim(hostId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.pickple.server.api.host.dto.response;

import com.pickple.server.api.host.domain.HostCategoryInfo;
import lombok.Builder;

@Builder
public record HostByMoimResponse(
String hostNickName, // 호스트 닉네임
String hostImageUrl, // 호스트 프로필 사진 url
String count, // 호스트의 모임 횟수(두자릿수)
HostCategoryInfo hostCategoryList // 호스트가 선택한 카테고리 리스트
) {
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.pickple.server.api.host.service;

import com.pickple.server.api.host.domain.Host;
import com.pickple.server.api.host.dto.response.HostByMoimResponse;
import com.pickple.server.api.host.dto.response.HostGetResponse;
import com.pickple.server.api.host.repository.HostRepository;
import com.pickple.server.api.moim.domain.Moim;
import com.pickple.server.api.moim.repository.MoimRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -13,6 +17,7 @@
public class HostQueryService {

private final HostRepository hostRepository;
private final MoimRepository moimRepository;

public HostGetResponse getHost(Long hostId) {
Host host = hostRepository.findHostByIdOrThrow(hostId);
Expand All @@ -24,4 +29,17 @@ public HostGetResponse getHost(Long hostId) {
.hostLink(host.getLink())
.build();
}

public HostByMoimResponse getHostByMoim(Long hostId) {
Host host = hostRepository.findHostByIdOrThrow(hostId);
List<Moim> moimList = moimRepository.findMoimByHostId(hostId);
String count = String.format("%02d", moimList.size());

return HostByMoimResponse.builder()
.hostNickName(host.getNickname())
.hostImageUrl(host.getImageUrl())
.hostCategoryList(host.getCategoryList())
.count(count)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public interface MoimRepository extends JpaRepository<Moim, Long> {
Optional<Moim> findMoimById(Long id);

List<Moim> findMoimByHostId(Long hostId);

default Moim findMoimByIdOrThrow(Long id) {
return findMoimById(id)
.orElseThrow(() -> new CustomException(ErrorCode.MOIM_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ public enum SuccessCode {
SUBMITTER_POST_SUCCESS(20005, HttpStatus.OK, "호스트 승인 신청 성공"),
MOIM_DETAIL_GET_SUCCESS(20006, HttpStatus.OK, "모임 상세 정보 조회 성공"),
HOST_DETAIL_GET_SUCCESS(20007, HttpStatus.OK, "호스트 정보 조회 성공"),
MOIM_SUBMISSION_POST_SUCCESS(20007, HttpStatus.OK, "모임 참여 신청 성공"),
PRESIGNED_URL_GET_SUCCESS(20008, HttpStatus.OK, "presigned url 발급 성공"),
SUBMITTED_MOIM_DETAIL_GET_SUCCESS(20008, HttpStatus.OK, "신청한 모임 상세 정보 조회 성공"),
NOTICE_POST_SUCCESS(20009, HttpStatus.OK, "공지사항 작성 성공"),
MOIM_LIST_BY_CATEGORY_GET_SUCCESS(20010, HttpStatus.OK, "카테고리에 해당하는 모임 조회 성공"),
NOTICE_LIST_GET_SUCCESS(20011, HttpStatus.OK, "공지사항 리스트 조회 성공"),
MOIM_DESCRIPTION_GET_SUCCESS(20012, HttpStatus.OK, "모임에 해당하는 소개 조회 성공"),
MOIM_QUESTION_LIST_GET_SUCCESS(20013, HttpStatus.OK, "모임 질문 목록 조회 성공"),
SUBMITTED_MOIM_LIST_BY_GUEST_GET_SUCCESS(20014, HttpStatus.OK, "게스트에 해당하는 신청한 모임 리스트 조회 성공"),
MOIM_BANNER_GET_SUCCESS(30014, HttpStatus.OK, "홈 배너 조회 성공"),
MOIM_SUBMISSION_POST_SUCCESS(20008, HttpStatus.OK, "모임 참여 신청 성공"),
PRESIGNED_URL_GET_SUCCESS(20009, HttpStatus.OK, "presigned url 발급 성공"),
SUBMITTED_MOIM_DETAIL_GET_SUCCESS(200010, HttpStatus.OK, "신청한 모임 상세 정보 조회 성공"),
NOTICE_POST_SUCCESS(20011, HttpStatus.OK, "공지사항 작성 성공"),
MOIM_LIST_BY_CATEGORY_GET_SUCCESS(20012, HttpStatus.OK, "카테고리에 해당하는 모임 조회 성공"),
NOTICE_LIST_GET_SUCCESS(20013, HttpStatus.OK, "공지사항 리스트 조회 성공"),
MOIM_DESCRIPTION_GET_SUCCESS(20014, HttpStatus.OK, "모임에 해당하는 소개 조회 성공"),
MOIM_QUESTION_LIST_GET_SUCCESS(20015, HttpStatus.OK, "모임 질문 목록 조회 성공"),
MOIM_BANNER_GET_SUCCESS(20016, HttpStatus.OK, "홈 배너 조회 성공"),
HOST_BY_MOIM_GET_SUCCESS(20017, HttpStatus.OK, "모임에 해당하는 호스트 정보 조회 성공"),
SUBMITTED_MOIM_LIST_BY_GUEST_GET_SUCCESS(20018, HttpStatus.OK, "게스트에 해당하는 신청한 모임 리스트 조회 성공"),

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

0 comments on commit 892718d

Please sign in to comment.