-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Item 테이블 초기 데이터 구축 및 조회 API 구현 #56
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fbe886a
feat: item info 테이블 생성 flyway script 작성
dev-ant e09a3a8
feat: item info 조회 컨트롤러, 서비스, 레포지토리 구현
dev-ant 3349a14
fix: item info에서 name을 pk로 변경
dev-ant 0e510d3
feat: item info repository 추상화를 위한 Port, PortImpl 클래스 분리
dev-ant 97edb2c
fix: optimize imports
dev-ant 4ed05d2
Fix: V6 flyway script 초디 데이터 적재 INSERT문 sub_category 중복 제거
dev-ant 6c5c67a
fix: ItemInfoJpaRepository 불필요한 finAll 함수 제거
dev-ant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 0 additions & 18 deletions
18
src/main/java/until/the/eternity/item/application/service/ItemService.java
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/main/java/until/the/eternity/item/interfaces/rest/controller/ItemController.java
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
src/main/java/until/the/eternity/iteminfo/application/service/ItemInfoService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package until.the.eternity.iteminfo.application.service; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import until.the.eternity.iteminfo.domain.entity.ItemInfo; | ||
| import until.the.eternity.iteminfo.domain.repository.ItemInfoRepositoryPort; | ||
| import until.the.eternity.iteminfo.interfaces.rest.dto.response.ItemCategoryResponse; | ||
| import until.the.eternity.iteminfo.interfaces.rest.dto.response.ItemInfoResponse; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Service | ||
| @Transactional(readOnly = true) | ||
| @RequiredArgsConstructor | ||
| public class ItemInfoService { | ||
|
|
||
| private final ItemInfoRepositoryPort itemInfoRepository; | ||
|
|
||
| public List<ItemCategoryResponse> findItemCategories() { | ||
| return ItemCategoryResponse.from(); | ||
| } | ||
|
|
||
| public List<ItemInfoResponse> findAll() { | ||
| List<ItemInfo> itemInfos = itemInfoRepository.findAll(); | ||
| return ItemInfoResponse.from(itemInfos); | ||
| } | ||
|
|
||
| public List<ItemInfoResponse> findByTopCategory(String topCategory) { | ||
| List<ItemInfo> itemInfos = itemInfoRepository.findByTopCategory(topCategory); | ||
| return ItemInfoResponse.from(itemInfos); | ||
| } | ||
|
|
||
| public List<ItemInfoResponse> findBySubCategory(String subCategory) { | ||
| List<ItemInfo> itemInfos = itemInfoRepository.findBySubCategory(subCategory); | ||
| return ItemInfoResponse.from(itemInfos); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/main/java/until/the/eternity/iteminfo/domain/entity/ItemInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package until.the.eternity.iteminfo.domain.entity; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table(name = "item_info") | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class ItemInfo { | ||
|
|
||
| @Id | ||
| @Column(name = "name", nullable = false) | ||
| private String name; | ||
|
|
||
| @Column(name = "sub_category", nullable = false) | ||
| private String subCategory; | ||
|
|
||
| @Column(name = "top_category", nullable = false) | ||
| private String topCategory; | ||
|
|
||
| @Column(name = "description") | ||
| private String description; | ||
|
|
||
| @Column(name = "inventory_width") | ||
| private Byte inventoryWidth; | ||
|
|
||
| @Column(name = "inventory_height") | ||
| private Byte inventoryHeight; | ||
|
|
||
| @Column(name = "inventory_max_bundle_count") | ||
| private Integer inventoryMaxBundleCount; | ||
|
|
||
| @Column(name = "history", length = 3000) | ||
| private String history; | ||
|
|
||
| @Column(name = "acquisition_method", length = 3000) | ||
| private String acquisitionMethod; | ||
|
|
||
| @Column(name = "store_sales_price", length = 3000) | ||
| private String storeSalesPrice; | ||
|
|
||
| @Column(name = "weapon_type") | ||
| private String weaponType; | ||
|
|
||
| @Column(name = "repair") | ||
| private String repair; | ||
|
|
||
| @Column(name = "max_alteration_count") | ||
| private Byte maxAlterationCount; | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/until/the/eternity/iteminfo/domain/repository/ItemInfoRepositoryPort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package until.the.eternity.iteminfo.domain.repository; | ||
|
|
||
| import until.the.eternity.iteminfo.domain.entity.ItemInfo; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface ItemInfoRepositoryPort { | ||
| List<ItemInfo> findAll(); | ||
|
|
||
| List<ItemInfo> findByTopCategory(String topCategory); | ||
|
|
||
| List<ItemInfo> findBySubCategory(String subCategory); | ||
| } |
16 changes: 16 additions & 0 deletions
16
...in/java/until/the/eternity/iteminfo/infrastructure/persistence/ItemInfoJpaRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package until.the.eternity.iteminfo.infrastructure.persistence; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| import until.the.eternity.iteminfo.domain.entity.ItemInfo; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface ItemInfoJpaRepository | ||
| extends JpaRepository<ItemInfo, String>, JpaSpecificationExecutor<ItemInfo> { | ||
|
|
||
|
|
||
| List<ItemInfo> findByTopCategory(String topCategory); | ||
|
|
||
| List<ItemInfo> findBySubCategory(String subCategory); | ||
| } |
29 changes: 29 additions & 0 deletions
29
...va/until/the/eternity/iteminfo/infrastructure/persistence/ItemInfoRepositoryPortImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package until.the.eternity.iteminfo.infrastructure.persistence; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
| import until.the.eternity.iteminfo.domain.entity.ItemInfo; | ||
| import until.the.eternity.iteminfo.domain.repository.ItemInfoRepositoryPort; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class ItemInfoRepositoryPortImpl implements ItemInfoRepositoryPort { | ||
| private final ItemInfoJpaRepository jpaRepository; | ||
|
|
||
| @Override | ||
| public List<ItemInfo> findAll() { | ||
| return jpaRepository.findAll(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<ItemInfo> findByTopCategory(String topCategory) { | ||
| return jpaRepository.findByTopCategory(topCategory); | ||
| } | ||
|
|
||
| @Override | ||
| public List<ItemInfo> findBySubCategory(String subCategory) { | ||
| return jpaRepository.findBySubCategory(subCategory); | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
src/main/java/until/the/eternity/iteminfo/interfaces/rest/controller/ItemInfoController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package until.the.eternity.iteminfo.interfaces.rest.controller; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import until.the.eternity.common.response.ApiResponse; | ||
| import until.the.eternity.iteminfo.application.service.ItemInfoService; | ||
| import until.the.eternity.iteminfo.interfaces.rest.dto.response.ItemCategoryResponse; | ||
| import until.the.eternity.iteminfo.interfaces.rest.dto.response.ItemInfoResponse; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/item-infos") | ||
| @RequiredArgsConstructor | ||
| @Tag(name = "Item Info", description = "아이템 정보 조회 API") | ||
| public class ItemInfoController { | ||
|
|
||
| private final ItemInfoService itemInfoService; | ||
|
|
||
| @GetMapping("/categories") | ||
| @Operation(summary = "카테고리 정보", description = "아이템 상위 카테고리, 하위 카테고리 정보 조회") | ||
| public ResponseEntity<ApiResponse<List<ItemCategoryResponse>>> findItemCategories() { | ||
| List<ItemCategoryResponse> itemCategories = itemInfoService.findItemCategories(); | ||
| return ResponseEntity.ok(ApiResponse.success(itemCategories)); | ||
| } | ||
|
|
||
| @Operation(summary = "모든 아이템 정보 조회", description = "시스템에 저장된 모든 아이템 정보를 조회합니다.") | ||
| @GetMapping | ||
| public List<ItemInfoResponse> getAllItemInfos() { | ||
| return itemInfoService.findAll(); | ||
| } | ||
|
|
||
| @Operation(summary = "상위 카테고리로 검색", description = "상위 카테고리 이름으로 아이템 정보를 검색합니다.") | ||
| @GetMapping("/search/top-category") | ||
| public List<ItemInfoResponse> searchItemInfosByTopCategory( | ||
| @Parameter(description = "검색할 상위 카테고리", required = true, example = "무기") @RequestParam | ||
| String topCategory) { | ||
| return itemInfoService.findByTopCategory(topCategory); | ||
| } | ||
|
|
||
| @Operation(summary = "하위 카테고리로 검색", description = "하위 카테고리 이름으로 아이템 정보를 검색합니다.") | ||
| @GetMapping("/search/sub-category") | ||
| public List<ItemInfoResponse> searchItemInfosBySubCategory( | ||
| @Parameter(description = "검색할 하위 카테고리", required = true, example = "한손검") @RequestParam | ||
| String subCategory) { | ||
| return itemInfoService.findBySubCategory(subCategory); | ||
dev-ant marked this conversation as resolved.
Show resolved
Hide resolved
dev-ant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2
...rfaces/rest/dto/ItemCategoryResponse.java → ...st/dto/response/ItemCategoryResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/until/the/eternity/iteminfo/interfaces/rest/dto/response/ItemInfoResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package until.the.eternity.iteminfo.interfaces.rest.dto.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.Builder; | ||
| import until.the.eternity.iteminfo.domain.entity.ItemInfo; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Builder | ||
| @Schema(description = "아이템 정보 응답 DTO") | ||
| public record ItemInfoResponse( | ||
| @Schema(description = "아이템 이름", example = "나뭇가지") String name, | ||
| @Schema(description = "상위 카테고리", example = "무기") String topCategory, | ||
| @Schema(description = "하위 카테고리", example = "한손검") String subCategory, | ||
| @Schema(description = "아이템 설명", example = "흔한 나뭇가지이다.") String description, | ||
| @Schema(description = "인벤토리 가로 크기", example = "1") Byte inventoryWidth, | ||
| @Schema(description = "인벤토리 세로 크기", example = "2") Byte inventoryHeight, | ||
| @Schema(description = "최대 번들 가능 개수", example = "100") Integer inventoryMaxBundleCount, | ||
| @Schema(description = "아이템 역사") String history, | ||
| @Schema(description = "입수 방법") String acquisitionMethod, | ||
| @Schema(description = "1개 상점 판매가") String storeSalesPrice, | ||
| @Schema(description = "공격 속도 및 무기 타입") String weaponType, | ||
| @Schema(description = "수리 정보") String repair, | ||
| @Schema(description = "최대 개조 횟수") Byte maxAlterationCount) { | ||
| public static ItemInfoResponse from(ItemInfo itemInfo) { | ||
| return ItemInfoResponse.builder() | ||
| .name(itemInfo.getName()) | ||
| .topCategory(itemInfo.getTopCategory()) | ||
| .subCategory(itemInfo.getSubCategory()) | ||
| .description(itemInfo.getDescription()) | ||
| .inventoryWidth(itemInfo.getInventoryWidth()) | ||
| .inventoryHeight(itemInfo.getInventoryHeight()) | ||
| .inventoryMaxBundleCount(itemInfo.getInventoryMaxBundleCount()) | ||
| .history(itemInfo.getHistory()) | ||
| .acquisitionMethod(itemInfo.getAcquisitionMethod()) | ||
| .storeSalesPrice(itemInfo.getStoreSalesPrice()) | ||
| .weaponType(itemInfo.getWeaponType()) | ||
| .repair(itemInfo.getRepair()) | ||
| .maxAlterationCount(itemInfo.getMaxAlterationCount()) | ||
| .build(); | ||
| } | ||
|
|
||
| public static List<ItemInfoResponse> from(List<ItemInfo> itemInfos) { | ||
| return itemInfos.stream().map(ItemInfoResponse::from).collect(Collectors.toList()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| CREATE TABLE item_info ( | ||
| name VARCHAR(255) NOT NULL PRIMARY KEY COMMENT '아이템의 이름', | ||
| sub_category VARCHAR(25) NOT NULL COMMENT '아이템 하위 카테고리', | ||
| top_category VARCHAR(25) NOT NULL COMMENT '아이템 상위 카테고리', | ||
| description VARCHAR(255) COMMENT '아이템의 설명', | ||
| inventory_width TINYINT COMMENT '인벤토리 가로 크기', | ||
| inventory_height TINYINT COMMENT '인벤토리 세로 크기', | ||
| inventory_max_bundle_count INT COMMENT '최대 번들 가능 개수', | ||
| history VARCHAR(3000) COMMENT '아이템의 역사', | ||
| acquisition_method VARCHAR(3000) COMMENT '입수 방법', | ||
| store_sales_price VARCHAR(3000) COMMENT '1개 상점 판매가', | ||
| weapon_type VARCHAR(25) COMMENT '공격 속도 및 무기 타입', | ||
| repair VARCHAR(25) COMMENT '수리', | ||
| max_alteration_count TINYINT COMMENT '최대 개조 횟수' | ||
|
|
||
| ) COMMENT='아이템 정보 테이블'; | ||
|
|
||
| -- 초기 데이터 적재 쿼리 | ||
| -- INSERT INTO item_info (name, top_category, sub_category) select distinct item_name, item_top_category, item_sub_category from auction_history; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.