[ADD] ショートカット機能のためのEntity/Model/Formを追加しました。

This commit is contained in:
s-choi
2026-09-24 12:41:31 +09:00
parent 5ca3226dfa
commit 11a8fbf665
3 changed files with 146 additions and 0 deletions

View File

@@ -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<FixedCostModel> convertFrom(List<FixedCostEntity> 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());
}
}

View File

@@ -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;
}

View File

@@ -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<FixedCostForm> convertFrom(List<FixedCostModel> 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());
}
}