Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#61 [feat] GET - 글모임별 글감 카테고리 조회 #65

Merged
merged 8 commits into from
Jan 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import com.mile.dto.SuccessResponse;
import com.mile.exception.message.SuccessMessage;
import com.mile.moim.serivce.MoimService;
import com.mile.moim.serivce.dto.CategoryListResponse;
import com.mile.moim.serivce.dto.ContentListResponse;
import com.mile.writerName.serivce.dto.PopularWriterListResponse;
import com.mile.moim.serivce.dto.MoimTopicResponse;
Expand Down Expand Up @@ -63,4 +64,12 @@ public SuccessResponse<MoimInfoResponse> getMoimInfo(
return SuccessResponse.of(SuccessMessage.MOIM_INFO_SUCCESS, moimService.getMoimInfo(moimId));
}


@GetMapping("/{moimId}/categoryList")
@Override
public SuccessResponse<CategoryListResponse> getCategoryList(
@PathVariable final Long moimId
) {
return SuccessResponse.of(SuccessMessage.CATEGORY_LIST_SEARCH_SUCCESS, moimService.getCategoryList(moimId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mile.dto.ErrorResponse;
import com.mile.dto.SuccessResponse;
import com.mile.moim.serivce.dto.CategoryListResponse;
import com.mile.moim.serivce.dto.ContentListResponse;
import com.mile.writerName.serivce.dto.PopularWriterListResponse;
import com.mile.moim.serivce.dto.MoimTopicResponse;
Expand Down Expand Up @@ -92,4 +93,16 @@ SuccessResponse<MoimTopicResponse> getTopicFromMoim(
SuccessResponse<MoimInfoResponse> getMoimInfo(
final Long moimId
);

@Operation(summary = "카테고리 리스트 조회")
@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "카테고리 리스트 조회가 완료되었습니다."),
@ApiResponse(responseCode = "500", description = "서버 내부 오류입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
}
)
public SuccessResponse<CategoryListResponse> getCategoryList(
@PathVariable final Long moimId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum ErrorMessage {
COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 댓글이 존재하지 않습니다."),
CURIOUS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 궁금해요는 존재하지 않습니다."),
TOPIC_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 주제가 존재하지 않습니다."),
KEYWORD_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 글모임의 글감 키워드가 존재하지 않습니다."),
WRITERS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 모임의 작가가 요청한 개수 이상 존재하지 않습니다"),
WRITER_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 작가는 존재하지 않습니다."),
RECCOMEND_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "추천 글감을 받아오는데 실패했습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public enum SuccessMessage {
RECOMMENDATION_GET_SUCCESS(HttpStatus.OK.value(), "추천 글감이 조회되었습니다."),
PRESIGNED_URL_GET_SUCCESS(HttpStatus.OK.value(), "이미지를 업로드할 url이 발행되었습니다."),
POST_DELETE_SUCCESS(HttpStatus.OK.value(), "글 삭제가 완료되었습니다."),
CATEGORY_LIST_SEARCH_SUCCESS(HttpStatus.OK.value(), "카테고리 리스트 조회가 완료되었습니다."),
MOIM_TOPIC_GET_SUCCESS(HttpStatus.OK.value(), "글감 조회가 완료되었습니다."),

/*
201 CREATED
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mile.exception.model.NotFoundException;
import com.mile.moim.domain.Moim;
import com.mile.moim.repository.MoimRepository;
import com.mile.moim.serivce.dto.CategoryListResponse;
import com.mile.moim.serivce.dto.ContentListResponse;
import com.mile.moim.serivce.dto.MoimAuthenticateResponse;
import com.mile.moim.serivce.dto.MoimTopicResponse;
Expand Down Expand Up @@ -51,6 +52,7 @@ public MoimAuthenticateResponse getAuthenticateUserOfMoim(
) {
return MoimAuthenticateResponse.of(writerNameService.isUserInMoim(moimId, userId));
}

private Moim findById(
final Long moimId
) {
Expand Down Expand Up @@ -94,4 +96,11 @@ public MoimInfoResponse getMoimInfo(
DateUtil.getStringDateOfLocalDate(moim.getCreatedAt())
);
}

public CategoryListResponse getCategoryList(
final Long moimId
) {
return CategoryListResponse.of(topicService.getKeywordsFromMoim(moimId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mile.moim.serivce.dto;

import com.mile.topic.serivce.dto.CategoryResponse;
import java.util.List;

public record CategoryListResponse(List<CategoryResponse> categoryList) {
public static CategoryListResponse of(final List<CategoryResponse> categoryList) {
return new CategoryListResponse(categoryList);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mile.config.BaseTimeEntity;
import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.NotFoundException;
import com.mile.topic.serivce.dto.CategoryResponse;
import com.mile.moim.domain.Moim;
import com.mile.topic.domain.Topic;
import com.mile.topic.repository.TopicRepository;
Expand Down Expand Up @@ -63,6 +64,28 @@ public Topic findById(
);
}

public List<CategoryResponse> getKeywordsFromMoim(
final Long moimId
) {
List<Topic> topicList = findByMoimId(moimId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1
길이가 0일 경우 예외 처리를 해야할 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 네 isKeywordsEmpty 에서 0인 경우 예외처리를 하고 있습니다!

isKeywordsEmpty(topicList);
return topicList
.stream()
.map(CategoryResponse::of)
.collect(Collectors.toList());
}

private void isKeywordsEmpty(
final List<Topic> topicList
) {
if (topicList.isEmpty()) {
throw new NotFoundException(ErrorMessage.KEYWORD_NOT_FOUND);
}
}




public String findLatestTopicByMoim(
final Moim moim
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mile.topic.serivce.dto;

import com.mile.topic.domain.Topic;

public record CategoryResponse(Long categoryId, String categoryName) {
public static CategoryResponse of(Topic topic) {
return new CategoryResponse(topic.getId(), topic.getKeyword());
}
}