-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
controller, entity, repository, service 작성완료 Add: README 파일 추가 프로젝트 개요 및 개발환경 Chore: 빌드 관련 의존성 추가 Lombok, Swagger, JPA
- Loading branch information
Showing
6 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,45 @@ | ||
# BE_Item_Server | ||
|
||
## 🌐 프로젝트 개요 | ||
|
||
해당 프로젝트는 DPANG 서비스의 상품 서버로서, 사용자의 상품, 상품 문의, 인기 상품과 관련한 서비스를 담당하고 있습니다. | ||
|
||
## 🛠️ 프로젝트 개발 환경 | ||
|
||
프로젝트는 아래 환경에서 개발되었습니다. | ||
|
||
> OS: MacOS Sonoma 14.2.1 | ||
> IDE: Intellij IDEA | ||
> Java 17 | ||
<!-- | ||
## ✅ 프로젝트 실행 | ||
해당 프로젝트를 추가로 개발 혹은 실행시켜보고 싶으신 경우 아래의 절차에 따라 진행해주세요 | ||
#### 1. `secret.yml` 생성 | ||
```commandline | ||
cd ./src/main/resources | ||
touch secret.yml | ||
``` | ||
#### 2. `secret.yml` 작성 | ||
```text | ||
``` | ||
#### 3. 프로젝트 실행 | ||
```commandline | ||
./gradlew bootrun | ||
``` | ||
**참고) 프로젝트가 실행 중인 환경에서 아래 URL을 통해 API 명세서를 확인할 수 있습니다** | ||
```commandline | ||
http://localhost:8080/swagger-ui/index.html | ||
``` | ||
--> |
This file contains 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
32 changes: 32 additions & 0 deletions
32
src/main/java/kea/dpang/item/controller/ItemController.java
This file contains 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,32 @@ | ||
package kea.dpang.item.controller; | ||
|
||
import kea.dpang.item.entity.Item; | ||
import kea.dpang.item.service.ItemService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.Map; | ||
|
||
@RestController | ||
@RequestMapping("/api/products") | ||
public class ItemController { | ||
|
||
private final ItemService itemService; | ||
|
||
@Autowired | ||
public ItemController(ItemService itemService) { | ||
this.itemService = itemService; | ||
} | ||
|
||
@GetMapping("/{itemId}") | ||
public ResponseEntity<?> getItemById(@PathVariable Long id) { | ||
return itemService.getItemById(id) | ||
.map(product -> ResponseEntity.ok().body(product)) | ||
.orElse(ResponseEntity.status(404).body((Item) Map.of( | ||
"status", 404, | ||
"message", "상품을 찾을 수 없습니다." | ||
))); | ||
} | ||
} | ||
|
This file contains 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,60 @@ | ||
package kea.dpang.item.entity; | ||
|
||
import jakarta.persistence.*; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "products") | ||
public class Item { | ||
// 상품 ID | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long itemId; | ||
|
||
// 상품명 | ||
@Column(nullable = false) | ||
private String itemName; | ||
|
||
// 상품 분류 카테고리 | ||
@Column(nullable = false) | ||
private String category; | ||
|
||
// 브랜드명 | ||
@Column(nullable = false) | ||
private String brand; | ||
|
||
// 상품 원가 | ||
@Column(nullable = false) | ||
private Double itemPrice; | ||
|
||
// 평점 | ||
private Double rating; | ||
|
||
// 리뷰 리스트 | ||
@ElementCollection | ||
private List<String> reviews; | ||
|
||
// 할인율 | ||
private Double discountRate; | ||
|
||
// 할인가 | ||
private Double discountPrice; | ||
|
||
// 상품 상세정보 | ||
@Column(length = 1000) | ||
private String description; | ||
|
||
// 상품 사진 | ||
private String itemImage; | ||
|
||
// 상품 썸네일 사진 | ||
private String thumbnailImage; | ||
|
||
// 위시리스트 | ||
private Boolean wishlistCheck; | ||
|
||
// 이미지 리스트 | ||
@ElementCollection | ||
private List<String> images; | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
src/main/java/kea/dpang/item/repository/ItemRepository.java
This file contains 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 kea.dpang.item.repository; | ||
|
||
import kea.dpang.item.entity.Item; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ItemRepository extends JpaRepository<Item, Long> { | ||
Optional<Item> findById(Long id); | ||
List<Item> findByItemNameContaining(String itemName); | ||
} | ||
|
This file contains 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,24 @@ | ||
package kea.dpang.item.service; | ||
|
||
import kea.dpang.item.entity.Item; | ||
import kea.dpang.item.repository.ItemRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class ItemService { | ||
|
||
private final ItemRepository itemRepository; | ||
|
||
@Autowired | ||
public ItemService(ItemRepository itemRepository) { | ||
this.itemRepository = itemRepository; | ||
} | ||
|
||
public Optional<Item> getItemById(Long id) { | ||
// 상품 ID로 상품을 조회합니다. | ||
return itemRepository.findById(id); | ||
} | ||
} | ||
|