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

[BE] issue99: 태그ID로 필터링하여 스터디 검색하도록 수정 #100

Merged
merged 1 commit into from
Jul 20, 2022
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 @@ -10,26 +10,26 @@
@ToString
public class TagRequest {

private final List<String> generation;
private final List<String> area;
private final List<String> tag;
private final List<Long> generation;
private final List<Long> area;
private final List<Long> tag;

public TagRequest(final List<String> generation, final List<String> area, final List<String> tag) {
public TagRequest(final List<Long> generation, final List<Long> area, final List<Long> tag) {
this.generation = Objects.requireNonNullElseGet(generation, ArrayList::new);
this.area = Objects.requireNonNullElseGet(area, ArrayList::new);
this.tag = Objects.requireNonNullElseGet(tag, ArrayList::new);
}

public List<String> getFilterNames() {
List<String> filterNames = new ArrayList<>();
filterNames.addAll(generation);
filterNames.addAll(area);
filterNames.addAll(tag);
public List<Long> getFilterIds() {
List<Long> filterIds = new ArrayList<>();
filterIds.addAll(generation);
filterIds.addAll(area);
filterIds.addAll(tag);

return filterNames;
return filterIds;
}

public boolean isEmpty() {
return getFilterNames().isEmpty();
return getFilterIds().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ private StudiesResponse searchWithoutFilter(final String title, final Pageable p
}

private List<Tag> getFilterFromName(final TagRequest tagRequest) {
final List<String> filterNames = tagRequest.getFilterNames();
final List<Long> filterIds = tagRequest.getFilterIds();
final List<Tag> tags = new ArrayList<>();

for (String filterName : filterNames) {
final Tag tag = tagRepository.findByName(filterName)
for (Long filterId : filterIds) {
final Tag tag = tagRepository.findById(filterId)
.orElseThrow(TagNotExistException::new);
tags.add(tag);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.woowacourse.moamoa.tag.domain.repository;

import com.woowacourse.moamoa.tag.domain.Tag;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface JpaTagRepository extends JpaRepository<Tag, Long>, TagRepository {
Optional<Tag> findByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
public interface TagRepository {

List<Tag> findAllByNameContainingIgnoreCase(String name);
Optional<Tag> findByName(String name);

Optional<Tag> findById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void getStudiesByHasSpaceKeyword() {
public void getStudiesByFilter() {
RestAssured.given().log().all()
.queryParam("title", "")
.queryParam("area", "BE")
.queryParam("area", 3)
.queryParam("page", 0)
.queryParam("size", 3)
.when().log().all()
Expand All @@ -147,7 +147,7 @@ public void getStudiesByFilter() {
public void getStudiesByFilterAndTitle() {
RestAssured.given().log().all()
.queryParam("title", "ja")
.queryParam("area", "BE")
.queryParam("area", 3)
.queryParam("page", 0)
.queryParam("size", 3)
.when().log().all()
Expand All @@ -168,8 +168,8 @@ public void getStudiesByFilterAndTitle() {
public void getStudiesBySameCategoryFilter() {
RestAssured.given().log().all()
.queryParam("title", "")
.queryParam("area", "BE")
.queryParam("area", "FE")
.queryParam("area", 3)
.queryParam("area", 4)
.queryParam("page", 0)
.queryParam("size", 5)
.when().log().all()
Expand All @@ -195,8 +195,8 @@ public void getStudiesBySameCategoryFilter() {
public void getStudiesByAnotherCategoryFilter() {
RestAssured.given().log().all()
.queryParam("title", "")
.queryParam("area", "BE")
.queryParam("tag", "Java")
.queryParam("area", 3)
.queryParam("tag", 1)
.queryParam("page", 0)
.queryParam("size", 3)
.when().log().all()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public void searchByTitleAndFilter() {
@Test
public void searchByFilters() {
// given
Tag tag_4기 = tagRepository.findByName("4기").orElseThrow();
Tag tag_BE = tagRepository.findByName("BE").orElseThrow();
Tag tag_FE = tagRepository.findByName("FE").orElseThrow();
Tag tag_4기 = tagRepository.findById(2L).orElseThrow();
Tag tag_BE = tagRepository.findById(3L).orElseThrow();
Tag tag_FE = tagRepository.findById(4L).orElseThrow();

final PageRequest pageRequest = PageRequest.of(0, 5);
final StudySearchCondition searchCondition = new StudySearchCondition("",
Expand Down Expand Up @@ -163,9 +163,9 @@ public void searchByFilters() {
@Test
public void searchByFiltersWithTitle() {
// given
Tag tag_4기 = tagRepository.findByName("4기").orElseThrow();
Tag tag_BE = tagRepository.findByName("BE").orElseThrow();
Tag tag_FE = tagRepository.findByName("FE").orElseThrow();
Tag tag_4기 = tagRepository.findById(2L).orElseThrow();
Tag tag_BE = tagRepository.findById(3L).orElseThrow();
Tag tag_FE = tagRepository.findById(4L).orElseThrow();

final PageRequest pageRequest = PageRequest.of(0, 5);
final StudySearchCondition searchCondition = new StudySearchCondition("java",
Expand Down