From 6ce77797e9e8a253f9d17d1b5b26a9558ea0db75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=83=9C=EC=98=81?= Date: Thu, 12 Dec 2024 16:36:54 +0900 Subject: [PATCH] =?UTF-8?q?[OpenAPI]=20=EC=82=AC=EC=9A=A9=EC=9E=90,=20?= =?UTF-8?q?=EC=83=81=ED=92=88,=20=EA=B1=B0=EB=9E=98=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=20#10=20(#15)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 주요사항 * Users, Products, Transactions Entity/DTO 분리 * 객체별 필수, Null여부, JoinColumn 설정 * ERD 작성 * 관련사항 * OpenAPI Schema 노출을 위한 dummy api 작성 * UsersEntity 변경에 따른 기존 코드 수정 --- .github/workflows/maven.yml | 1 + .spectral.yaml | 2 +- docs/ObjectsERD.md | 63 ++++++++ .../domain/product/ProductController.java | 29 +++- .../com/karrot/domain/product/Products.java | 64 -------- .../karrot/domain/product/ProductsEntity.java | 145 +++++++++++++++++ .../domain/product/ProductsRequestDTO.java | 88 +++++++++++ .../domain/product/ProductsResponseDTO.java | 89 +++++++++++ .../transaction/TransactionController.java | 27 ++++ .../domain/transaction/Transactions.java | 66 -------- .../transaction/TransactionsEntity.java | 147 ++++++++++++++++++ .../transaction/TransactionsRequestDTO.java | 98 ++++++++++++ .../transaction/TransactionsResponseDTO.java | 103 ++++++++++++ .../karrot/domain/user/UserController.java | 34 ++-- .../karrot/domain/user/UserRepository.java | 8 +- .../com/karrot/domain/user/UserService.java | 8 +- .../karrot/domain/user/UserServiceImpl.java | 8 +- .../java/com/karrot/domain/user/Users.java | 40 ----- .../com/karrot/domain/user/UsersEntity.java | 114 ++++++++++++++ .../karrot/domain/user/UsersRequestDTO.java | 54 +++++++ .../karrot/domain/user/UsersResponseDTO.java | 70 +++++++++ src/main/resources/application-local.yml | 3 +- .../domain/user/UserControllerTest.java | 8 +- 23 files changed, 1063 insertions(+), 206 deletions(-) create mode 100644 docs/ObjectsERD.md delete mode 100644 src/main/java/com/karrot/domain/product/Products.java create mode 100644 src/main/java/com/karrot/domain/product/ProductsEntity.java create mode 100644 src/main/java/com/karrot/domain/product/ProductsRequestDTO.java create mode 100644 src/main/java/com/karrot/domain/product/ProductsResponseDTO.java delete mode 100644 src/main/java/com/karrot/domain/transaction/Transactions.java create mode 100644 src/main/java/com/karrot/domain/transaction/TransactionsEntity.java create mode 100644 src/main/java/com/karrot/domain/transaction/TransactionsRequestDTO.java create mode 100644 src/main/java/com/karrot/domain/transaction/TransactionsResponseDTO.java delete mode 100644 src/main/java/com/karrot/domain/user/Users.java create mode 100644 src/main/java/com/karrot/domain/user/UsersEntity.java create mode 100644 src/main/java/com/karrot/domain/user/UsersRequestDTO.java create mode 100644 src/main/java/com/karrot/domain/user/UsersResponseDTO.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0cadbad..8d7bc39 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -18,6 +18,7 @@ on: #- '.github/**' - 'docker/**' - '.*' + - 'docs/**' jobs: build: diff --git a/.spectral.yaml b/.spectral.yaml index dd6c5ad..bd1a7cd 100644 --- a/.spectral.yaml +++ b/.spectral.yaml @@ -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 diff --git a/docs/ObjectsERD.md b/docs/ObjectsERD.md new file mode 100644 index 0000000..0d816d0 --- /dev/null +++ b/docs/ObjectsERD.md @@ -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" +``` \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/product/ProductController.java b/src/main/java/com/karrot/domain/product/ProductController.java index 6bb75e5..554cccf 100644 --- a/src/main/java/com/karrot/domain/product/ProductController.java +++ b/src/main/java/com/karrot/domain/product/ProductController.java @@ -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 { -} + + /** + * + * @param request + * @return + */ + + @Operation(summary ="dummy", description = "products dummpy api!") + @PostMapping("/") + public ResponseEntity dummy(ProductsRequestDTO request) { + throw new NotYetImplementedException(); + } +} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/product/Products.java b/src/main/java/com/karrot/domain/product/Products.java deleted file mode 100644 index 86bb64b..0000000 --- a/src/main/java/com/karrot/domain/product/Products.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.karrot.domain.product; - -import java.time.LocalDateTime; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import com.karrot.domain.user.Users; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Entity -@Table(name="products") -@Data -@Schema(name = "Product", description = "상품 정보") -public class Products { - @Id - @Schema(name = "id", description = "상품 ID") - private Long id; - - @Schema(name = "name", description = "상품 이름") - private String name; - - @Schema(name = "price", description = "상품 가격") - private int price; - - @Schema(name = "category", description = "상품 카테고리") - private String category; - - @Schema(name = "description", description = "상품 설명") - private int description; - - @Schema(name = "isPrivate", description = "상품 비공개여부") - private boolean isPrivate; - - @Schema(name = "isSoldOut", description = "상품 판매여부") - private boolean isSoldOut; - - @Schema(name = "isDeleted", description = "상품 삭제여부") - private boolean isDeleted; - - @ManyToOne - @Schema(name = "createUser", description = "상품을 등록한 사용자 정보") - private Users createUser; - - @Schema(name = "createdDateTime", description = "상품 등록일시") - private LocalDateTime createdDateTime; - - @ManyToOne - @Schema(name = "modifyUser", description = "상품을 수정한 사용자 정보") - private Users modifyUser; - - @Schema(name = "modifiedDateTime", description = "상품 수정일시") - private LocalDateTime modifiedDateTime; - - @ManyToOne - @Schema(name = "deleteUser", description = "상품을 삭제한 사용자 정보") - private Users deleteUser; - - @Schema(name = "deletedDateTime", description = "상품 삭제일시") - private LocalDateTime deletedDateTime; -} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/product/ProductsEntity.java b/src/main/java/com/karrot/domain/product/ProductsEntity.java new file mode 100644 index 0000000..32d2b46 --- /dev/null +++ b/src/main/java/com/karrot/domain/product/ProductsEntity.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/product/ProductsRequestDTO.java b/src/main/java/com/karrot/domain/product/ProductsRequestDTO.java new file mode 100644 index 0000000..762c1af --- /dev/null +++ b/src/main/java/com/karrot/domain/product/ProductsRequestDTO.java @@ -0,0 +1,88 @@ +package com.karrot.domain.product; + +import javax.persistence.ManyToOne; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +import org.springframework.lang.Nullable; + +import com.karrot.domain.user.UsersEntity; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(name = "Product", description = "상품 정보") +public class ProductsRequestDTO { + /** + * 상품 이름 + */ + @Schema(name = "name", description = "상품 이름", required = true, nullable = false, example = "Apple", maxLength = 100) + @NotNull + @Size(max = 100) + private String name; + + /** + * 상품 가격 + */ + @Schema(name = "price", description = "상품 가격", required = true, nullable = false, example = "1000", minimum = "0") + @NotNull + @Min(0) + private int price; + + /** + * 상품 카테고리 + */ + @Schema(name = "category", description = "상품 카테고리", required = false, nullable = true, example = "Fruit", maxLength = 100) + @Size(max = 100) + private String category; + + /** + * 상품 설명 + */ + @Schema(name = "description", description = "상품 설명", required = false, nullable = true, example = "This is an apple.", maxLength = 1000) + @Size(max = 1000) + private String description; + + /** + * 상품 비공개여부 + */ + @Schema(name = "isPrivate", description = "상품 비공개여부", required = true, nullable = false, example = "false") + @NotNull + private boolean isPrivate; + + /** + * 상품 판매여부 + */ + @Schema(name = "isSoldOut", description = "상품 판매여부", required = true, nullable = false, example = "false") + @NotNull + private boolean isSoldOut; + + /** + * 상품 삭제여부 + */ + @Schema(name = "isDeleted", description = "상품 삭제여부", required = true, nullable = false, example = "false") + @NotNull + private boolean isDeleted; + + /** + * 상품을 등록한 사용자 정보 + */ + @Schema(name = "createUser", description = "상품을 등록한 사용자 정보", required = true, nullable = false) + @NotNull + private UsersEntity createUser; + + /** + * 상품을 수정한 사용자 정보 + */ + @Schema(name = "modifyUser", description = "상품을 수정한 사용자 정보", required = false, nullable = true) + @Nullable + private UsersEntity modifyUser; + + /** + * 상품을 삭제한 사용자 정보 + */ + @Schema(name = "deleteUser", description = "상품을 삭제한 사용자 정보", required = false, nullable = true) + @Nullable + private UsersEntity deleteUser; +} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/product/ProductsResponseDTO.java b/src/main/java/com/karrot/domain/product/ProductsResponseDTO.java new file mode 100644 index 0000000..ba8eb13 --- /dev/null +++ b/src/main/java/com/karrot/domain/product/ProductsResponseDTO.java @@ -0,0 +1,89 @@ +package com.karrot.domain.product; + +import java.time.LocalDateTime; + +import com.karrot.domain.user.UsersEntity; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(name = "Product", description = "상품 정보") +public class ProductsResponseDTO { + /** + * 상품 ID + */ + @Schema(name = "name", description = "상품 이름", required = true, nullable = false, example = "Apple", maxLength = 100) + private String name; + + /** + * 상품 가격 + */ + @Schema(name = "price", description = "상품 가격", required = true, nullable = false, example = "1000", minimum = "0") + private int price; + + /** + * 상품 카테고리 + */ + @Schema(name = "category", description = "상품 카테고리", required = false, nullable = true, example = "Fruit", maxLength = 100) + private String category; + + /** + * 상품 설명 + */ + @Schema(name = "description", description = "상품 설명", required = false, nullable = true, example = "This is an apple.", maxLength = 1000) + private String description; + + /** + * 상품 비공개여부 + */ + @Schema(name = "isPrivate", description = "상품 비공개여부", required = true, nullable = false, example = "false") + private boolean isPrivate; + + /** + * 상품 판매여부 + */ + @Schema(name = "isSoldOut", description = "상품 판매여부", required = true, nullable = false, example = "false") + private boolean isSoldOut; + + /** + * 상품 삭제여부 + */ + @Schema(name = "isDeleted", description = "상품 삭제여부", required = true, nullable = false, example = "false") + private boolean isDeleted; + + /** + * 상품을 등록한 사용자 정보 + */ + @Schema(name = "createUser", description = "상품을 등록한 사용자 정보", required = true, nullable = false) + private UsersEntity createUser; + + /** + * 상품 등록일시 + */ + @Schema(name = "createdDateTime", description = "상품 등록일시") + private LocalDateTime createdDateTime; + + /** + * 상품을 수정한 사용자 정보 + */ + @Schema(name = "modifyUser", description = "상품을 수정한 사용자 정보", required = false, nullable = true) + private UsersEntity modifyUser; + + /** + * 상품 수정일시 + */ + @Schema(name = "modifiedDateTime", description = "상품 수정일시") + private LocalDateTime modifiedDateTime; + + /** + * 상품을 삭제한 사용자 정보 + */ + @Schema(name = "deleteUser", description = "상품을 삭제한 사용자 정보", required = false, nullable = true) + private UsersEntity deleteUser; + + /** + * 상품 삭제일시 + */ + @Schema(name = "deletedDateTime", description = "상품 삭제일시") + private LocalDateTime deletedDateTime; +} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/transaction/TransactionController.java b/src/main/java/com/karrot/domain/transaction/TransactionController.java index 7f93b9c..6a879df 100644 --- a/src/main/java/com/karrot/domain/transaction/TransactionController.java +++ b/src/main/java/com/karrot/domain/transaction/TransactionController.java @@ -1,5 +1,32 @@ package com.karrot.domain.transaction; +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 = "Transactions", description = "거래 정보") +@RestController +@RequestMapping("/api/transactions") public class TransactionController { + /** + * + * @param request + * @return + */ + + @Operation(summary ="dummy", description = "transactions dummpy api!") + @PostMapping("/") + public ResponseEntity dummy(TransactionsRequestDTO request) { + throw new NotYetImplementedException(); + } + } diff --git a/src/main/java/com/karrot/domain/transaction/Transactions.java b/src/main/java/com/karrot/domain/transaction/Transactions.java deleted file mode 100644 index f4766d9..0000000 --- a/src/main/java/com/karrot/domain/transaction/Transactions.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.karrot.domain.transaction; - -import java.time.LocalDateTime; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import com.karrot.domain.user.Users; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Entity -@Table(name = "transactions") -@Data -@Schema(name = "Transaction", description = "거래 정보") -public class Transactions { - @Id - @Schema(name = "id", description = "거래 ID") - private Long id; - - @Schema(name = "productId", description = "상품 ID") - private Long productId; - - @Schema(name = "buyerId", description = "구매자 ID") - private Long buyerId; - - @Schema(name = "sellerId", description = "판매자 ID") - private Long sellerId; - - @Schema(name = "transactionDateTime", description = "거래 일시") - private String transactionDateTime; - - @Schema(name = "transactionAmount", description = "거래 금액") - private int transactionAmount; - - @Schema(name = "transactionStatus", description = "거래 상태") - private String transactionStatus; - - @Schema(name = "isDeleted", description = "거래 삭제여부") - private boolean isDeleted; - - //TODO: createdUserId인지, createUsers로 할지 고민 필요 - @ManyToOne - @Schema(name = "createUser", description = "상품을 등록한 사용자 정보") - private Users createUser; - - @Schema(name = "createdDateTime", description = "상품 등록일시") - private LocalDateTime createdDateTime; - - @ManyToOne - @Schema(name = "modifyUser", description = "상품을 수정한 사용자 정보") - private Users modifyUser; - - @Schema(name = "modifiedDateTime", description = "상품 수정일시") - private LocalDateTime modifiedDateTime; - - @ManyToOne - @Schema(name = "deleteUser", description = "상품을 삭제한 사용자 정보") - private Users deleteUser; - - @Schema(name = "deletedDateTime", description = "상품 삭제일시") - private LocalDateTime deletedDateTime; -} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/transaction/TransactionsEntity.java b/src/main/java/com/karrot/domain/transaction/TransactionsEntity.java new file mode 100644 index 0000000..d126852 --- /dev/null +++ b/src/main/java/com/karrot/domain/transaction/TransactionsEntity.java @@ -0,0 +1,147 @@ +package com.karrot.domain.transaction; + +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 org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.lang.Nullable; + +import com.karrot.domain.product.ProductsEntity; +import com.karrot.domain.user.UsersEntity; + +import lombok.Data; + +@Entity +@Table(name = "transactions") +@Data +public class TransactionsEntity { + /** + * 거래 ID + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false) + @NotNull + private Long id; + + /** + * 거래할 상품 + */ + @ManyToOne + @NotNull + @JoinColumn(name = "productId", nullable = false) + private ProductsEntity product; + + /** + * 구매자 + */ + @ManyToOne + @NotNull + @JoinColumn(name = "buyerId", nullable = false) + private UsersEntity buyer; + + /** + * 판매자 + */ + @ManyToOne + @NotNull + @JoinColumn(name = "sellerId", nullable = false) + private UsersEntity seller; + + /** + * 거래 완료 일시 + */ + @Column(nullable = true) + @Nullable + private LocalDateTime transactionDateTime; + + /** + * 거래 금액 + */ + @Column(nullable = true) + @Nullable + @Min(0) + private Integer transactionAmount; + + /** + * 거래 상태 + */ + @Column(nullable = false) + @NotNull + private Boolean isOpen; + + /** + * 거래 삭제여부 + */ + @Column(nullable = false) + @NotNull + private Boolean isDeleted; + + /** + * 거래 등록자 + */ + //TODO: createdUserId인지, createUsers로 할지 고민 필요 + @NotNull + @ManyToOne + @JoinColumn(name = "createdUserId", nullable = false) + private UsersEntity createUser; + + /** + * 거래 등록일시 + */ + @Column(nullable = false) + @NotNull + @CreatedDate + private LocalDateTime createdDateTime; + + /** + * 거래 수정자 + */ + @ManyToOne + @Nullable + @JoinColumn(name = "modifiedUserId", nullable = true) + private UsersEntity modifyUser; + + /** + * 거래 수정일시 + */ + @Column(nullable = true) + @Nullable + @LastModifiedDate + private LocalDateTime modifiedDateTime; + + /** + * 거래 삭제자 + */ + @ManyToOne + @Nullable + @JoinColumn(name = "deletedUserId", nullable = true) + private UsersEntity deleteUser; + + /** + * 거래 삭제일시 + */ + @Column(nullable = true) + @Nullable + private LocalDateTime deletedDateTime; + + /** + * 삭제일시 자동 생성 + */ + @PreRemove + public void preRemove() { + this.deletedDateTime = LocalDateTime.now(); + } +} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/transaction/TransactionsRequestDTO.java b/src/main/java/com/karrot/domain/transaction/TransactionsRequestDTO.java new file mode 100644 index 0000000..a7122b4 --- /dev/null +++ b/src/main/java/com/karrot/domain/transaction/TransactionsRequestDTO.java @@ -0,0 +1,98 @@ +package com.karrot.domain.transaction; + +import java.time.LocalDateTime; + +import javax.persistence.ManyToOne; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +import org.springframework.lang.Nullable; + +import com.karrot.domain.product.ProductsEntity; +import com.karrot.domain.user.UsersEntity; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class TransactionsRequestDTO { + /** + * 거래 ID + */ + @NotNull + @Schema(name = "id", description = "거래 ID", required = true, nullable = false, example = "1") + private Long id; + + /** + * 거래할 상품 + */ + @NotNull + @Schema(name = "product", description = "거래할 상품", required = true, nullable = false) + private ProductsEntity product; + + /** + * 구매자 + */ + @NotNull + @Schema(name = "buyer", description = "구매자", required = true, nullable = false) + private UsersEntity buyer; + + /** + * 판매자 + */ + @NotNull + @Schema(name = "seller", description = "판매자", required = true, nullable = false) + private UsersEntity seller; + + /** + * 거래 완료 일시 + */ + @Nullable + @Schema(name = "transactionDateTime", description = "거래 일시", required = false, nullable = true, example = "2023-01-01T12:00:00") + private LocalDateTime transactionDateTime; + + /** + * 거래 금액 + */ + @Nullable + @Min(0) + @Schema(name = "transactionAmount", description = "거래 금액", required = false, nullable = true, example = "10000") + private Integer transactionAmount; + + /** + * 거래 상태 + */ + @NotNull + @Schema(name = "isOpen", description = "거래 상태", required = true, nullable = false, example = "true") + private String isOpen; + + /** + * 거래 삭제여부 + */ + @NotNull + @Schema(name = "isDeleted", description = "거래 삭제여부", required = true, nullable = false, example = "false") + private Boolean isDeleted; + + /** + * 거래 등록자 + */ + //TODO: createdUserId인지, createUsers로 할지 고민 필요 + @NotNull + @ManyToOne + @Schema(name = "createUser", description = "거래 등록자", required = true, nullable = false) + private UsersEntity createUser; + + /** + * 거래 수정자 + */ + @Nullable + @Schema(name = "modifyUser", description = "거래 수정자", required = false, nullable = true) + private UsersEntity modifyUser; + + /** + * 거래 삭제자 + */ + @Nullable + @Schema(name = "deleteUser", description = "거래 삭제자", required = false, nullable = true) + private UsersEntity deleteUser; +} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/transaction/TransactionsResponseDTO.java b/src/main/java/com/karrot/domain/transaction/TransactionsResponseDTO.java new file mode 100644 index 0000000..e2bd663 --- /dev/null +++ b/src/main/java/com/karrot/domain/transaction/TransactionsResponseDTO.java @@ -0,0 +1,103 @@ +package com.karrot.domain.transaction; + +import java.time.LocalDateTime; + +import javax.persistence.ManyToOne; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +import org.springframework.lang.Nullable; + +import com.karrot.domain.product.ProductsEntity; +import com.karrot.domain.user.UsersEntity; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class TransactionsResponseDTO { + /** + * 거래 ID + */ + @Schema(name = "id", description = "거래 ID", required = true, nullable = false, example = "1") + private Long id; + + /** + * 거래할 상품 + */ + @Schema(name = "product", description = "거래할 상품", required = true, nullable = false) + private ProductsEntity product; + + /** + * 구매자 + */ + @Schema(name = "buyer", description = "구매자", required = true, nullable = false) + private UsersEntity buyer; + + /** + * 판매자 + */ + @Schema(name = "seller", description = "판매자", required = true, nullable = false) + private UsersEntity seller; + + /** + * 거래 완료 일시 + */ + @Schema(name = "transactionDateTime", description = "거래 일시", required = false, nullable = true, example = "2023-01-01T12:00:00") + private LocalDateTime transactionDateTime; + + /** + * 거래 금액 + */ + @Schema(name = "transactionAmount", description = "거래 금액", required = false, nullable = true, example = "10000") + private Integer transactionAmount; + + /** + * 거래 상태 + */ + @Schema(name = "isOpen", description = "거래 상태", required = true, nullable = false, example = "true") + private String isOpen; + + /** + * 거래 삭제여부 + */ + @Schema(name = "isDeleted", description = "거래 삭제여부", required = true, nullable = false, example = "false") + private Boolean isDeleted; + + /** + * 거래 등록자 + */ + //TODO: createdUserId인지, createUsers로 할지 고민 필요 + @Schema(name = "createUser", description = "거래 등록자", required = true, nullable = false) + private UsersEntity createUser; + + /** + * 거래 등록일시 + */ + @Schema(name = "createdDateTime", description = "거래 등록일시", required = true, nullable = false, example = "2023-01-01T12:00:00") + private LocalDateTime createdDateTime; + + /** + * 거래 수정자 + */ + @Schema(name = "modifyUser", description = "거래 수정자", required = false, nullable = true) + private UsersEntity modifyUser; + + /** + * 거래 수정일시 + */ + @Schema(name = "modifiedDateTime", description = "거래 수정일시", required = false, nullable = true, example = "2023-01-02T12:00:00") + private LocalDateTime modifiedDateTime; + + /** + * 거래 삭제자 + */ + @Schema(name = "deleteUser", description = "거래 삭제자", required = false, nullable = true) + private UsersEntity deleteUser; + + /** + * 거래 삭제일시 + */ + @Schema(name = "deletedDateTime", description = "거래 삭제일시", required = false, nullable = true, example = "2023-01-03T12:00:00") + private LocalDateTime deletedDateTime; +} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/user/UserController.java b/src/main/java/com/karrot/domain/user/UserController.java index 5259a91..7149db2 100644 --- a/src/main/java/com/karrot/domain/user/UserController.java +++ b/src/main/java/com/karrot/domain/user/UserController.java @@ -22,7 +22,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; -@Tag(name = "User", description = "사용자 정보") +@Tag(name = "Users", description = "사용자 정보") @RestController @RequestMapping("/api/users") public class UserController { @@ -34,22 +34,22 @@ public class UserController { *
  • name : createUser *
  • desc : 사용자를 생성한다. * - * @param Users user - * @return ResponseEntity + * @param UsersResponseDTO user + * @return ResponseEntity */ @Operation(summary ="Create User", description = "Create User!") @PostMapping("/") @ApiResponses( value = { //TODO : [개선] 응답코드에 따라 객체 언마샬 로직이 분기를 타야함. responseCode, responseMessage, responseSchema를 포함한 객체를 반환하도록 수정 - @ApiResponse(responseCode = "201", description = "Create User Succeess", content = @Content(examples={}, schema = @Schema(implementation = Users.class))), + @ApiResponse(responseCode = "201", description = "Create User Succeess", content = @Content(examples={}, schema = @Schema(implementation = UsersResponseDTO.class))), @ApiResponse(responseCode = "400", description = "Invalid input", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Invalid input")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "403", description = "Forbidden", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Forbidden")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "409", description = "User already exists", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="User Already exists")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "503", description = "Internal server error", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Internal server error")}, schema = @Schema(implementation = String.class))) } ) - public ResponseEntity createUser(@RequestBody Users user) { + public ResponseEntity createUser(@RequestBody UsersResponseDTO user) { throw new NotYetImplementedException(); //HttpStatus status = HttpStatus.CREATED; //User saved = userService.save(user); @@ -62,18 +62,18 @@ public ResponseEntity createUser(@RequestBody Users user) { *
  • desc : 모든 사용자 정보를 조회한다. * * @param - * @return List + * @return List */ @Operation(summary ="Get User", description = "Return all Users") @GetMapping("/") @ApiResponses( value = { - @ApiResponse(responseCode = "200", description = "Get User Success", content = @Content(schema = @Schema(implementation = Users.class))), + @ApiResponse(responseCode = "200", description = "Get User Success", content = @Content(schema = @Schema(implementation = UsersResponseDTO.class))), @ApiResponse(responseCode = "403", description = "Forbidden", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Forbidden")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "503", description = "Internal server error", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Internal server error")}, schema = @Schema(implementation = String.class))) } ) - public List getAllUsers() { + public List getAllUsers() { throw new NotYetImplementedException(); //return userService.getAllUsers(); } @@ -84,14 +84,14 @@ public List getAllUsers() { *
  • desc : 특정 사용자 정보를 조회한다. * * @param Long id - * @return ResponseEntity + * @return ResponseEntity */ @Operation(summary ="Get User", description = "Return User by ID") @Parameter(name = "id", description = "사용자 ID", required = true) @GetMapping("/{id}") @ApiResponses( value = { - @ApiResponse(responseCode = "200", description = "Get User Success", content = @Content(schema = @Schema(implementation = Users.class))), + @ApiResponse(responseCode = "200", description = "Get User Success", content = @Content(schema = @Schema(implementation = UsersResponseDTO.class))), @ApiResponse(responseCode = "400", description = "Invalid input", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Invalid input")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "403", description = "Forbidden", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Forbidden")}, schema = @Schema(implementation = String.class))), //TODO : [개선] user not found로 사용자 존재여부를 추정할 수 있음, 보안을 위해 제거하는게 좋을까? @@ -99,7 +99,7 @@ public List getAllUsers() { @ApiResponse(responseCode = "503", description = "Internal server error", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Internal server error")}, schema = @Schema(implementation = String.class))) } ) - public ResponseEntity getUser(@PathVariable Long id) { + public ResponseEntity getUser(@PathVariable Long id) { throw new NotYetImplementedException(); //return userService.getUser(id) // .map(user -> new ResponseEntity<>(user, HttpStatus.OK)) @@ -111,22 +111,22 @@ public ResponseEntity getUser(@PathVariable Long id) { *
  • name : updateUser *
  • desc : 사용자 정보를 변경한다. * - * @param Long id, Users user - * @return ResponseEntity + * @param Long id, UsersRequestDTO user + * @return UsersResponseDTO */ @Operation(summary ="Put User", description = "Update User by ID") @Parameter(name = "id", description = "사용자 ID", required = true) @PutMapping("/{id}") @ApiResponses( value = { - @ApiResponse(responseCode = "200", description = "Update User Success", content = @Content(schema = @Schema(implementation = Users.class))), + @ApiResponse(responseCode = "200", description = "Update User Success", content = @Content(schema = @Schema(implementation = UsersResponseDTO.class))), @ApiResponse(responseCode = "400", description = "Invalid input", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Invalid input")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "403", description = "Forbidden", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Forbidden")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "404", description = "User not found", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="User not found")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "503", description = "Internal server error", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Internal server error")}, schema = @Schema(implementation = String.class))) } ) - public ResponseEntity updateUser(@PathVariable Long id, @RequestBody Users user) { + public ResponseEntity updateUser(@PathVariable Long id, @RequestBody UsersRequestDTO user) { throw new NotYetImplementedException(); //return userService.getUser(id) // .map(existingUser -> { @@ -150,14 +150,14 @@ public ResponseEntity updateUser(@PathVariable Long id, @RequestBody User @DeleteMapping("/{id}") @ApiResponses( value = { - @ApiResponse(responseCode = "200", description = "Update User Success", content = @Content(schema = @Schema(implementation = Users.class))), + @ApiResponse(responseCode = "200", description = "Delete User Success", content = @Content(examples={@ExampleObject(name="", summary="", description="", value="Delete User Success")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "400", description = "Invalid input", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Invalid input")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "403", description = "Forbidden", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Forbidden")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "404", description = "User not found", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="User not found")}, schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "503", description = "Internal server error", content= @Content(examples={@ExampleObject(name="", summary="", description="", value="Internal server error")}, schema = @Schema(implementation = String.class))) } ) - public ResponseEntity deleteUser(@PathVariable Long id) { + public ResponseEntity deleteUser(@PathVariable Long id) { throw new NotYetImplementedException(); //return userService.getUser(id) // .map(user -> { diff --git a/src/main/java/com/karrot/domain/user/UserRepository.java b/src/main/java/com/karrot/domain/user/UserRepository.java index dc9f64f..e87f2e6 100644 --- a/src/main/java/com/karrot/domain/user/UserRepository.java +++ b/src/main/java/com/karrot/domain/user/UserRepository.java @@ -9,14 +9,14 @@ @Repository @Transactional -public interface UserRepository extends JpaRepository { +public interface UserRepository extends JpaRepository { //TODO: JPA 이름규칙에 맞춰 수정하기 - public Users save(Users user); + public UsersEntity save(UsersEntity user); - public List findAll(); + public List findAll(); - public Optional findById(Long id); + public Optional findById(Long id); //public Users updateById(Long id, Users user); diff --git a/src/main/java/com/karrot/domain/user/UserService.java b/src/main/java/com/karrot/domain/user/UserService.java index 375969c..3d19628 100644 --- a/src/main/java/com/karrot/domain/user/UserService.java +++ b/src/main/java/com/karrot/domain/user/UserService.java @@ -4,13 +4,13 @@ public interface UserService { - public Users createUser(Users user); + public UsersResponseDTO createUser(UsersRequestDTO user); - public List getAllUsers(); + public List getAllUsers(); - public Users getUser(Long id); + public UsersResponseDTO getUser(Long id); - public Users updateUser(Long id, Users user); + public UsersResponseDTO updateUser(Long id, UsersRequestDTO user); public void deleteUser(Long id); } diff --git a/src/main/java/com/karrot/domain/user/UserServiceImpl.java b/src/main/java/com/karrot/domain/user/UserServiceImpl.java index 8cb906f..40c7f5d 100644 --- a/src/main/java/com/karrot/domain/user/UserServiceImpl.java +++ b/src/main/java/com/karrot/domain/user/UserServiceImpl.java @@ -16,25 +16,25 @@ public class UserServiceImpl implements UserService { private UserRepository userRepository; @Override - public Users createUser(Users user) + public UsersResponseDTO createUser(UsersRequestDTO user) { throw new NotYetImplementedException(); } @Override - public List getAllUsers() + public List getAllUsers() { throw new NotYetImplementedException(); } @Override - public Users getUser(Long id) + public UsersResponseDTO getUser(Long id) { throw new NotYetImplementedException(); } @Override - public Users updateUser(Long id, Users user) + public UsersResponseDTO updateUser(Long id, UsersRequestDTO user) { throw new NotYetImplementedException(); } diff --git a/src/main/java/com/karrot/domain/user/Users.java b/src/main/java/com/karrot/domain/user/Users.java deleted file mode 100644 index cbd0e44..0000000 --- a/src/main/java/com/karrot/domain/user/Users.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.karrot.domain.user; - -import java.time.LocalDateTime; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Entity -@Table(name="users") -@Data -@Schema(name = "User", description = "사용자 정보") -public class Users { - @Id - @Schema(name = "id", description = "사용자 ID") - private Long id; - @Schema(name = "name", description = "사용자 이름") - private String name; - @Schema(name = "introduction", description = "사용자 소개글") - private String introduction; - - @Schema(name = "isActive", description = "사용자 활성화여부") - private boolean isActive; - - @Schema(name = "createProgramId", description = "사용자 등록 프로그램 Id(자체 회원가입, OAuth 등)") - private String createProgramId; - @Schema(name = "createdDateTime", description = "상품 등록일시") - private LocalDateTime createdDateTime; - @Schema(name = "modifyProgramId", description = "사용자 수정 프로그램 Id(자체 프로필수정, 데이터연동 등)") - private String modifyProgramId; - @Schema(name = "modifiedDateTime", description = "상품 수정일시") - private LocalDateTime modifiedDateTime; - @Schema(name = "deleteProgramId", description = "사용자 삭제 프로그램 Id(자체 회원탈퇴, 관리자 삭제, 개인정보 보존만료 등)") - private String deleteProgramId; - @Schema(name = "deletedDateTime", description = "상품 삭제일시") - private LocalDateTime deletedDateTime; -} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/user/UsersEntity.java b/src/main/java/com/karrot/domain/user/UsersEntity.java new file mode 100644 index 0000000..89ee30c --- /dev/null +++ b/src/main/java/com/karrot/domain/user/UsersEntity.java @@ -0,0 +1,114 @@ +package com.karrot.domain.user; + +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.PreRemove; +import javax.persistence.Table; +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 lombok.Data; + +@Entity +@Table(name="users") +@Data +public class UsersEntity { + /** + * 사용자 ID + */ + @Id + //TODO : [개선] H2, PostgreSQL 등 각 DB에 맞는 ID 생성 전략을 수립하여야함 + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false) + @NotNull + private Long id; + + /** + * 사용자 이름 + */ + @Column(nullable = false, length = 10) + @NotNull + @Size(max = 10) + private String name; + + /** + * 사용자 소개글 + */ + @Column(nullable = true, length = 255) + @Nullable + @Size(max = 255) + private String introduction; + + /** + * 사용자 활성화여부 + */ + @Column(nullable = false) + @NotNull + private boolean isActive; + + /** + * 사용자 등록 프로그램 Id(자체 회원가입, OAuth 등) + */ + @Column(nullable = false, length = 20) + @NotNull + @Size(max = 20) + //@CreatedBy TODO: [개선] JPA Auditing을 사용하여 사용자 ID를 자동으로 생성하도록 수정, 그럼 시스템단의 변경은? + private String createProgramId; + + /** + * 사용자 등록일시 + */ + @Column(nullable = false) + @NotNull + @CreatedDate + private LocalDateTime createdDateTime; + + /** + * 사용자 수정 프로그램 Id(자체 프로필수정, 데이터연동 등) + */ + @Column(nullable = true, length = 20) + @Nullable + @Size(max = 20) + //@LastModifiedBy TODO: [개선] JPA Auditing을 사용하여 사용자 ID를 자동으로 생성하도록 수정, 그럼 시스템단의 변경은? + private String modifyProgramId; + + /** + * 사용자 수정일시 + */ + @Column(nullable = true) + @Nullable + @LastModifiedDate + private LocalDateTime modifiedDateTime; + + /** + * 사용자 삭제 프로그램 Id(자체 회원탈퇴, 관리자 삭제, 개인정보 보존만료 등) + */ + @Column(nullable = true, length = 20) + @Nullable + @Size(max = 20) + private String deleteProgramId; + + /** + * 사용자 삭제일시 + */ + @Column(nullable = true) + @Nullable + private LocalDateTime deletedDateTime; + + /** + * 삭제일시 자동 생성 + */ + @PreRemove + public void preRemove() { + this.deletedDateTime = LocalDateTime.now(); + } +} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/user/UsersRequestDTO.java b/src/main/java/com/karrot/domain/user/UsersRequestDTO.java new file mode 100644 index 0000000..e5ec63d --- /dev/null +++ b/src/main/java/com/karrot/domain/user/UsersRequestDTO.java @@ -0,0 +1,54 @@ +package com.karrot.domain.user; + +import javax.validation.constraints.Size; + +import org.springframework.lang.Nullable; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(name = "User", description = "사용자 정보") +public class UsersRequestDTO { + /** + * 사용자 이름 + */ + @Schema(name = "name", description = "사용자 이름", required = false, nullable = false, example = "John Doe", maxLength = 10) + @Size(max = 10) + private String name; + + /** + * 사용자 소개글 + */ + @Schema(name = "introduction", description = "사용자 소개글", required = false, nullable = true, example = "Hello, I am John.", maxLength = 255) + @Size(max = 255) + private String introduction; + + /** + * 사용자 활성화여부 + */ + @Schema(name = "isActive", description = "사용자 활성화여부", required = false, nullable = false, example = "true") + private boolean isActive; + + /** + * 사용자 등록 프로그램 Id(자체 회원가입, OAuth 등) + */ + @Schema(name = "createProgramId", description = "사용자 등록 프로그램 Id(자체 회원가입, OAuth 등)", required = false, nullable = true, example = "oauth", maxLength = 20) + @Size(max = 20) + private String createProgramId; + + /** + * 사용자 수정 프로그램 Id(자체 프로필수정, 데이터연동 등) + */ + @Schema(name = "modifyProgramId", description = "사용자 수정 프로그램 Id(자체 프로필수정, 데이터연동 등)", required = true, nullable = true, example = "profile_edit", maxLength = 20) + @Nullable + @Size(max = 20) + private String modifyProgramId; + + /** + * 사용자 삭제 프로그램 Id(자체 회원탈퇴, 관리자 삭제, 개인정보 보존만료 등) + */ + @Schema(name = "deleteProgramId", description = "사용자 삭제 프로그램 Id(자체 회원탈퇴, 관리자 삭제, 개인정보 보존만료 등)", required = false, nullable = true, example = "admin_delete", maxLength = 20) + @Size(max = 20) + private String deleteProgramId; +} \ No newline at end of file diff --git a/src/main/java/com/karrot/domain/user/UsersResponseDTO.java b/src/main/java/com/karrot/domain/user/UsersResponseDTO.java new file mode 100644 index 0000000..5879f3d --- /dev/null +++ b/src/main/java/com/karrot/domain/user/UsersResponseDTO.java @@ -0,0 +1,70 @@ +package com.karrot.domain.user; + +import java.time.LocalDateTime; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(name = "User", description = "사용자 정보") +public class UsersResponseDTO { + /** + * 사용자 ID + */ + @Schema(name = "id", description = "사용자 ID", required = true, nullable = false, example = "1") + private Long id; + + /** + * 사용자 이름 + */ + @Schema(name = "name", description = "사용자 이름", required = false, nullable = false, example = "John Doe", maxLength = 10) + private String name; + + /** + * 사용자 소개글 + */ + @Schema(name = "introduction", description = "사용자 소개글", required = false, nullable = true, example = "Hello, I am John.", maxLength = 255) + private String introduction; + + /** + * 사용자 활성화여부 + */ + @Schema(name = "isActive", description = "사용자 활성화여부", required = false, nullable = false, example = "true") + private boolean isActive; + + /** + * 사용자 등록 프로그램 Id(자체 회원가입, OAuth 등) + */ + @Schema(name = "createProgramId", description = "사용자 등록 프로그램 Id(자체 회원가입, OAuth 등)", required = false, nullable = false, example = "oauth", maxLength = 20) + private String createProgramId; + + /** + * 사용자 등록일시 + */ + @Schema(name = "createdDateTime", description = "사용자 등록일시", required = false, nullable = false, example = "2023-01-01T12:00:00") + private LocalDateTime createdDateTime; + + /** + * 사용자 수정 프로그램 Id(자체 프로필수정, 데이터연동 등) + */ + @Schema(name = "modifyProgramId", description = "사용자 수정 프로그램 Id(자체 프로필수정, 데이터연동 등)", required = true, nullable = false, example = "profile_edit", maxLength = 20) + private String modifyProgramId; + + /** + * 사용자 수정일시 + */ + @Schema(name = "modifiedDateTime", description = "사용자 수정일시", required = true, nullable = false, example = "2023-01-02T12:00:00") + private LocalDateTime modifiedDateTime; + + /** + * 사용자 삭제 프로그램 Id(자체 회원탈퇴, 관리자 삭제, 개인정보 보존만료 등) + */ + @Schema(name = "deleteProgramId", description = "사용자 삭제 프로그램 Id(자체 회원탈퇴, 관리자 삭제, 개인정보 보존만료 등)", required = false, nullable = true, example = "admin_delete", maxLength = 20) + private String deleteProgramId; + + /** + * 사용자 삭제일시 + */ + @Schema(name = "deletedDateTime", description = "사용자 삭제일시", required = false, nullable = true, example = "2023-01-03T12:00:00") + private LocalDateTime deletedDateTime; +} \ No newline at end of file diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 2440530..830d395 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -31,4 +31,5 @@ springdoc: path: /swagger disable-swagger-default-url: true display-request-duration: true - operations-sorter: alpha \ No newline at end of file + operations-sorter: alpha + tags-sorter: alpha \ No newline at end of file diff --git a/src/test/java/com/karrot/domain/user/UserControllerTest.java b/src/test/java/com/karrot/domain/user/UserControllerTest.java index 1613c31..3040320 100644 --- a/src/test/java/com/karrot/domain/user/UserControllerTest.java +++ b/src/test/java/com/karrot/domain/user/UserControllerTest.java @@ -54,7 +54,7 @@ public class UserControllerTest { @Test public void givenValidUser_whenCreateUser_thenThrowNotYetImplementException() throws Exception { //given - Users user = new Users(); + UsersEntity user = new UsersEntity(); user.setId(1L); user.setName("John Doe"); String payload = new ObjectMapper().writeValueAsString(user); @@ -121,13 +121,13 @@ public void givenValidUserId_whenGetUser_thenThrowNotYetImplementException() thr @Test public void givenValidUserIdAndUser_whenUpdateUser_thenThrowNotYetImplementException() throws Exception { //given - Users user = new Users(); - user.setId(1L); + UsersRequestDTO user = new UsersRequestDTO(); + //user.setId(1L); user.setName("John Doe"); String payload = new ObjectMapper().writeValueAsString(user); //when - when(userController.updateUser(any(Long.class), any(Users.class))).thenThrow(new NotYetImplementedException()); + when(userController.updateUser(any(Long.class), any(UsersRequestDTO.class))).thenThrow(new NotYetImplementedException()); MockHttpServletRequestBuilder request = put("/api/users/1") .contentType(MediaType.APPLICATION_JSON) .content(payload);