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

[Feature/#43] recruit card api 개발 revert건 재반영 #59

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CardController {

@GetMapping("/cards/type-count")
public ResponseEntity<CardTypeCountGetResponse> getCardTypeCounts(@AuthUser User user) {
return ResponseEntity.ok(cardService.getCardTypeCounts(user));
return ResponseEntity.ok(cardService.getCardTypeCountsInMyInfo(user));
}

@GetMapping("/cards/{card-id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CardTypeCountInRecruitGetResponse> getCardTypeCounts(@AuthUser User user) {
return ResponseEntity.ok(cardInRecruitService.getCardTypeCountsInRecruit(user));
}

@GetMapping("/recruits/{recruit-id}/cards")
public ResponseEntity<List<CardListGetResponse>> 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<CardCreateResponse> createCard(
@AuthUser User user,
@PathVariable("recruit-id") Long recruitId,
@PathVariable("card-id") Long cardId) {

return ResponseEntity.ok(cardInRecruitService.copyCardFromMyInfo(user, cardId, recruitId));
}

}
Original file line number Diff line number Diff line change
@@ -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<CardCopyInfo, Long> {

}
41 changes: 37 additions & 4 deletions src/main/java/com/server/bbo_gak/domain/card/dao/CardDao.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,27 +19,59 @@ public class CardDao {

private final JPAQueryFactory query;

public List<Card> findAllByUserIdAndCardTypeValueList(User user, CardTypeValue[] cardTypeValueList) {
public List<Card> 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<Card> findAllByUserIdAndCardTypeValue(User user, CardTypeValue cardTypeValue) {
public List<Card> 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());

}
}
Original file line number Diff line number Diff line change
@@ -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<Card> cards) {

Map<CardTypeValue, Long> 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();
}

}
27 changes: 21 additions & 6 deletions src/main/java/com/server/bbo_gak/domain/card/entity/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<CardTag> cardTagList = new ArrayList<>();

Expand All @@ -60,29 +60,44 @@ public class Card extends BaseEntity {
@OneToMany(mappedBy = "card", fetch = FetchType.LAZY)
private List<CardType> 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<CardType> cardTypeList, User user) {
public Card(String title, String content, LocalDateTime accessTime, List<CardType> 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) {
return Card.builder()
.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();
}

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

@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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading
Loading