Skip to content

Commit

Permalink
Feat: 객체지향 관련 package 추가
Browse files Browse the repository at this point in the history
controller, entity, repository, service 작성완료
Add: README 파일 추가
프로젝트 개요 및 개발환경
Chore: 빌드 관련 의존성 추가
Lombok, Swagger, JPA
  • Loading branch information
oo-ni committed Jan 11, 2024
1 parent 74df56b commit 972ba1d
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 2 deletions.
45 changes: 45 additions & 0 deletions README.md
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
```
-->
13 changes: 11 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ repositories {
}

dependencies {
// Spring
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-api:2.1.0'

}

tasks.named('test') {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/kea/dpang/item/controller/ItemController.java
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", "상품을 찾을 수 없습니다."
)));
}
}

60 changes: 60 additions & 0 deletions src/main/java/kea/dpang/item/entity/Item.java
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 src/main/java/kea/dpang/item/repository/ItemRepository.java
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);
}

24 changes: 24 additions & 0 deletions src/main/java/kea/dpang/item/service/ItemService.java
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);
}
}

0 comments on commit 972ba1d

Please sign in to comment.