diff --git a/src/main/java/com/server/bbo_gak/domain/card/controller/TagController.java b/src/main/java/com/server/bbo_gak/domain/card/controller/TagController.java index b6a3b32..15cd345 100644 --- a/src/main/java/com/server/bbo_gak/domain/card/controller/TagController.java +++ b/src/main/java/com/server/bbo_gak/domain/card/controller/TagController.java @@ -28,6 +28,14 @@ public ResponseEntity> getAllTagList( return ResponseEntity.ok(tagService.getAllTagList(user)); } + @GetMapping("/recruits/{recruit-id}/tags") + public ResponseEntity> getAllRecruitsTagList( + @AuthUser User user, + @PathVariable("recruit-id") Long recruitId + ) { + return ResponseEntity.ok(tagService.getAllRecruitsTagList(user, recruitId)); + } + @GetMapping("/cards/{card-id}/tags") public ResponseEntity> getcCardTagList( @AuthUser User user, diff --git a/src/main/java/com/server/bbo_gak/domain/card/dto/response/CardGetResponse.java b/src/main/java/com/server/bbo_gak/domain/card/dto/response/CardGetResponse.java index b8fffc1..96248d7 100644 --- a/src/main/java/com/server/bbo_gak/domain/card/dto/response/CardGetResponse.java +++ b/src/main/java/com/server/bbo_gak/domain/card/dto/response/CardGetResponse.java @@ -3,8 +3,10 @@ import com.server.bbo_gak.domain.card.entity.Card; import com.server.bbo_gak.domain.card.entity.CardTag; import com.server.bbo_gak.domain.card.entity.CardTypeValueGroup; +import com.server.bbo_gak.domain.recruit.entity.Recruit; import com.server.bbo_gak.global.utils.BaseDateTimeFormatter; import java.util.List; +import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; @@ -14,6 +16,7 @@ public record CardGetResponse( String content, String createdDate, String updatedDate, + String recruitTitle, String cardTypeValueGroup, List cardTypeValueList, List tagList @@ -29,9 +32,14 @@ public static CardGetResponse of(Card card, List cardTagList) { .map(cardType -> cardType.getCardTypeValue().getValue()) .toList(); + String recruitTitle = Optional.ofNullable(card.getRecruit()) + .map(Recruit::getTitle) + .orElse(null); + return CardGetResponse.builder() .title(card.getTitle()) .content(card.getContent()) + .recruitTitle(recruitTitle) .cardTypeValueGroup( CardTypeValueGroup.findByCardTypeValue(card.getCardTypeList().getFirst().getCardTypeValue()).getValue()) .createdDate(card.getCreatedDate().format(BaseDateTimeFormatter.getLocalDateTimeFormatter())) diff --git a/src/main/java/com/server/bbo_gak/domain/card/service/TagService.java b/src/main/java/com/server/bbo_gak/domain/card/service/TagService.java index 501411a..b334095 100644 --- a/src/main/java/com/server/bbo_gak/domain/card/service/TagService.java +++ b/src/main/java/com/server/bbo_gak/domain/card/service/TagService.java @@ -7,6 +7,8 @@ import com.server.bbo_gak.domain.card.entity.Card; import com.server.bbo_gak.domain.card.entity.CardTag; import com.server.bbo_gak.domain.card.entity.Tag; +import com.server.bbo_gak.domain.recruit.dao.RecruitRepository; +import com.server.bbo_gak.domain.recruit.entity.Recruit; import com.server.bbo_gak.domain.user.entity.Job; import com.server.bbo_gak.domain.user.entity.User; import com.server.bbo_gak.global.error.exception.BusinessException; @@ -24,6 +26,7 @@ public class TagService { private final CardRepository cardRepository; private final TagRepository tagRepository; private final CardTagRepository cardTagRepository; + private final RecruitRepository recruitRepository; @Transactional(readOnly = true) public List getAllTagList(User user) { @@ -33,6 +36,19 @@ public List getAllTagList(User user) { .toList(); } + @Transactional(readOnly = true) + public List getAllRecruitsTagList(User user, Long recruitId) { + + Recruit recruit = recruitRepository.findByUserIdAndId(user.getId(), recruitId) + .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_NOT_FOUND)); + + return recruit.getCardList().stream() + .flatMap(card -> card.getCardTagList().stream().map(CardTag::getTag)) + .distinct() + .map(TagGetResponse::from) + .toList(); + } + @Transactional(readOnly = true) public List getTagListInCard(User user, Long cardId) { diff --git a/src/test/java/com/server/bbo_gak/domain/card/controller/CardControllerTest.java b/src/test/java/com/server/bbo_gak/domain/card/controller/CardControllerTest.java index 32f5cdc..1c21fab 100644 --- a/src/test/java/com/server/bbo_gak/domain/card/controller/CardControllerTest.java +++ b/src/test/java/com/server/bbo_gak/domain/card/controller/CardControllerTest.java @@ -96,6 +96,7 @@ class 카드_단건_조회 { .responseSchema(Schema.schema("CardGetResponse")) .responseFields(fieldWithPath("title").type(JsonFieldType.STRING).description("Card 제목"), fieldWithPath("content").type(JsonFieldType.STRING).description("Card 내용"), + fieldWithPath("recruitTitle").type(JsonFieldType.STRING).optional().description("공고 제목"), fieldWithPath("cardTypeValueList").type(JsonFieldType.ARRAY).description("Card 타입값 리스트"), fieldWithPath("createdDate").type(JsonFieldType.STRING).description("Card 생성일시"), fieldWithPath("updatedDate").type(JsonFieldType.STRING).description("Card 수정일시"), diff --git a/src/test/java/com/server/bbo_gak/domain/card/controller/TagControllerTest.java b/src/test/java/com/server/bbo_gak/domain/card/controller/TagControllerTest.java index d592955..de00445 100644 --- a/src/test/java/com/server/bbo_gak/domain/card/controller/TagControllerTest.java +++ b/src/test/java/com/server/bbo_gak/domain/card/controller/TagControllerTest.java @@ -75,6 +75,42 @@ private ResourceSnippetParameters getSuccessResponseResource() { } } + @Nested + class 전체_태그_목록_조회_공고에서 { + + @Test + @Transactional + public void 성공() throws Exception { + + // TEST + ResultActions resultActions = mockMvc.perform(getRequest()) + .andExpect(status().isOk()); + + // DOCS + resultActions.andDo(document("[전체_태그_목록_조회_공고에서] 성공", resource(getSuccessResponseResource()))); + } + + private MockHttpServletRequestBuilder getRequest() { + return get(DEFAULT_URL + "/recruits/{recruit-id}/tags", 1L) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON); + } + + private ResourceSnippetParameters getSuccessResponseResource() { + return ResourceSnippetParameters.builder() + .description("전체 카드 태그 목록").tags("Tag") + .pathParameters( + parameterWithName("recruit-id").description("recruit-id") + ) + .responseSchema(Schema.schema("TagGetResponse")) + .responseFields( + fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("태그 ID"), + fieldWithPath("[].name").type(JsonFieldType.STRING).description("태그 이름"), + fieldWithPath("[].type").type(JsonFieldType.STRING).description("태그 타입")) + .build(); + } + } + @Nested class 카드_태그_목록_조회 {