From 11a8fbf665be4c53a5bff3a3c88df9283b6f654e Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 12:41:31 +0900 Subject: [PATCH] =?UTF-8?q?[ADD]=20=E3=82=B7=E3=83=A7=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=82=AB=E3=83=83=E3=83=88=E6=A9=9F=E8=83=BD=E3=81=AE=E3=81=9F?= =?UTF-8?q?=E3=82=81=E3=81=AEEntity/Model/Form=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/app/domain/model/FixedCostModel.java | 49 +++++++++++++++++ .../app/infra/entity/FixedCostEntity.java | 42 ++++++++++++++ .../app/presentation/form/FixedCostForm.java | 55 +++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 src/main/java/com/example/demo/app/domain/model/FixedCostModel.java create mode 100644 src/main/java/com/example/demo/app/infra/entity/FixedCostEntity.java create mode 100644 src/main/java/com/example/demo/app/presentation/form/FixedCostForm.java diff --git a/src/main/java/com/example/demo/app/domain/model/FixedCostModel.java b/src/main/java/com/example/demo/app/domain/model/FixedCostModel.java new file mode 100644 index 0000000..45d57be --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/model/FixedCostModel.java @@ -0,0 +1,49 @@ +package com.example.demo.app.domain.model; + +import java.util.List; + +import com.example.demo.app.infra.entity.CategoryEntity; +import com.example.demo.app.infra.entity.FixedCostEntity; +import com.example.demo.app.infra.entity.UserEntity; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class FixedCostModel { + + private Long fixedCostId; + + private Long userId; + + private Long categoryId; + + private String fixedCostName; + + private Integer amount; + + + public static FixedCostModel convertFrom(FixedCostEntity fixedCostEntity) { + return new FixedCostModel( + fixedCostEntity.getFixedCostId(), + fixedCostEntity.getUserEntity().getUserId(), + fixedCostEntity.getCategoryEntity().getCategoryId(), + fixedCostEntity.getFixedCostName(), + fixedCostEntity.getAmount()); + } + + public static List convertFrom(List fixedCostEntityList) { + return fixedCostEntityList.stream().map(FixedCostModel::convertFrom).toList(); + } + + public static FixedCostEntity convertTo(FixedCostModel fixedCostModel, UserEntity userEntity, CategoryEntity categoryEntity) { + return new FixedCostEntity( + fixedCostModel.getFixedCostId(), + userEntity, + categoryEntity, + fixedCostModel.getFixedCostName(), + fixedCostModel.getAmount()); + } + +} diff --git a/src/main/java/com/example/demo/app/infra/entity/FixedCostEntity.java b/src/main/java/com/example/demo/app/infra/entity/FixedCostEntity.java new file mode 100644 index 0000000..ef131b2 --- /dev/null +++ b/src/main/java/com/example/demo/app/infra/entity/FixedCostEntity.java @@ -0,0 +1,42 @@ +package com.example.demo.app.infra.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "fixed_cost_t") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class FixedCostEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "fixed_cost_id") + private Long fixedCostId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private UserEntity userEntity; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private CategoryEntity categoryEntity; + + @Column(name = "fixed_cost_name", nullable = false) + private String fixedCostName; + + @Column(name = "amount", nullable = false) + private Integer amount; +} diff --git a/src/main/java/com/example/demo/app/presentation/form/FixedCostForm.java b/src/main/java/com/example/demo/app/presentation/form/FixedCostForm.java new file mode 100644 index 0000000..8c12754 --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/form/FixedCostForm.java @@ -0,0 +1,55 @@ +package com.example.demo.app.presentation.form; + +import java.util.List; + +import com.example.demo.app.domain.model.FixedCostModel; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class FixedCostForm { + + private Long fixedCostId; + + private Long userId; + + private Long categoryId; + + private String fixedCostName; + + private Integer amount; + + private String categoryName; + + + public static FixedCostForm convertFrom(FixedCostModel fixedCostModel) { + return new FixedCostForm( + fixedCostModel.getFixedCostId(), + fixedCostModel.getUserId(), + fixedCostModel.getCategoryId(), + fixedCostModel.getFixedCostName(), + fixedCostModel.getAmount(), + ""); + } + + + public static List convertFrom(List fixedCostModelList) { + return fixedCostModelList.stream().map(fixedCostModel -> FixedCostForm.convertFrom(fixedCostModel)).toList(); + } + + public static FixedCostModel convertTo(FixedCostForm fixedCostForm) { + return new FixedCostModel( + fixedCostForm.getFixedCostId(), + fixedCostForm.getUserId(), + fixedCostForm.getCategoryId(), + fixedCostForm.getFixedCostName(), + fixedCostForm.getAmount()); + } + + + +}