From e1a0019fccae2b426f7525159a84e401e0d63066 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 01:45:47 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20TagDto=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/funeat/product/dto/ProductResponse.java | 2 +- .../src/main/java/com/funeat/tag/{domain => dto}/TagDto.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) rename backend/src/main/java/com/funeat/tag/{domain => dto}/TagDto.java (86%) diff --git a/backend/src/main/java/com/funeat/product/dto/ProductResponse.java b/backend/src/main/java/com/funeat/product/dto/ProductResponse.java index e01eb354a..a0400ef05 100644 --- a/backend/src/main/java/com/funeat/product/dto/ProductResponse.java +++ b/backend/src/main/java/com/funeat/product/dto/ProductResponse.java @@ -2,7 +2,7 @@ import com.funeat.product.domain.Product; import com.funeat.tag.domain.Tag; -import com.funeat.tag.domain.TagDto; +import com.funeat.tag.dto.TagDto; import java.util.ArrayList; import java.util.List; diff --git a/backend/src/main/java/com/funeat/tag/domain/TagDto.java b/backend/src/main/java/com/funeat/tag/dto/TagDto.java similarity index 86% rename from backend/src/main/java/com/funeat/tag/domain/TagDto.java rename to backend/src/main/java/com/funeat/tag/dto/TagDto.java index 16770f5e2..41ca73ee9 100644 --- a/backend/src/main/java/com/funeat/tag/domain/TagDto.java +++ b/backend/src/main/java/com/funeat/tag/dto/TagDto.java @@ -1,4 +1,6 @@ -package com.funeat.tag.domain; +package com.funeat.tag.dto; + +import com.funeat.tag.domain.Tag; public class TagDto { From 58ef81c5505bfb61e5a9ec43956e372020d53c28 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 01:47:10 +0900 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20TagController=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EB=B0=8F=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=ED=83=9C=EA=B7=B8=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/funeat/tag/dto/TagsResponse.java | 22 +++++++++++++++++++ .../tag/presentation/TagController.java | 21 ++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 backend/src/main/java/com/funeat/tag/dto/TagsResponse.java create mode 100644 backend/src/main/java/com/funeat/tag/presentation/TagController.java diff --git a/backend/src/main/java/com/funeat/tag/dto/TagsResponse.java b/backend/src/main/java/com/funeat/tag/dto/TagsResponse.java new file mode 100644 index 000000000..005b89365 --- /dev/null +++ b/backend/src/main/java/com/funeat/tag/dto/TagsResponse.java @@ -0,0 +1,22 @@ +package com.funeat.tag.dto; + +import java.util.List; + +public class TagsResponse { + + private final String tagType; + private final List tags; + + public TagsResponse(final String tagType, final List tags) { + this.tagType = tagType; + this.tags = tags; + } + + public String getTagType() { + return tagType; + } + + public List getTags() { + return tags; + } +} diff --git a/backend/src/main/java/com/funeat/tag/presentation/TagController.java b/backend/src/main/java/com/funeat/tag/presentation/TagController.java new file mode 100644 index 000000000..a0e2377c8 --- /dev/null +++ b/backend/src/main/java/com/funeat/tag/presentation/TagController.java @@ -0,0 +1,21 @@ +package com.funeat.tag.presentation; + +import com.funeat.tag.dto.TagsResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; + +@Tag(name = "04.Tag", description = "태그 기능") +public interface TagController { + + @Operation(summary = "전체 태그 목록 조회", description = "전체 태그 목록을 태그 타입 별로 조회한다.") + @ApiResponse( + responseCode = "200", + description = "전체 태그 목록 조회 성공." + ) + @GetMapping + ResponseEntity> getAllTags(); +} From 59449c3268e823e127cd8d530f8ed065e7fe253b Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 01:49:00 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20TagType=20enum=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/funeat/tag/domain/Tag.java | 14 ++++++++++++++ .../main/java/com/funeat/tag/domain/TagType.java | 6 ++++++ 2 files changed, 20 insertions(+) create mode 100644 backend/src/main/java/com/funeat/tag/domain/TagType.java diff --git a/backend/src/main/java/com/funeat/tag/domain/Tag.java b/backend/src/main/java/com/funeat/tag/domain/Tag.java index 22edc07e2..8b4f8d995 100644 --- a/backend/src/main/java/com/funeat/tag/domain/Tag.java +++ b/backend/src/main/java/com/funeat/tag/domain/Tag.java @@ -1,6 +1,8 @@ package com.funeat.tag.domain; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -14,6 +16,9 @@ public class Tag { private String name; + @Enumerated(EnumType.STRING) + private TagType tagType; + protected Tag() { } @@ -21,6 +26,11 @@ public Tag(final String name) { this.name = name; } + public Tag(final String name, final TagType tagType) { + this.name = name; + this.tagType = tagType; + } + public Long getId() { return id; } @@ -28,4 +38,8 @@ public Long getId() { public String getName() { return name; } + + public TagType getTagType() { + return tagType; + } } diff --git a/backend/src/main/java/com/funeat/tag/domain/TagType.java b/backend/src/main/java/com/funeat/tag/domain/TagType.java new file mode 100644 index 000000000..5408099bd --- /dev/null +++ b/backend/src/main/java/com/funeat/tag/domain/TagType.java @@ -0,0 +1,6 @@ +package com.funeat.tag.domain; + +public enum TagType { + + TASTE, PRICE, ETC +} From 27cc3be04d1d06c01e3857e24da45c24823769b7 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 01:50:38 +0900 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=ED=83=9C?= =?UTF-8?q?=EA=B7=B8=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20=ED=83=9C=EA=B7=B8=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EB=B3=84=EB=A1=9C=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/tag/application/TagService.java | 38 +++++++++++++++++++ .../funeat/tag/persistence/TagRepository.java | 3 ++ .../tag/presentation/TagApiController.java | 24 ++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 backend/src/main/java/com/funeat/tag/application/TagService.java create mode 100644 backend/src/main/java/com/funeat/tag/presentation/TagApiController.java diff --git a/backend/src/main/java/com/funeat/tag/application/TagService.java b/backend/src/main/java/com/funeat/tag/application/TagService.java new file mode 100644 index 000000000..87bdacba8 --- /dev/null +++ b/backend/src/main/java/com/funeat/tag/application/TagService.java @@ -0,0 +1,38 @@ +package com.funeat.tag.application; + +import com.funeat.tag.domain.TagType; +import com.funeat.tag.dto.TagDto; +import com.funeat.tag.dto.TagsResponse; +import com.funeat.tag.persistence.TagRepository; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +public class TagService { + + private final TagRepository tagRepository; + + public TagService(final TagRepository tagRepository) { + this.tagRepository = tagRepository; + } + + public List getAllTags() { + final List responses = new ArrayList<>(); + for (final TagType tagType : TagType.values()) { + getTagsByTagType(responses, tagType); + } + return responses; + } + + private void getTagsByTagType(final List responses, final TagType tagType) { + final List tags = tagRepository.findTagsByTagType(tagType).stream() + .map(TagDto::toDto) + .collect(Collectors.toList()); + final TagsResponse tagsResponse = new TagsResponse(tagType.name(), tags); + responses.add(tagsResponse); + } +} diff --git a/backend/src/main/java/com/funeat/tag/persistence/TagRepository.java b/backend/src/main/java/com/funeat/tag/persistence/TagRepository.java index 2730bdbc2..b74e0197c 100644 --- a/backend/src/main/java/com/funeat/tag/persistence/TagRepository.java +++ b/backend/src/main/java/com/funeat/tag/persistence/TagRepository.java @@ -1,10 +1,13 @@ package com.funeat.tag.persistence; import com.funeat.tag.domain.Tag; +import com.funeat.tag.domain.TagType; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; public interface TagRepository extends JpaRepository { List findTagsByIdIn(final List tagIds); + + List findTagsByTagType(final TagType tagType); } diff --git a/backend/src/main/java/com/funeat/tag/presentation/TagApiController.java b/backend/src/main/java/com/funeat/tag/presentation/TagApiController.java new file mode 100644 index 000000000..b8e5c6b69 --- /dev/null +++ b/backend/src/main/java/com/funeat/tag/presentation/TagApiController.java @@ -0,0 +1,24 @@ +package com.funeat.tag.presentation; + +import com.funeat.tag.application.TagService; +import com.funeat.tag.dto.TagsResponse; +import java.util.List; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TagApiController implements TagController { + + private final TagService tagService; + + public TagApiController(final TagService tagService) { + this.tagService = tagService; + } + + @GetMapping("/api/tags") + public ResponseEntity> getAllTags() { + final List responses = tagService.getAllTags(); + return ResponseEntity.ok(responses); + } +} From 18a5e1ccba3475723e615d364576a62718dc953b Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 01:52:11 +0900 Subject: [PATCH 05/10] =?UTF-8?q?test:=20=ED=83=9C=EA=B7=B8=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EC=9C=BC=EB=A1=9C=20=ED=83=9C=EA=B7=B8=EB=93=A4?= =?UTF-8?q?=EC=9D=84=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20repository?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tag/persistence/TagRepositoryTest.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/src/test/java/com/funeat/tag/persistence/TagRepositoryTest.java b/backend/src/test/java/com/funeat/tag/persistence/TagRepositoryTest.java index 968a41b99..76f1305fe 100644 --- a/backend/src/test/java/com/funeat/tag/persistence/TagRepositoryTest.java +++ b/backend/src/test/java/com/funeat/tag/persistence/TagRepositoryTest.java @@ -1,5 +1,7 @@ package com.funeat.tag.persistence; +import static com.funeat.tag.domain.TagType.PRICE; +import static com.funeat.tag.domain.TagType.TASTE; import static org.assertj.core.api.Assertions.assertThat; import com.funeat.common.DataCleaner; @@ -28,7 +30,9 @@ class TagRepositoryTest { @Test void 여러_태그_아이디로_태그들을_조회_할_수_있다() { // given - final var tags = 태그_추가_요청(); + final var tag1 = 태그_추가_요청(new Tag("testTag1")); + final var tag2 = 태그_추가_요청(new Tag("testTag2")); + final var tags = List.of(tag1, tag2); final var tagIds = tags.stream() .map(Tag::getId) .collect(Collectors.toList()); @@ -41,10 +45,23 @@ class TagRepositoryTest { .isEqualTo(tags); } - private List 태그_추가_요청() { - final var testTag1 = tagRepository.save(new Tag("testTag1")); - final var testTag2 = tagRepository.save(new Tag("testTag2")); + @Test + void 태그_타입으로_태그들을_조회할_수_있다() { + // given + final var tag1 = 태그_추가_요청(new Tag("단짠단짠", TASTE)); + final var tag2 = 태그_추가_요청(new Tag("매콤해요", TASTE)); + final var tag3 = 태그_추가_요청(new Tag("갓성비", PRICE)); + final var expected = List.of(tag1, tag2); + + // when + final var actual = tagRepository.findTagsByTagType(TASTE); + + // then + assertThat(actual).usingRecursiveComparison() + .isEqualTo(expected); + } - return List.of(testTag1, testTag2); + private Tag 태그_추가_요청(final Tag tag) { + return tagRepository.save(tag); } } From 65b3d7ff2f47f66e1b4a06f701a0e96d11875513 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 01:53:23 +0900 Subject: [PATCH 06/10] =?UTF-8?q?test:=20=EC=A0=84=EC=B2=B4=20=ED=83=9C?= =?UTF-8?q?=EA=B7=B8=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EC=9D=B8=EC=88=98=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acceptance/tag/TagAcceptanceTest.java | 55 +++++++++++++++++++ .../com/funeat/acceptance/tag/TagSteps.java | 18 ++++++ 2 files changed, 73 insertions(+) create mode 100644 backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java create mode 100644 backend/src/test/java/com/funeat/acceptance/tag/TagSteps.java diff --git a/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java new file mode 100644 index 000000000..18e3d8228 --- /dev/null +++ b/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java @@ -0,0 +1,55 @@ +package com.funeat.acceptance.tag; + +import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; +import static com.funeat.acceptance.common.CommonSteps.정상_처리; +import static com.funeat.acceptance.tag.TagSteps.전체_태그_목록_조회_요청; +import static com.funeat.tag.domain.TagType.ETC; +import static com.funeat.tag.domain.TagType.PRICE; +import static com.funeat.tag.domain.TagType.TASTE; +import static org.assertj.core.api.Assertions.assertThat; + +import com.funeat.acceptance.common.AcceptanceTest; +import com.funeat.tag.domain.Tag; +import com.funeat.tag.domain.TagType; +import com.funeat.tag.dto.TagsResponse; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; + +@SuppressWarnings("NonAsciiCharacters") +public class TagAcceptanceTest extends AcceptanceTest { + + @Test + void 전체_태그_목록을_조회할_수_있다() { + // given + final var tag1 = 태그_추가_요청(new Tag("단짠단짠", TASTE)); + final var tag2 = 태그_추가_요청(new Tag("매콤해요", TASTE)); + final var tag3 = 태그_추가_요청(new Tag("갓성비", PRICE)); + final var tag4 = 태그_추가_요청(new Tag("바삭바삭", ETC)); + + // when + final var response = 전체_태그_목록_조회_요청(); + + // then + STATUS_CODE를_검증한다(response, 정상_처리); + 전체_태그_목록_조회_결과를_검증한다(response, List.of(tag1, tag2, tag3, tag4)); + } + + private Tag 태그_추가_요청(final Tag tag) { + return tagRepository.save(tag); + } + + private void 전체_태그_목록_조회_결과를_검증한다(final ExtractableResponse response, final List tags) { + final var expectedByType = tags.stream().collect(Collectors.groupingBy(Tag::getTagType)); + final var actual = response.jsonPath().getList("", TagsResponse.class); + + for (final TagsResponse tagsResponse : actual) { + final TagType tagType = TagType.valueOf(tagsResponse.getTagType()); + assertThat(tagType).isIn(expectedByType.keySet()); + assertThat(tagsResponse.getTags()).usingRecursiveComparison() + .isEqualTo(expectedByType.get(tagType)); + } + } +} diff --git a/backend/src/test/java/com/funeat/acceptance/tag/TagSteps.java b/backend/src/test/java/com/funeat/acceptance/tag/TagSteps.java new file mode 100644 index 000000000..53dae95a1 --- /dev/null +++ b/backend/src/test/java/com/funeat/acceptance/tag/TagSteps.java @@ -0,0 +1,18 @@ +package com.funeat.acceptance.tag; + +import static io.restassured.RestAssured.given; + +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; + +@SuppressWarnings("NonAsciiCharacters") +public class TagSteps { + + public static ExtractableResponse 전체_태그_목록_조회_요청() { + return given() + .when() + .get("/api/tags") + .then() + .extract(); + } +} From a9e91b849920e5841ad4fde9a03ef54e73380189 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 01:57:46 +0900 Subject: [PATCH 07/10] =?UTF-8?q?refactor:=20TagsResponse=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EB=8C=80=EC=8B=A0=20=EC=A0=95=EC=A0=81=20?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/funeat/tag/application/TagService.java | 2 +- backend/src/main/java/com/funeat/tag/dto/TagsResponse.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/funeat/tag/application/TagService.java b/backend/src/main/java/com/funeat/tag/application/TagService.java index 87bdacba8..71e84fdc0 100644 --- a/backend/src/main/java/com/funeat/tag/application/TagService.java +++ b/backend/src/main/java/com/funeat/tag/application/TagService.java @@ -32,7 +32,7 @@ private void getTagsByTagType(final List responses, final TagType final List tags = tagRepository.findTagsByTagType(tagType).stream() .map(TagDto::toDto) .collect(Collectors.toList()); - final TagsResponse tagsResponse = new TagsResponse(tagType.name(), tags); + final TagsResponse tagsResponse = TagsResponse.toResponse(tagType.name(), tags); responses.add(tagsResponse); } } diff --git a/backend/src/main/java/com/funeat/tag/dto/TagsResponse.java b/backend/src/main/java/com/funeat/tag/dto/TagsResponse.java index 005b89365..e81f29e10 100644 --- a/backend/src/main/java/com/funeat/tag/dto/TagsResponse.java +++ b/backend/src/main/java/com/funeat/tag/dto/TagsResponse.java @@ -12,6 +12,10 @@ public TagsResponse(final String tagType, final List tags) { this.tags = tags; } + public static TagsResponse toResponse(final String tagType, final List tags) { + return new TagsResponse(tagType, tags); + } + public String getTagType() { return tagType; } From aca7d8a8619456d8047b66cbf8a6de9b953b9f58 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 02:05:39 +0900 Subject: [PATCH 08/10] =?UTF-8?q?test:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20Tag=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/com/funeat/tag/domain/Tag.java | 4 ---- .../funeat/acceptance/product/ProductAcceptanceTest.java | 8 ++++---- .../funeat/acceptance/review/ReviewAcceptanceTest.java | 5 +++-- .../com/funeat/review/application/ReviewServiceTest.java | 5 +++-- .../review/persistence/ReviewTagRepositoryTest.java | 9 +++++---- .../com/funeat/tag/persistence/TagRepositoryTest.java | 5 +++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/com/funeat/tag/domain/Tag.java b/backend/src/main/java/com/funeat/tag/domain/Tag.java index 8b4f8d995..554b8db6f 100644 --- a/backend/src/main/java/com/funeat/tag/domain/Tag.java +++ b/backend/src/main/java/com/funeat/tag/domain/Tag.java @@ -22,10 +22,6 @@ public class Tag { protected Tag() { } - public Tag(final String name) { - this.name = name; - } - public Tag(final String name, final TagType tagType) { this.name = name; this.tagType = tagType; diff --git a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java index 7e3f9da33..3356a2426 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java @@ -24,6 +24,7 @@ import com.funeat.review.domain.Review; import com.funeat.review.presentation.dto.ReviewCreateRequest; import com.funeat.tag.domain.Tag; +import com.funeat.tag.domain.TagType; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; @@ -318,7 +319,6 @@ class 리뷰수_기준_내림차순으로_카테고리별_상품_목록_조회 { review3_1, review3_2, review3_3); 복수_리뷰_추가_요청(reviews); - // when final var response = 카테고리별_상품_목록_조회_요청(categoryId, "reviewCount", "desc", 0); @@ -373,9 +373,9 @@ class 리뷰수_기준_내림차순으로_카테고리별_상품_목록_조회 { final Product product = new Product("삼각김밥1", 1000L, "image.png", "맛있는 삼각김밥1", 간편식사); final Long productId = 상품_추가_요청(product); final Long memberId = 기본_멤버_추가_요청(); - final Tag tag1 = 태그_추가_요청(new Tag("1번")); - final Tag tag2 = 태그_추가_요청(new Tag("2번")); - final Tag tag3 = 태그_추가_요청(new Tag("3번")); + final Tag tag1 = 태그_추가_요청(new Tag("1번", TagType.ETC)); + final Tag tag2 = 태그_추가_요청(new Tag("2번", TagType.ETC)); + final Tag tag3 = 태그_추가_요청(new Tag("3번", TagType.ETC)); final MultiPartSpecification image = 리뷰_사진_명세_요청(); final ReviewCreateRequest request1 = new ReviewCreateRequest(4L, diff --git a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index acc2d2d68..33334a2bc 100644 --- a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -23,6 +23,7 @@ import com.funeat.review.presentation.dto.SortingReviewDto; import com.funeat.review.presentation.dto.SortingReviewsPageDto; import com.funeat.tag.domain.Tag; +import com.funeat.tag.domain.TagType; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.restassured.specification.MultiPartSpecification; @@ -106,8 +107,8 @@ class ReviewAcceptanceTest extends AcceptanceTest { } private List 태그_추가_요청() { - final Tag testTag1 = tagRepository.save(new Tag("testTag1")); - final Tag testTag2 = tagRepository.save(new Tag("testTag2")); + final Tag testTag1 = tagRepository.save(new Tag("testTag1", TagType.ETC)); + final Tag testTag2 = tagRepository.save(new Tag("testTag2", TagType.ETC)); return List.of(testTag1.getId(), testTag2.getId()); } diff --git a/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java b/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java index fc4f7177b..0957277bd 100644 --- a/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -17,6 +17,7 @@ import com.funeat.review.presentation.dto.ReviewFavoriteRequest; import com.funeat.review.presentation.dto.SortingReviewDto; import com.funeat.tag.domain.Tag; +import com.funeat.tag.domain.TagType; import com.funeat.tag.persistence.TagRepository; import java.util.List; import java.util.stream.Collectors; @@ -166,8 +167,8 @@ void init() { } private List 태그_추가_요청() { - final Tag testTag1 = tagRepository.save(new Tag("testTag1")); - final Tag testTag2 = tagRepository.save(new Tag("testTag2")); + final Tag testTag1 = tagRepository.save(new Tag("testTag1", TagType.ETC)); + final Tag testTag2 = tagRepository.save(new Tag("testTag2", TagType.ETC)); return List.of(testTag1, testTag2); } diff --git a/backend/src/test/java/com/funeat/review/persistence/ReviewTagRepositoryTest.java b/backend/src/test/java/com/funeat/review/persistence/ReviewTagRepositoryTest.java index b65e52226..22cf8f5b1 100644 --- a/backend/src/test/java/com/funeat/review/persistence/ReviewTagRepositoryTest.java +++ b/backend/src/test/java/com/funeat/review/persistence/ReviewTagRepositoryTest.java @@ -11,6 +11,7 @@ import com.funeat.review.domain.Review; import com.funeat.review.domain.ReviewTag; import com.funeat.tag.domain.Tag; +import com.funeat.tag.domain.TagType; import com.funeat.tag.persistence.TagRepository; import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; @@ -53,10 +54,10 @@ class ReviewTagRepositoryTest { final var product = new Product("망고", 1_000L, "mango.png", "망고망고", null); productRepository.save(product); - final var tag1 = new Tag("1번"); - final var tag2 = new Tag("2번"); - final var tag3 = new Tag("3번"); - final var tag4 = new Tag("4번"); + final var tag1 = new Tag("1번", TagType.ETC); + final var tag2 = new Tag("2번", TagType.ETC); + final var tag3 = new Tag("3번", TagType.ETC); + final var tag4 = new Tag("4번", TagType.ETC); tagRepository.saveAll(List.of(tag1, tag2, tag3, tag4)); final var review1 = new Review(member, product, "review1.png", 5L, "최고의 망고", true, 25L); diff --git a/backend/src/test/java/com/funeat/tag/persistence/TagRepositoryTest.java b/backend/src/test/java/com/funeat/tag/persistence/TagRepositoryTest.java index 76f1305fe..1defe725a 100644 --- a/backend/src/test/java/com/funeat/tag/persistence/TagRepositoryTest.java +++ b/backend/src/test/java/com/funeat/tag/persistence/TagRepositoryTest.java @@ -1,5 +1,6 @@ package com.funeat.tag.persistence; +import static com.funeat.tag.domain.TagType.ETC; import static com.funeat.tag.domain.TagType.PRICE; import static com.funeat.tag.domain.TagType.TASTE; import static org.assertj.core.api.Assertions.assertThat; @@ -30,8 +31,8 @@ class TagRepositoryTest { @Test void 여러_태그_아이디로_태그들을_조회_할_수_있다() { // given - final var tag1 = 태그_추가_요청(new Tag("testTag1")); - final var tag2 = 태그_추가_요청(new Tag("testTag2")); + final var tag1 = 태그_추가_요청(new Tag("testTag1", ETC)); + final var tag2 = 태그_추가_요청(new Tag("testTag2", ETC)); final var tags = List.of(tag1, tag2); final var tagIds = tags.stream() .map(Tag::getId) From a308ea72f3459e0db372257d042cc07c15792439 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 17:22:47 +0900 Subject: [PATCH 09/10] =?UTF-8?q?refactor:=20getTagsByTagType=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EC=97=90=EC=84=9C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=EC=97=90=20=EB=A7=9E=EA=B2=8C=20TagsResponse?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=94=EB=A1=9C=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/funeat/tag/application/TagService.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/funeat/tag/application/TagService.java b/backend/src/main/java/com/funeat/tag/application/TagService.java index 71e84fdc0..efb15849d 100644 --- a/backend/src/main/java/com/funeat/tag/application/TagService.java +++ b/backend/src/main/java/com/funeat/tag/application/TagService.java @@ -23,16 +23,15 @@ public TagService(final TagRepository tagRepository) { public List getAllTags() { final List responses = new ArrayList<>(); for (final TagType tagType : TagType.values()) { - getTagsByTagType(responses, tagType); + responses.add(getTagsByTagType(tagType)); } return responses; } - private void getTagsByTagType(final List responses, final TagType tagType) { + private TagsResponse getTagsByTagType(final TagType tagType) { final List tags = tagRepository.findTagsByTagType(tagType).stream() .map(TagDto::toDto) .collect(Collectors.toList()); - final TagsResponse tagsResponse = TagsResponse.toResponse(tagType.name(), tags); - responses.add(tagsResponse); + return TagsResponse.toResponse(tagType.name(), tags); } } From 22647061f1a96b9c5be4523be1047481625b93a5 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 17:23:41 +0900 Subject: [PATCH 10/10] =?UTF-8?q?style:=20=EA=B0=9C=ED=96=89=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/funeat/acceptance/tag/TagAcceptanceTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java index 18e3d8228..0ddc4e723 100644 --- a/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java @@ -42,8 +42,10 @@ public class TagAcceptanceTest extends AcceptanceTest { } private void 전체_태그_목록_조회_결과를_검증한다(final ExtractableResponse response, final List tags) { - final var expectedByType = tags.stream().collect(Collectors.groupingBy(Tag::getTagType)); - final var actual = response.jsonPath().getList("", TagsResponse.class); + final var expectedByType = tags.stream() + .collect(Collectors.groupingBy(Tag::getTagType)); + final var actual = response.jsonPath() + .getList("", TagsResponse.class); for (final TagsResponse tagsResponse : actual) { final TagType tagType = TagType.valueOf(tagsResponse.getTagType());