Skip to content

Commit

Permalink
[OpenAPI] 사용자, 상품, 거래 객체 #10 (#15)
Browse files Browse the repository at this point in the history
* 주요사항
  * Users, Products, Transactions Entity/DTO 분리
  * 객체별 필수, Null여부, JoinColumn 설정
  * ERD 작성
* 관련사항
  * OpenAPI Schema 노출을 위한 dummy api 작성
  * UsersEntity 변경에 따른 기존 코드 수정
  • Loading branch information
tae0y authored Dec 12, 2024
1 parent 6485599 commit 6ce7779
Show file tree
Hide file tree
Showing 23 changed files with 1,063 additions and 206 deletions.
1 change: 1 addition & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
#- '.github/**'
- 'docker/**'
- '.*'
- 'docs/**'

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ rules:
- field: responses
function: truthy
message: Responses are required

# 응답 코드 규칙 : 200, 401, 500 응답 코드가 있어야 함
operation-responsecode-convention:
description: All Operation response should include 200, 401, 500
Expand Down
63 changes: 63 additions & 0 deletions docs/ObjectsERD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# ObjectsERD

> Written in Mermaid.js syntax
> https://mermaid.js.org/syntax/flowchart.html
- vscode에서 다음 확장프로그램을 설치
- Mermaid Markdown Syntax Highlighting : 마크다운 텍스트 문서에서 신택스 린팅
- Mermaid Graphical Editor : 마크다운 코드블럭을 mermaid로 지정하면 상단에 GUI 에디터로 이동할 수 있는 "MermaidEditor" 표시

## Users, Products, Transactions
```mermaid
erDiagram
USERS {
bigint id PK "사용자 ID"
varchar name "사용자 이름"
varchar introduction "사용자 소개글"
boolean isActive "사용자 활성화 여부"
varchar createProgramId "사용자 등록 프로그램 ID"
datetime createdDateTime "사용자 등록일시"
varchar modifyProgramId "사용자 수정 프로그램 ID"
datetime modifiedDateTime "사용자 수정일시"
varchar deleteProgramId "사용자 삭제 프로그램 ID"
datetime deletedDateTime "사용자 삭제일시"
}
PRODUCTS {
bigint id PK "상품 ID"
varchar name "상품 이름"
int price "상품 가격"
varchar category "상품 카테고리"
varchar description "상품 설명"
boolean isPrivate "상품 비공개 여부"
boolean isSoldOut "상품 판매 여부"
boolean isDeleted "상품 삭제 여부"
bigint createUserId FK "상품 등록 사용자 ID"
datetime createdDateTime "상품 등록일시"
bigint modifyUserId FK "상품 수정 사용자 ID"
datetime modifiedDateTime "상품 수정일시"
bigint deleteUserId FK "상품 삭제 사용자 ID"
datetime deletedDateTime "상품 삭제일시"
}
TRANSACTIONS {
bigint id PK "거래 ID"
bigint productId FK "거래 상품 ID"
bigint buyerId FK "구매자 ID"
bigint sellerId FK "판매자 ID"
datetime transactionDateTime "거래 완료 일시"
int transactionAmount "거래 금액"
boolean isOpen "거래 상태"
boolean isDeleted "거래 삭제 여부"
bigint createdUserId FK "거래 등록 사용자 ID"
datetime createdDateTime "거래 등록일시"
bigint modifiedUserId FK "거래 수정 사용자 ID"
datetime modifiedDateTime "거래 수정일시"
bigint deletedUserId FK "거래 삭제 사용자 ID"
datetime deletedDateTime "거래 삭제일시"
}
USERS ||--o{ PRODUCTS : "createUserId, modifyUserId, deleteUserId"
USERS ||--o{ TRANSACTIONS : "buyerId, sellerId, createdUserId, modifiedUserId, deletedUserId"
PRODUCTS ||--o{ TRANSACTIONS : "productId"
```
29 changes: 28 additions & 1 deletion src/main/java/com/karrot/domain/product/ProductController.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
package com.karrot.domain.product;

import org.hibernate.cfg.NotYetImplementedException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "Products", description = "상품 정보")
@RestController
@RequestMapping("/api/products")
public class ProductController {
}

/**
* <ul>
* <li>name : dummy
* <li>desc : OpenAPI 문서에 객체 표시되게 하기 위한 dummy API
* </ul>
* @param request
* @return
*/

@Operation(summary ="dummy", description = "products dummpy api!")
@PostMapping("/")
public ResponseEntity<ProductsResponseDTO> dummy(ProductsRequestDTO request) {
throw new NotYetImplementedException();
}
}
64 changes: 0 additions & 64 deletions src/main/java/com/karrot/domain/product/Products.java

This file was deleted.

145 changes: 145 additions & 0 deletions src/main/java/com/karrot/domain/product/ProductsEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.karrot.domain.product;

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PreRemove;
import javax.persistence.Table;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.lang.Nullable;

import com.karrot.domain.user.UsersEntity;
import lombok.Data;

@Entity
@Table(name="products")
@Data
public class ProductsEntity {
/**
* 상품 ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
@NotNull
private Long id;

/**
* 상품 이름
*/
@Column(nullable = false, length = 100)
@NotNull
@Size(max = 100)
private String name;

/**
* 상품 가격
*/
@Column(nullable = false)
@NotNull
@Min(0)
private Integer price;

/**
* 상품 카테고리
*/
@Column(nullable = true, length = 100)
@Nullable
@Size(max = 100)
private String category;

/**
* 상품 설명
*/
@Column(nullable = true, length = 1000)
@Nullable
@Size(max = 1000)
private String description;

/**
* 상품 비공개여부
*/
@Column(nullable = false)
@NotNull
private boolean isPrivate;

/**
* 상품 판매여부
*/
@Column(nullable = false)
@NotNull
private boolean isSoldOut;

/**
* 상품 삭제여부
*/
@Column(nullable = false)
@NotNull
private boolean isDeleted;

/**
* 상품을 등록한 사용자 정보
*/
@NotNull
@ManyToOne
@JoinColumn(name = "createUserId", nullable = false)
private UsersEntity createUser;

/**
* 상품 등록일시
*/
@Column(nullable = false)
@NotNull
@CreatedDate
private LocalDateTime createdDateTime;

/**
* 상품을 수정한 사용자 정보
*/
@Nullable
@ManyToOne
@JoinColumn(name = "modifyUserId", nullable = true)
private UsersEntity modifyUser;

/**
* 상품 수정일시
*/
@Column(nullable = true)
@Nullable
@LastModifiedDate
private LocalDateTime modifiedDateTime;

/**
* 상품을 삭제한 사용자 정보
*/
@Nullable
@ManyToOne
@JoinColumn(name = "deleteUserId", nullable = true)
private UsersEntity deleteUser;

/**
* 상품 삭제일시
*/
@Column(nullable = true)
@Nullable
private LocalDateTime deletedDateTime;

/**
* 삭제일시 자동 생성
*/
@PreRemove
public void preRemove() {
this.deletedDateTime = LocalDateTime.now();
}
}
Loading

0 comments on commit 6ce7779

Please sign in to comment.