Skip to content

Commit

Permalink
[hotfix][#117] card search api 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
JeongSangByuk committed Sep 12, 2024
1 parent eaae736 commit 31c464b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public class CardSearchController {
@GetMapping("/search/cards")
public ResponseEntity<List<CardSearchByTagListResponse>> searchCardByTagList(
@AuthUser User user,
@RequestParam(value = "card-type-value-group", required = false) String cardTypeValueGroup,
@RequestParam(value = "tag-ids") List<Long> tagIdList) {
return ResponseEntity.ok(cardSearchService.searchCardByTagList(user, cardTypeValueGroup, tagIdList));
return ResponseEntity.ok(cardSearchService.searchCardByTagList(user, tagIdList));
}

@GetMapping("/search/card-tag-history")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public List<Card> findAllByUserIdAndCardTypeValueList(User user, CardTypeValue[]
.leftJoin(qCard.cardTypeList, qCardType).fetchJoin()
.where(qCard.user.id.eq(user.getId())
.and(cardTypeValueList.length == 0 ? null : qCardType.cardTypeValue.in(cardTypeValueList))
.and(qCardType.cardTypeValue.in(cardTypeValueList))
.and(recruitId == null ? null : qCard.recruit.id.eq(recruitId)))
.distinct()
.fetch();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.server.bbo_gak.domain.card.dao;

import com.server.bbo_gak.domain.card.entity.CardTagSearchHistory;
import com.server.bbo_gak.domain.card.entity.Tag;
import com.server.bbo_gak.domain.user.entity.User;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CardTagSearchHistoryRepository extends JpaRepository<CardTagSearchHistory, Long> {

List<CardTagSearchHistory> findTop10ByUserOrderByCreatedDate(User user);

void deleteAllByUserAndTagIn(User user, List<Tag> tags);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
import com.server.bbo_gak.domain.card.entity.Card;
import com.server.bbo_gak.domain.card.entity.CardTagSearchHistory;
import com.server.bbo_gak.domain.card.entity.CardTypeValue;
import com.server.bbo_gak.domain.card.entity.CardTypeValueGroup;
import com.server.bbo_gak.domain.card.entity.Tag;
import com.server.bbo_gak.domain.user.entity.User;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -28,14 +25,12 @@ public class CardSearchService {
private final CardDao cardDao;

@Transactional
public List<CardSearchByTagListResponse> searchCardByTagList(User user, String cardTypeValueGroup,
List<Long> tagIdList) {
public List<CardSearchByTagListResponse> searchCardByTagList(User user, List<Long> tagIdList) {

List<Tag> tagList = tagRepository.findAllById(tagIdList);
List<Card> cards = cardDao.findAllByUserIdAndCardTypeValueList(user, new CardTypeValue[0], null);

List<Card> cards = cardDao.findAllByUserIdAndCardTypeValueList(user, getCardTypeValueList(cardTypeValueGroup),
null);

cardTagSearchHistoryRepository.deleteAllByUserAndTagIn(user, tagList);
cardTagSearchHistoryRepository.saveAll(tagList.stream()
.map(tag -> new CardTagSearchHistory(user, tag))
.toList());
Expand All @@ -45,7 +40,7 @@ public List<CardSearchByTagListResponse> searchCardByTagList(User user, String c
.filter(card -> tagList.isEmpty() || card.isTagListContain(tagList))
.sorted(Comparator.comparing(Card::getUpdatedDate).reversed())
.map(CardSearchByTagListResponse::from)
.collect(Collectors.toList());
.toList();
}

@Transactional(readOnly = true)
Expand All @@ -55,10 +50,4 @@ public List<TagGetResponse> getCardTagSearchHistoryList(User user) {
.toList();
}

private CardTypeValue[] getCardTypeValueList(String cardTypeValueGroupInput) {
return Optional.ofNullable(cardTypeValueGroupInput)
.map(cardTypeValueGroup -> CardTypeValueGroup.findByValue(cardTypeValueGroup).getCardTypeValueList())
.orElseGet(() -> new CardTypeValue[0]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class 카드_검색_태그_리스트로 {

mockMvc.perform(get(DEFAULT_URL + "/search/cards").contentType(MediaType.APPLICATION_JSON)
.queryParam("tag-ids", "1,2")
.queryParam("card-type-value-group", "내_정보")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("[카드_검색_태그_리스트로] 성공", preprocessResponse(prettyPrint()), resource(getBuild())));
Expand All @@ -48,8 +47,7 @@ class 카드_검색_태그_리스트로 {
private ResourceSnippetParameters getBuild() {
return ResourceSnippetParameters.builder().description("카드_검색_태그_리스트로").tags(cardSearch)
.queryParameters(
parameterWithName("tag-ids").description("태그 아이디 리스트"),
parameterWithName("card-type-value-group").description("카드 타입 그룹").optional())
parameterWithName("tag-ids").description("태그 아이디 리스트"))
.responseSchema(Schema.schema("CardListGetResponse"))
.responseFields(fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("Card ID"),
fieldWithPath("[].title").type(JsonFieldType.STRING).description("Card 제목"),
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/card-test-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ VALUES (4, 'EXPERIENCE', 2, false, '2024-07-24 21:26:28.000000', '2024-07-24 21:
INSERT INTO card_type (card_type_id, card_type_value, card_id, deleted, update_at, created_at)
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');
VALUES (6, 'PERSONAL_STATEMENT', 3, 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)
Expand Down

0 comments on commit 31c464b

Please sign in to comment.