Skip to content

Commit

Permalink
Merge pull request #105 from depromeet/feature/#95
Browse files Browse the repository at this point in the history
[feat][#104] 공고에서 태그 조회시 생성된 태그만 보이게끔
  • Loading branch information
JeongSangByuk authored Aug 30, 2024
2 parents 301ee85 + f674ae0 commit acc39f2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public ResponseEntity<List<TagGetResponse>> getAllTagList(
return ResponseEntity.ok(tagService.getAllTagList(user));
}

@GetMapping("/recruits/{recruit-id}/tags")
public ResponseEntity<List<TagGetResponse>> getAllRecruitsTagList(
@AuthUser User user,
@PathVariable("recruit-id") Long recruitId
) {
return ResponseEntity.ok(tagService.getAllRecruitsTagList(user, recruitId));
}

@GetMapping("/cards/{card-id}/tags")
public ResponseEntity<List<TagGetResponse>> getcCardTagList(
@AuthUser User user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,6 +16,7 @@ public record CardGetResponse(
String content,
String createdDate,
String updatedDate,
String recruitTitle,
String cardTypeValueGroup,
List<String> cardTypeValueList,
List<TagGetResponse> tagList
Expand All @@ -29,9 +32,14 @@ public static CardGetResponse of(Card card, List<CardTag> 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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TagGetResponse> getAllTagList(User user) {
Expand All @@ -33,6 +36,19 @@ public List<TagGetResponse> getAllTagList(User user) {
.toList();
}

@Transactional(readOnly = true)
public List<TagGetResponse> 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<TagGetResponse> getTagListInCard(User user, Long cardId) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 수정일시"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 카드_태그_목록_조회 {
Expand Down

0 comments on commit acc39f2

Please sign in to comment.