diff --git a/src/main/java/com/server/bbo_gak/domain/card/controller/CardController.java b/src/main/java/com/server/bbo_gak/domain/card/controller/CardController.java index 6abce7d..489b0c0 100644 --- a/src/main/java/com/server/bbo_gak/domain/card/controller/CardController.java +++ b/src/main/java/com/server/bbo_gak/domain/card/controller/CardController.java @@ -32,7 +32,7 @@ public class CardController { @GetMapping("/cards/type-count") public ResponseEntity getCardTypeCounts(@AuthUser User user) { - return ResponseEntity.ok(cardService.getCardTypeCounts(user)); + return ResponseEntity.ok(cardService.getCardTypeCountsInMyInfo(user)); } @GetMapping("/cards/{card-id}") diff --git a/src/main/java/com/server/bbo_gak/domain/card/controller/CardInRecruitController.java b/src/main/java/com/server/bbo_gak/domain/card/controller/CardInRecruitController.java new file mode 100644 index 0000000..84c5377 --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/card/controller/CardInRecruitController.java @@ -0,0 +1,49 @@ +package com.server.bbo_gak.domain.card.controller; + +import com.server.bbo_gak.domain.card.dto.response.CardCreateResponse; +import com.server.bbo_gak.domain.card.dto.response.CardListGetResponse; +import com.server.bbo_gak.domain.card.dto.response.CardTypeCountInRecruitGetResponse; +import com.server.bbo_gak.domain.card.service.CardInRecruitService; +import com.server.bbo_gak.domain.user.entity.User; +import com.server.bbo_gak.global.annotation.AuthUser; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1") +@RequiredArgsConstructor +public class CardInRecruitController { + + private final CardInRecruitService cardInRecruitService; + + @GetMapping("/recruits/{recruit-id}/cards/type-count") + public ResponseEntity getCardTypeCounts(@AuthUser User user) { + return ResponseEntity.ok(cardInRecruitService.getCardTypeCountsInRecruit(user)); + } + + @GetMapping("/recruits/{recruit-id}/cards") + public ResponseEntity> getCardDetail( + @AuthUser User user, + @PathVariable("recruit-id") Long recruitId, + @RequestParam("type") String type) { + + return ResponseEntity.ok(cardInRecruitService.getCardListInRecruit(user, recruitId, type)); + } + + @PostMapping("/recruits/{recruit-id}/cards/{card-id}") + public ResponseEntity createCard( + @AuthUser User user, + @PathVariable("recruit-id") Long recruitId, + @PathVariable("card-id") Long cardId) { + + return ResponseEntity.ok(cardInRecruitService.copyCardFromMyInfo(user, cardId, recruitId)); + } + +} diff --git a/src/main/java/com/server/bbo_gak/domain/card/dao/CardCopyInfoRepository.java b/src/main/java/com/server/bbo_gak/domain/card/dao/CardCopyInfoRepository.java new file mode 100644 index 0000000..63857cb --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/card/dao/CardCopyInfoRepository.java @@ -0,0 +1,8 @@ +package com.server.bbo_gak.domain.card.dao; + +import com.server.bbo_gak.domain.card.entity.CardCopyInfo; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CardCopyInfoRepository extends JpaRepository { + +} diff --git a/src/main/java/com/server/bbo_gak/domain/card/dao/CardDao.java b/src/main/java/com/server/bbo_gak/domain/card/dao/CardDao.java index 1193546..b6d8b5b 100644 --- a/src/main/java/com/server/bbo_gak/domain/card/dao/CardDao.java +++ b/src/main/java/com/server/bbo_gak/domain/card/dao/CardDao.java @@ -1,5 +1,6 @@ package com.server.bbo_gak.domain.card.dao; +import com.querydsl.core.BooleanBuilder; import com.querydsl.jpa.impl.JPAQueryFactory; import com.server.bbo_gak.domain.card.entity.Card; import com.server.bbo_gak.domain.card.entity.CardTypeValue; @@ -18,27 +19,59 @@ public class CardDao { private final JPAQueryFactory query; - public List findAllByUserIdAndCardTypeValueList(User user, CardTypeValue[] cardTypeValueList) { + public List findAllByUserIdAndCardTypeValueList(User user, CardTypeValue[] cardTypeValueList, + boolean isRecruit) { QCard qCard = QCard.card; QCardType qCardType = QCardType.cardType; + createRecruitBooleanBuilder(qCard, isRecruit); + return query.selectFrom(qCard) .leftJoin(qCard.cardTypeList, qCardType).fetchJoin() - .where(qCard.user.id.eq(user.getId()).and(qCardType.cardTypeValue.in(cardTypeValueList))).distinct() + .where(qCard.user.id.eq(user.getId()) + .and(qCardType.cardTypeValue.in(cardTypeValueList)) + .and(createRecruitBooleanBuilder(qCard, isRecruit))) + .distinct() .fetch(); } - public List findAllByUserIdAndCardTypeValue(User user, CardTypeValue cardTypeValue) { + public List findAllByUserIdAndCardTypeValue(User user, CardTypeValue cardTypeValue, Long recruitId) { QCard qCard = QCard.card; QCardType qCardType = QCardType.cardType; + createRecruitBooleanBuilder(qCard, recruitId); + return query.selectFrom(qCard) .leftJoin(qCard.cardTypeList, qCardType).fetchJoin() - .where(qCard.user.id.eq(user.getId()).and(qCardType.cardTypeValue.eq(cardTypeValue))).distinct() + .where(qCard.user.id.eq(user.getId()) + .and(qCardType.cardTypeValue.eq(cardTypeValue)) + .and(createRecruitBooleanBuilder(qCard, recruitId))) + .distinct() .fetch(); } + private BooleanBuilder createRecruitBooleanBuilder(QCard qCard, boolean isRecruit) { + + BooleanBuilder builder = new BooleanBuilder(); + + if (isRecruit) { + return builder.and(qCard.recruit.isNotNull()); + } + + return builder.and(qCard.recruit.isNull()); + } + private BooleanBuilder createRecruitBooleanBuilder(QCard qCard, Long recruitId) { + + BooleanBuilder builder = new BooleanBuilder(); + + if (recruitId == null) { + return builder.and(qCard.recruit.isNull()).and(qCard.copyFlag.isFalse()); + } + + return builder.and(qCard.recruit.id.eq(recruitId)).and(qCard.copyFlag.isTrue()); + + } } diff --git a/src/main/java/com/server/bbo_gak/domain/card/dto/response/CardTypeCountInRecruitGetResponse.java b/src/main/java/com/server/bbo_gak/domain/card/dto/response/CardTypeCountInRecruitGetResponse.java new file mode 100644 index 0000000..2757752 --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/card/dto/response/CardTypeCountInRecruitGetResponse.java @@ -0,0 +1,32 @@ +package com.server.bbo_gak.domain.card.dto.response; + +import com.server.bbo_gak.domain.card.entity.Card; +import com.server.bbo_gak.domain.card.entity.CardType; +import com.server.bbo_gak.domain.card.entity.CardTypeValue; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record CardTypeCountInRecruitGetResponse( + Long 서류_준비, + Long 과제_준비, + Long 인터뷰_준비 +) { + + public static CardTypeCountInRecruitGetResponse from(List cards) { + + Map cardTypeValueCountMap = cards.stream() + .flatMap(card -> card.getCardTypeList().stream()) + .collect(Collectors.groupingBy(CardType::getCardTypeValue, Collectors.counting())); + + return CardTypeCountInRecruitGetResponse.builder() + .서류_준비(cardTypeValueCountMap.getOrDefault(CardTypeValue.DOCUMENT_PREPARING, 0L)) + .과제_준비(cardTypeValueCountMap.getOrDefault(CardTypeValue.ASSIGNMENT_PREPARING, 0L)) + .인터뷰_준비(cardTypeValueCountMap.getOrDefault(CardTypeValue.INTERVIEW_PREPARING, 0L)) + .build(); + } + +} diff --git a/src/main/java/com/server/bbo_gak/domain/card/entity/Card.java b/src/main/java/com/server/bbo_gak/domain/card/entity/Card.java index c7355de..9875be2 100644 --- a/src/main/java/com/server/bbo_gak/domain/card/entity/Card.java +++ b/src/main/java/com/server/bbo_gak/domain/card/entity/Card.java @@ -42,12 +42,12 @@ public class Card extends BaseEntity { private LocalDateTime accessTime; + private Boolean copyFlag = false; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; - private boolean copyFlag = false; - @OneToMany(mappedBy = "card", fetch = FetchType.LAZY) private List cardTagList = new ArrayList<>(); @@ -60,21 +60,24 @@ public class Card extends BaseEntity { @OneToMany(mappedBy = "card", fetch = FetchType.LAZY) private List cardTypeList = new ArrayList<>(); - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "copy_info_id") - private CopyInfo copyInfo; + @OneToOne(mappedBy = "card", fetch = FetchType.LAZY) + @JoinColumn(name = "card_copy_info_id") + private CardCopyInfo cardCopyInfo; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "recruit_id") private Recruit recruit; @Builder - public Card(String title, String content, LocalDateTime accessTime, List cardTypeList, User user) { + public Card(String title, String content, LocalDateTime accessTime, List cardTypeList, User user, + Boolean copyFlag, Recruit recruit) { this.title = title; this.content = content; this.accessTime = accessTime; this.cardTypeList = cardTypeList; + this.copyFlag = copyFlag; this.user = user; + this.recruit = recruit; } public static Card creatEmptyCard(User user) { @@ -82,7 +85,19 @@ public static Card creatEmptyCard(User user) { .title("") .content("") .user(user) + .copyFlag(false) + .accessTime(LocalDateTime.now()) + .build(); + } + + public static Card copyCardFromMyInfo(Card card, User user, Recruit recruit) { + return Card.builder() + .title(card.getTitle()) + .content(card.getContent()) + .user(user) + .copyFlag(true) .accessTime(LocalDateTime.now()) + .recruit(recruit) .build(); } diff --git a/src/main/java/com/server/bbo_gak/domain/card/entity/CopyInfo.java b/src/main/java/com/server/bbo_gak/domain/card/entity/CardCopyInfo.java similarity index 52% rename from src/main/java/com/server/bbo_gak/domain/card/entity/CopyInfo.java rename to src/main/java/com/server/bbo_gak/domain/card/entity/CardCopyInfo.java index 93bb85a..4d7af8f 100644 --- a/src/main/java/com/server/bbo_gak/domain/card/entity/CopyInfo.java +++ b/src/main/java/com/server/bbo_gak/domain/card/entity/CardCopyInfo.java @@ -3,9 +3,13 @@ import com.server.bbo_gak.global.common.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import java.time.LocalDateTime; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -13,16 +17,21 @@ @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class CopyInfo extends BaseEntity { +public class CardCopyInfo extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "copy_info_id") + @Column(name = "card_copy_info_id") private Long id; - private Long parentCardId; + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "card_id") + private Card card; - public CopyInfo(Long parentCardId) { - this.parentCardId = parentCardId; + private LocalDateTime copiedTime; + + public CardCopyInfo(Card card) { + this.card = card; + this.copiedTime = LocalDateTime.now(); } } diff --git a/src/main/java/com/server/bbo_gak/domain/card/entity/CardTypeValueGroup.java b/src/main/java/com/server/bbo_gak/domain/card/entity/CardTypeValueGroup.java index 7caff48..0dca8d4 100644 --- a/src/main/java/com/server/bbo_gak/domain/card/entity/CardTypeValueGroup.java +++ b/src/main/java/com/server/bbo_gak/domain/card/entity/CardTypeValueGroup.java @@ -7,11 +7,11 @@ @AllArgsConstructor public enum CardTypeValueGroup { - MY_INFO(new CardTypeValue[]{CardTypeValue.EXPERIENCE, CardTypeValue.DOCUMENT_PREPARING, + MY_INFO(new CardTypeValue[]{CardTypeValue.EXPERIENCE, CardTypeValue.INTERVIEW_QUESTION, CardTypeValue.PERSONAL_STATEMENT}), - RECRUIT(new CardTypeValue[]{CardTypeValue.ASSIGNMENT_PREPARING, CardTypeValue.INTERVIEW_QUESTION, + RECRUIT(new CardTypeValue[]{CardTypeValue.ASSIGNMENT_PREPARING, CardTypeValue.DOCUMENT_PREPARING, CardTypeValue.INTERVIEW_PREPARING}); - + private CardTypeValue[] cardTypeValueList; } diff --git a/src/main/java/com/server/bbo_gak/domain/card/service/CardInRecruitService.java b/src/main/java/com/server/bbo_gak/domain/card/service/CardInRecruitService.java new file mode 100644 index 0000000..63752b8 --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/card/service/CardInRecruitService.java @@ -0,0 +1,110 @@ +package com.server.bbo_gak.domain.card.service; + +import com.server.bbo_gak.domain.card.dao.CardCopyInfoRepository; +import com.server.bbo_gak.domain.card.dao.CardDao; +import com.server.bbo_gak.domain.card.dao.CardImageRepository; +import com.server.bbo_gak.domain.card.dao.CardMemoRepository; +import com.server.bbo_gak.domain.card.dao.CardRepository; +import com.server.bbo_gak.domain.card.dao.CardTagRepository; +import com.server.bbo_gak.domain.card.dao.CardTypeRepository; +import com.server.bbo_gak.domain.card.dto.response.CardCreateResponse; +import com.server.bbo_gak.domain.card.dto.response.CardListGetResponse; +import com.server.bbo_gak.domain.card.dto.response.CardTypeCountInRecruitGetResponse; +import com.server.bbo_gak.domain.card.entity.Card; +import com.server.bbo_gak.domain.card.entity.CardCopyInfo; +import com.server.bbo_gak.domain.card.entity.CardImage; +import com.server.bbo_gak.domain.card.entity.CardMemo; +import com.server.bbo_gak.domain.card.entity.CardTag; +import com.server.bbo_gak.domain.card.entity.CardType; +import com.server.bbo_gak.domain.card.entity.CardTypeValue; +import com.server.bbo_gak.domain.card.entity.CardTypeValueGroup; +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.User; +import com.server.bbo_gak.global.error.exception.ErrorCode; +import com.server.bbo_gak.global.error.exception.NotFoundException; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class CardInRecruitService { + + private final CardDao cardDao; + private final CardRepository cardRepository; + private final RecruitRepository recruitRepository; + private final CardMemoRepository cardMemoRepository; + private final CardTypeRepository cardTypeRepository; + private final CardTagRepository cardTagRepository; + private final CardImageRepository cardImageRepository; + private final CardCopyInfoRepository cardCopyInfoRepository; + + + @Transactional(readOnly = true) + public CardTypeCountInRecruitGetResponse getCardTypeCountsInRecruit(User user) { + + CardTypeValue[] cardTypeValueList = CardTypeValueGroup.RECRUIT.getCardTypeValueList(); + + List cards = cardDao.findAllByUserIdAndCardTypeValueList(user, cardTypeValueList, true); + + return CardTypeCountInRecruitGetResponse.from(cards); + } + + @Transactional(readOnly = true) + public List getCardListInRecruit(User user, Long recruitId, String cardTypeValue) { + + List cards = cardDao.findAllByUserIdAndCardTypeValue(user, CardTypeValue.findByValue(cardTypeValue), + recruitId); + + return cards.stream() + .map(card -> CardListGetResponse.of(card, card.getCardTagList())) + .collect(Collectors.toList()); + } + + @Transactional + public CardCreateResponse copyCardFromMyInfo(User user, Long cardId, Long recruitId) { + + Card card = cardRepository.findByIdAndUser(cardId, user) + .orElseThrow(() -> new NotFoundException(ErrorCode.CARD_NOT_FOUND)); + + Recruit recruit = recruitRepository.findByUserIdAndId(user.getId(), recruitId) + .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_NOT_FOUND)); + + Card copiedCard = Card.copyCardFromMyInfo(card, user, recruit); + + cardRepository.save(copiedCard); + copyCardDataListFromCard(card, copiedCard); + + return new CardCreateResponse(copiedCard.getId()); + } + + private void copyCardDataListFromCard(Card card, Card copiedCard) { + saveDataList(card.getCardMemoList(), cardMemoRepository, + cardMemo -> new CardMemo(copiedCard, cardMemo.getContent())); + + saveDataList(card.getCardTypeList(), cardTypeRepository, + cardType -> new CardType(copiedCard, cardType.getCardTypeValue())); + + saveDataList(card.getCardTagList(), cardTagRepository, + cardTag -> new CardTag(copiedCard, cardTag.getTag())); + + saveDataList(card.getCardImageList(), cardImageRepository, + cardImage -> CardImage.of(copiedCard, cardImage.getFileName())); + + cardCopyInfoRepository.save(new CardCopyInfo(copiedCard)); + } + + private void saveDataList(List items, JpaRepository repository, Function mapper) { + + List copiedList = items.stream() + .map(mapper) + .toList(); + + repository.saveAll(copiedList); + } +} diff --git a/src/main/java/com/server/bbo_gak/domain/card/service/CardService.java b/src/main/java/com/server/bbo_gak/domain/card/service/CardService.java index 1fd3cab..9c5b027 100644 --- a/src/main/java/com/server/bbo_gak/domain/card/service/CardService.java +++ b/src/main/java/com/server/bbo_gak/domain/card/service/CardService.java @@ -37,15 +37,16 @@ public class CardService { private final CardTypeRepository cardTypeRepository; @Transactional(readOnly = true) - public CardTypeCountGetResponse getCardTypeCounts(User user) { + public CardTypeCountGetResponse getCardTypeCountsInMyInfo(User user) { CardTypeValue[] cardTypeValueList = CardTypeValueGroup.MY_INFO.getCardTypeValueList(); - List cards = cardDao.findAllByUserIdAndCardTypeValueList(user, cardTypeValueList); + List cards = cardDao.findAllByUserIdAndCardTypeValueList(user, cardTypeValueList, false); return CardTypeCountGetResponse.from(cards); } + @Transactional(readOnly = true) public CardGetResponse getCardDetail(User user, Long cardId) { @@ -60,13 +61,15 @@ public CardGetResponse getCardDetail(User user, Long cardId) { @Transactional(readOnly = true) public List getCardList(User user, String cardTypeValue) { - List cards = cardDao.findAllByUserIdAndCardTypeValue(user, CardTypeValue.findByValue(cardTypeValue)); + List cards = cardDao.findAllByUserIdAndCardTypeValue(user, CardTypeValue.findByValue(cardTypeValue), + null); return cards.stream() .map(card -> CardListGetResponse.of(card, card.getCardTagList())) .collect(Collectors.toList()); } + @Transactional public CardCreateResponse createCard(User user, CardCreateRequest cardCreateRequest) { diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java index a1d243b..16230c4 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java @@ -1,6 +1,5 @@ package com.server.bbo_gak.domain.recruit.service; -import com.server.bbo_gak.domain.card.entity.CardType; import com.server.bbo_gak.domain.recruit.dao.RecruitRepository; import com.server.bbo_gak.domain.recruit.dto.request.RecruitCreateRequest; import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleCreateRequest; @@ -148,16 +147,4 @@ private Recruit findRecruitByUserAndId(User user, Long recruitId) { return recruitRepository.findByUserIdAndId(user.getId(), recruitId) .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_NOT_FOUND)); } - - public void getCardListInRecruit(User user, Long recruitId, CardType type) { - - } - - public void getCardTypeCountsInRecruit(User user, Long recruitId) { - - } - - public void copyMyInfoCardToRecruit(User user, Long CardId, Long recruitId) { - - } } diff --git a/src/test/java/com/server/bbo_gak/domain/card/controller/CardInRecruitControllerTest.java b/src/test/java/com/server/bbo_gak/domain/card/controller/CardInRecruitControllerTest.java new file mode 100644 index 0000000..c86e0c5 --- /dev/null +++ b/src/test/java/com/server/bbo_gak/domain/card/controller/CardInRecruitControllerTest.java @@ -0,0 +1,113 @@ +package com.server.bbo_gak.domain.card.controller; + +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.server.bbo_gak.domain.card.dao.CardCopyInfoRepository; +import com.server.bbo_gak.domain.card.dao.CardRepository; +import com.server.bbo_gak.domain.card.dto.response.CardCreateResponse; +import com.server.bbo_gak.domain.card.dto.response.CardListGetResponse; +import com.server.bbo_gak.domain.card.dto.response.CardTypeCountInRecruitGetResponse; +import com.server.bbo_gak.global.AbstractRestDocsTests; +import com.server.bbo_gak.global.RestDocsFactory; +import java.util.List; +import org.assertj.core.util.Lists; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpMethod; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.transaction.annotation.Transactional; + +@SpringBootTest +@ActiveProfiles("test") +@Sql("/card-test-data.sql") +public class CardInRecruitControllerTest extends AbstractRestDocsTests { + + @Autowired + private CardRepository cardRepository; + + @Autowired + private CardCopyInfoRepository cardCopyInfoRepository; + + @Autowired + private RestDocsFactory restDocsFactory; + + private static final String DEFAULT_URL = "/api/v1"; + + private final String cardInRecruit = "CardInRecruit"; + + + @Nested + class 카드_타입_카운트_조회_공고에서 { + + @Test + public void 성공() throws Exception { + + mockMvc.perform( + restDocsFactory.createRequest(DEFAULT_URL + "/recruits/{recruit-id}/cards/type-count", null, + HttpMethod.GET, objectMapper, 1L)) + .andExpect(status().isOk()) + .andExpect(jsonPath("서류_준비").value(1)) + .andExpect(jsonPath("과제_준비").value(2)) + .andExpect(jsonPath("인터뷰_준비").value(3)) + .andDo( + result -> restDocsFactory.getSuccessResource("[카드_타입_카운트_조회_공고에서] 성공", "카드_타입_카운트_조회_공고에서", + cardInRecruit, + null, objectMapper.readValue(result.getResponse().getContentAsString(), + CardTypeCountInRecruitGetResponse.class)) + .handle(result)); + } + } + + @Nested + class 카드_리스트_조회_공고에서 { + + @Test + public void 성공() throws Exception { + + mockMvc.perform( + restDocsFactory.createRequest(DEFAULT_URL + "/recruits/{recruit-id}/cards?type=인터뷰_준비", null, + HttpMethod.GET, objectMapper, 1L)) + .andExpect(status().isOk()) + .andDo( + result -> + restDocsFactory.getSuccessResourceList("[카드_리스트_조회_공고에서] 성공", "카드_리스트_조회_공고에서", cardInRecruit, + Lists.list(), objectMapper.readValue(result.getResponse().getContentAsString(), + new TypeReference>() { + })) + .handle(result)) + .andExpect(jsonPath("$", hasSize(3))); + } + } + + @Nested + class 카드_공고로_복사 { + + @Test + @Transactional + public void 성공() throws Exception { + + Long originalCardId = 1L; + + ResultActions resultActions = mockMvc.perform( + restDocsFactory.createRequest(DEFAULT_URL + "/recruits/{recruit-id}/cards/{card-id}", null, + HttpMethod.POST, objectMapper, 1L, originalCardId)) + .andExpect(status().isOk()); + + resultActions.andDo( + result -> + restDocsFactory.getSuccessResource("[카드_공고로_복사] 성공", "카드_공고로_복사", cardInRecruit, + null, + objectMapper.readValue(result.getResponse().getContentAsString(), CardCreateResponse.class)) + .handle(result)); + + + } + } +} diff --git a/src/test/resources/card-test-data.sql b/src/test/resources/card-test-data.sql index 603c6d8..9f41d82 100644 --- a/src/test/resources/card-test-data.sql +++ b/src/test/resources/card-test-data.sql @@ -7,23 +7,49 @@ from tag; delete from card_type; delete +from card_copy_info; +delete from card; delete +from recruit; +delete +from recruit_season; +delete from users; INSERT INTO users (deleted, created_at, update_at, user_id, dtype, email, login_id, name, password, role) -VALUES (false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 1, '1', null, 'test', 'test', 'test', +VALUES (false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 1, 'AuthTestUser', 'test', 'test', 'test', + 'test', 'USER'); -INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title) +INSERT INTO recruit_season (recruit_season_id, name, user_id) +VALUES (1, 'test', 1); + +INSERT INTO recruit (recruit_id, created_at, deleted, update_at, recruit_status, site_url, title, + recruit_season_id, user_id) +VALUES (1, '2024-08-14 23:10:09.000000', false, '2024-08-14 23:10:12.000000', 'APPLICATION_COMPLETED', 'test', 'test', + 1, 1); + +-- my info card +INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title, recruit_id) VALUES (false, false, '2024-07-24 21:22:04.000000', 1, '2024-07-24 21:22:07.000000', '2024-07-24 21:22:08.000000', 1, - 'test_contents', 'test_title'); -INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title) + 'test_contents', 'test_title', null); +INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title, recruit_id) VALUES (false, false, '1970-01-01 00:00:00.001000', 2, '1970-01-01 00:00:00.001000', '1970-01-01 00:00:00.001000', 1, - 'testc', 'testc'); -INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title) + 'testc', 'testc', null); +INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title, recruit_id) VALUES (false, false, '1970-01-01 00:00:00.001000', 3, '1970-01-01 00:00:00.001000', '1970-01-01 00:00:00.001000', 1, - 'testc', 'testt'); + 'testc', 'testt', null); +-- recruit card +INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title, recruit_id) +VALUES (false, true, '2024-07-24 21:22:04.000000', 4, '2024-07-24 21:22:07.000000', '2024-07-24 21:22:08.000000', 1, + 'test_contents', 'test_title', 1); +INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title, recruit_id) +VALUES (false, true, '2024-07-24 21:22:04.000000', 5, '2024-07-24 21:22:07.000000', '2024-07-24 21:22:08.000000', 1, + 'test_contents', 'test_title', 1); +INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title, recruit_id) +VALUES (false, true, '2024-07-24 21:22:04.000000', 6, '2024-07-24 21:22:07.000000', '2024-07-24 21:22:08.000000', 1, + 'test_contents', 'test_title', 1); INSERT INTO tag (tag_id, name, tag_type) VALUES (1, '스프링', 'CAPABILITY'); @@ -44,6 +70,26 @@ INSERT INTO card_type (card_type_id, card_type_value, card_id, deleted, update_a VALUES (5, 'INTERVIEW_QUESTION', 1, false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'); INSERT INTO card_type (card_type_id, card_type_value, card_id, deleted, update_at, created_at) VALUES (6, 'INTERVIEW_QUESTION', 2, false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'); +INSERT INTO card_type (card_type_id, card_type_value, card_id, deleted, update_at, created_at) +VALUES (7, 'DOCUMENT_PREPARING', 4, false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'); +INSERT INTO card_type (card_type_id, card_type_value, card_id, deleted, update_at, created_at) +VALUES (8, 'INTERVIEW_PREPARING', 4, false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'); +INSERT INTO card_type (card_type_id, card_type_value, card_id, deleted, update_at, created_at) +VALUES (9, 'ASSIGNMENT_PREPARING', 4, false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'); +INSERT INTO card_type (card_type_id, card_type_value, card_id, deleted, update_at, created_at) +VALUES (10, 'INTERVIEW_PREPARING', 5, false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'); +INSERT INTO card_type (card_type_id, card_type_value, card_id, deleted, update_at, created_at) +VALUES (11, 'INTERVIEW_PREPARING', 6, false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'); +INSERT INTO card_type (card_type_id, card_type_value, card_id, deleted, update_at, created_at) +VALUES (12, 'ASSIGNMENT_PREPARING', 6, false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'); + +INSERT INTO card_copy_info (card_copy_info_id, created_at, deleted, update_at, copied_time, card_id) +VALUES (1, '2024-08-14 23:20:56.000000', false, '2024-08-14 23:20:59.000000', '2024-08-14 23:21:01.000000', 4); +INSERT INTO card_copy_info (card_copy_info_id, created_at, deleted, update_at, copied_time, card_id) +VALUES (2, '2024-08-14 23:20:56.000000', false, '2024-08-14 23:20:59.000000', '2024-08-14 23:21:01.000000', 5); +INSERT INTO card_copy_info (card_copy_info_id, created_at, deleted, update_at, copied_time, card_id) +VALUES (3, '2024-08-14 23:20:56.000000', false, '2024-08-14 23:20:59.000000', '2024-08-14 23:21:01.000000', 6); + INSERT INTO card_tag (deleted, card_id, card_tag_id, created_at, tag_id, update_at) VALUES (false, 1, 1, '2024-07-24 21:26:28.000000', 1, '2024-07-24 21:26:40.000000'); @@ -63,4 +109,8 @@ VALUES (false, 2, 4, '2024-07-24 21:26:31.000000', 'test contents 111', '2024-07 INSERT INTO card_memo (deleted, card_id, card_memo_id, created_at, content, update_at) VALUES (false, 2, 5, '2024-07-24 21:26:31.000000', 'test contents 222', '2024-07-24 21:26:42.000000'); INSERT INTO card_memo (deleted, card_id, card_memo_id, created_at, content, update_at) -VALUES (false, 3, 6, '2024-07-24 21:26:31.000000', 'test contents 333', '2024-07-24 21:26:42.000000'); \ No newline at end of file +VALUES (false, 3, 6, '2024-07-24 21:26:31.000000', 'test contents 333', '2024-07-24 21:26:42.000000'); + + + +