Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/depromeet/bbo-gak-server in…
Browse files Browse the repository at this point in the history
…to feature/#93
  • Loading branch information
lee-june-young committed Aug 30, 2024
2 parents bb13a18 + acc39f2 commit cea614b
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 10 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 @@ -7,7 +7,7 @@

public interface TagRepository extends JpaRepository<Tag, Long> {

List<Tag> findAllByJob(Job job);
List<Tag> findAllByJobIsIn(List<Job> jobList);

List<Tag> findAllByIdIsNotIn(List<Long> idList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
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;

@Builder(access = AccessLevel.PRIVATE)
public record CardGetResponse(
String title,
String content,
String createdDate,
String updatedDate,
String recruitTitle,
String cardTypeValueGroup,
List<String> cardTypeValueList,
List<TagGetResponse> tagList
Expand All @@ -28,11 +32,17 @@ 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()))
.updatedDate(card.getUpdatedDate().format(BaseDateTimeFormatter.getLocalDateTimeFormatter()))
.cardTypeValueList(cardTypeValueList)
.tagList(tagGetResponseList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
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;
import com.server.bbo_gak.global.error.exception.ErrorCode;
Expand All @@ -23,11 +26,25 @@ 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) {

return tagRepository.findAllByJob(user.getJob()).stream()
return tagRepository.findAllByJobIsIn(List.of(user.getJob(), Job.ALL)).stream()
.map(TagGetResponse::from)
.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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Recruit toEntity(User user, Season season) {
.season(season)
.title(title)
.siteUrl(siteUrl)
.recruitStatus(RecruitStatus.APPLICATION_COMPLETED)
.recruitStatus(RecruitStatus.PREPARATION_IN_PROGRESS)
.user(user)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum RecruitStatus {
DOCUMENT_PASSED("서류 통과"),
DOCUMENT_REJECTION("서류 탈락"),
INTERVIEW_PASSED("면접 통과"),
INTERVIEW_REJECTION("서류 탈락"),
INTERVIEW_REJECTION("면접 탈락"),
FINAL_ACCEPTANCE("최종 합격"),
FINAL_REJECTED("최종 탈락");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum RecruitStatusCategory {

private final List<RecruitStatus> statuses;

public static boolean isRejectionStatus(RecruitStatus status) {
return REJECTION_STATUS.getStatuses().contains(status);
public static boolean isRejectionStatusOrFinalAcceptance(RecruitStatus status) {
return REJECTION_STATUS.getStatuses().contains(status) || RecruitStatus.FINAL_ACCEPTANCE.equals(status);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.server.bbo_gak.domain.recruit.service;

import com.server.bbo_gak.domain.recruit.dao.RecruitRepository;
import com.server.bbo_gak.domain.recruit.dao.RecruitScheduleRepository;
import com.server.bbo_gak.domain.recruit.dto.request.RecruitCreateRequest;
import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleCreateRequest;
import com.server.bbo_gak.domain.recruit.dto.response.RecruitGetInnerResponse;
Expand Down Expand Up @@ -30,7 +29,6 @@ public class RecruitService {
private final RecruitRepository recruitRepository;
private final SeasonService seasonService;
private final RecruitScheduleService recruitScheduleService;
private final RecruitScheduleRepository recruitScheduleRepository;

public List<RecruitGetResponse> getTotalRecruitList(User user) {
List<Recruit> recruits = recruitRepository.findAllByUserId(user.getId());
Expand Down Expand Up @@ -82,7 +80,7 @@ private LocalDate getNearestUpcomingDate(Recruit recruit) {

private Map<Boolean, List<Recruit>> partitionRecruits(List<Recruit> recruits) {
return recruits.stream()
.filter(recruit -> !RecruitStatusCategory.isRejectionStatus(
.filter(recruit -> !RecruitStatusCategory.isRejectionStatusOrFinalAcceptance(
recruit.getRecruitStatus())) // 불합격 상태 필터링
.collect(Collectors.partitioningBy(this::isNeedsScheduleUpdate));
}
Expand Down Expand Up @@ -121,7 +119,6 @@ private void addRecruitScheduleIfRequired(RecruitCreateRequest request, Recruit
RecruitScheduleCreateRequest.of(
request.recruitScheduleStage(), request.deadLine())
);
recruitScheduleRepository.save(recruitSchedule);
recruit.addSchedule(recruitSchedule);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ 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 수정일시"),
fieldWithPath("cardTypeValueGroup").type(JsonFieldType.STRING).description("Card 그룹 이름"),
fieldWithPath("tagList.[].id").type(JsonFieldType.NUMBER).description("태그 ID"),
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 cea614b

Please sign in to comment.