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()); + } + + + +}