Skip to content

Commit f840e5f

Browse files
committed
refactor prenda Entity (la lista en marca)
1 parent 946bed0 commit f840e5f

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

src/main/java/com/outfitlab/project/domain/model/MarcaModel.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.outfitlab.project.domain.model;
22

3-
import lombok.Getter;
3+
import com.outfitlab.project.infrastructure.model.PrendaEntity;
44

55
import java.time.LocalDateTime;
6+
import java.util.ArrayList;
7+
import java.util.List;
68

79
public class MarcaModel {
810

@@ -11,15 +13,17 @@ public class MarcaModel {
1113
private String logoUrl;
1214
private LocalDateTime createdAt;
1315
private LocalDateTime updatedAt;
16+
private List<PrendaModel> prendas;
1417

1518
public MarcaModel(){}
1619

17-
public MarcaModel(String codigoMarca, String nombre, String logoUrl, LocalDateTime createdAt, LocalDateTime updatedAt) {
20+
public MarcaModel(String codigoMarca, String nombre, String logoUrl, LocalDateTime createdAt, LocalDateTime updatedAt, List<PrendaModel> prendas) {
1821
this.codigoMarca = codigoMarca;
1922
this.nombre = nombre;
2023
this.logoUrl = logoUrl;
2124
this.createdAt = createdAt;
2225
this.updatedAt = updatedAt;
26+
this.prendas = prendas;
2327
}
2428

2529
public String getCodigoMarca() {
@@ -61,4 +65,12 @@ public LocalDateTime getUpdatedAt() {
6165
public void setUpdatedAt(LocalDateTime updatedAt) {
6266
this.updatedAt = updatedAt;
6367
}
68+
69+
public List<PrendaModel> getPrendas() {
70+
return prendas;
71+
}
72+
73+
public void setPrendas(List<PrendaModel> prendas) {
74+
this.prendas = prendas;
75+
}
6476
}

src/main/java/com/outfitlab/project/infrastructure/model/MarcaEntity.java

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonManagedReference;
44
import com.outfitlab.project.domain.model.MarcaModel;
5+
import com.outfitlab.project.domain.model.PrendaModel;
56
import jakarta.persistence.*;
67
import lombok.AllArgsConstructor;
78
import lombok.Getter;
@@ -63,24 +64,47 @@ public void addPrenda(PrendaEntity prenda) {
6364

6465

6566
// ------------- acá hacemos los dos convert ------------
66-
public static MarcaModel convertToModel(MarcaEntity marcaEntity) {
67+
public static MarcaModel convertToModel(MarcaEntity entity) {
68+
if (entity == null) return null;
69+
70+
List<PrendaModel> prendasModel = new ArrayList<>();
71+
if (entity.getPrendas() != null) {
72+
for (PrendaEntity prendaEntity : entity.getPrendas()) {
73+
prendasModel.add(PrendaEntity.convertToModel(prendaEntity));
74+
}
75+
}
76+
6777
return new MarcaModel(
68-
marcaEntity.getCodigoMarca(),
69-
marcaEntity.getNombre(),
70-
marcaEntity.getLogoUrl(),
71-
marcaEntity.getCreatedAt(),
72-
marcaEntity.getUpdatedAt()
78+
entity.getCodigoMarca(),
79+
entity.getNombre(),
80+
entity.getLogoUrl(),
81+
entity.getCreatedAt(),
82+
entity.getUpdatedAt(),
83+
prendasModel
7384
);
7485
}
7586

76-
public static MarcaEntity convertToEntity(MarcaModel marcaModel) {
77-
return new MarcaEntity(
78-
marcaModel.getCodigoMarca(),
79-
marcaModel.getNombre(),
80-
marcaModel.getLogoUrl(),
81-
marcaModel.getCreatedAt(),
82-
marcaModel.getUpdatedAt()
83-
);
87+
public static MarcaEntity convertToEntity(MarcaModel model) {
88+
if (model == null) return null;
89+
90+
MarcaEntity entity = new MarcaEntity();
91+
entity.setCodigoMarca(model.getCodigoMarca());
92+
entity.setNombre(model.getNombre());
93+
entity.setLogoUrl(model.getLogoUrl());
94+
entity.setCreatedAt(model.getCreatedAt());
95+
entity.setUpdatedAt(model.getUpdatedAt());
96+
97+
List<PrendaEntity> prendasEntity = new ArrayList<>();
98+
if (model.getPrendas() != null) {
99+
for (PrendaModel prendaModel : model.getPrendas()) {
100+
PrendaEntity prendaEntity = PrendaEntity.convertToEntity(prendaModel);
101+
prendaEntity.setMarca(entity);
102+
prendasEntity.add(prendaEntity);
103+
}
104+
}
105+
106+
entity.setPrendas(prendasEntity);
107+
return entity;
84108
}
85109
//--------------------------------------------------------
86110
}

0 commit comments

Comments
 (0)