From 3ccf9a81a1dd9aaf90bb7485d5468f70eb0750f8 Mon Sep 17 00:00:00 2001 From: "mourad.zouabi" Date: Mon, 5 Apr 2021 22:06:49 +0200 Subject: [PATCH] Better use of lombok --- .../server/controller/PersonController.java | 1 + .../mzouabi/ng2/server/dto/AbstractDTO.java | 13 ++---- .../net/mzouabi/ng2/server/dto/PersonDTO.java | 45 +++---------------- .../ng2/server/mapper/PersonMapper.java | 10 ++--- .../ng2/server/model/AbstractEntity.java | 29 ++++-------- .../net/mzouabi/ng2/server/model/Person.java | 36 +++------------ .../ng2/server/service/PersonService.java | 1 - 7 files changed, 29 insertions(+), 106 deletions(-) diff --git a/backend/src/main/java/net/mzouabi/ng2/server/controller/PersonController.java b/backend/src/main/java/net/mzouabi/ng2/server/controller/PersonController.java index 6eeab04..f351a18 100644 --- a/backend/src/main/java/net/mzouabi/ng2/server/controller/PersonController.java +++ b/backend/src/main/java/net/mzouabi/ng2/server/controller/PersonController.java @@ -45,6 +45,7 @@ public void updatePerson(@RequestBody PersonDTO personDTO) { public void deletePerson(@PathVariable Long id) { personService.deletePerson(id); } + } diff --git a/backend/src/main/java/net/mzouabi/ng2/server/dto/AbstractDTO.java b/backend/src/main/java/net/mzouabi/ng2/server/dto/AbstractDTO.java index 314dc8a..3008c21 100644 --- a/backend/src/main/java/net/mzouabi/ng2/server/dto/AbstractDTO.java +++ b/backend/src/main/java/net/mzouabi/ng2/server/dto/AbstractDTO.java @@ -1,17 +1,10 @@ package net.mzouabi.ng2.server.dto; -/** - * Created by mouradzouabi on 05/03/16. - */ +import lombok.Data; + +@Data public class AbstractDTO { private Long id; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } } diff --git a/backend/src/main/java/net/mzouabi/ng2/server/dto/PersonDTO.java b/backend/src/main/java/net/mzouabi/ng2/server/dto/PersonDTO.java index 79af017..d03881c 100644 --- a/backend/src/main/java/net/mzouabi/ng2/server/dto/PersonDTO.java +++ b/backend/src/main/java/net/mzouabi/ng2/server/dto/PersonDTO.java @@ -1,49 +1,18 @@ package net.mzouabi.ng2.server.dto; +import lombok.Data; + import java.util.Date; -/** - * Created by mouradzouabi on 04/12/15. - */ +@Data public class PersonDTO extends AbstractDTO { - String firstname; - - String lastname; - - Integer age; - - Date dateOfBirth; - - public String getFirstname() { - return firstname; - } - - public void setFirstname(String firstname) { - this.firstname = firstname; - } - - public String getLastname() { - return lastname; - } - - public void setLastname(String lastname) { - this.lastname = lastname; - } + private String firstname; - public Integer getAge() { - return age; - } + private String lastname; - public void setAge(Integer age) { - this.age = age; - } + private Integer age; - public Date getDateOfBirth() { - return dateOfBirth; - } + private Date dateOfBirth; - public void setDateOfBirth(Date dateOfBirth) { - this.dateOfBirth = dateOfBirth; - } } diff --git a/backend/src/main/java/net/mzouabi/ng2/server/mapper/PersonMapper.java b/backend/src/main/java/net/mzouabi/ng2/server/mapper/PersonMapper.java index 2c27ecc..b5ccd02 100644 --- a/backend/src/main/java/net/mzouabi/ng2/server/mapper/PersonMapper.java +++ b/backend/src/main/java/net/mzouabi/ng2/server/mapper/PersonMapper.java @@ -5,18 +5,14 @@ import org.mapstruct.Mapper; import org.mapstruct.MappingTarget; import org.mapstruct.ReportingPolicy; -import org.mapstruct.TargetType; -/** - * Created by mouradzouabi on 04/12/15. - */ @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface PersonMapper { - public PersonDTO toDTO(Person person); + PersonDTO toDTO(Person person); - public Person toEntity(PersonDTO person); + Person toEntity(PersonDTO person); - public void mapToEntity(PersonDTO personDTO, @MappingTarget Person person); + void mapToEntity(PersonDTO personDTO, @MappingTarget Person person); } diff --git a/backend/src/main/java/net/mzouabi/ng2/server/model/AbstractEntity.java b/backend/src/main/java/net/mzouabi/ng2/server/model/AbstractEntity.java index 385b6be..81a64ec 100644 --- a/backend/src/main/java/net/mzouabi/ng2/server/model/AbstractEntity.java +++ b/backend/src/main/java/net/mzouabi/ng2/server/model/AbstractEntity.java @@ -1,35 +1,22 @@ package net.mzouabi.ng2.server.model; +import lombok.Data; + import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.persistence.Version; import java.io.Serializable; +@Data @MappedSuperclass public class AbstractEntity implements Serializable { - @Id - @GeneratedValue - private Long id; - - @Version - private Integer version; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Integer getVersion() { - return version; - } + @Id + @GeneratedValue + private Long id; - public void setVersion(Integer version) { - this.version = version; - } + @Version + private Integer version; } diff --git a/backend/src/main/java/net/mzouabi/ng2/server/model/Person.java b/backend/src/main/java/net/mzouabi/ng2/server/model/Person.java index 7db83cb..ba1191f 100644 --- a/backend/src/main/java/net/mzouabi/ng2/server/model/Person.java +++ b/backend/src/main/java/net/mzouabi/ng2/server/model/Person.java @@ -1,41 +1,19 @@ package net.mzouabi.ng2.server.model; +import lombok.Data; + import javax.persistence.Entity; -import javax.persistence.Table; -import java.util.Date; +@Data @Entity public class Person extends AbstractEntity { - private static final long serialVersionUID = -6321180910534044216L; - - String firstname; - - String lastname; - - Integer age; - - public String getFirstname() { - return firstname; - } - - public void setFirstname(String firstname) { - this.firstname = firstname; - } + private static final long serialVersionUID = -6321180910534044216L; - public String getLastname() { - return lastname; - } + private String firstname; - public void setLastname(String lastname) { - this.lastname = lastname; - } + private String lastname; - public Integer getAge() { - return age; - } + private Integer age; - public void setAge(Integer age) { - this.age = age; - } } diff --git a/backend/src/main/java/net/mzouabi/ng2/server/service/PersonService.java b/backend/src/main/java/net/mzouabi/ng2/server/service/PersonService.java index 7abf9d3..78ca21a 100644 --- a/backend/src/main/java/net/mzouabi/ng2/server/service/PersonService.java +++ b/backend/src/main/java/net/mzouabi/ng2/server/service/PersonService.java @@ -35,7 +35,6 @@ public Optional getPerson(Long id) { public void updatePerson(PersonDTO personDTO) { personRepository.findById(personDTO.getId()) .ifPresent(person -> personMapper.mapToEntity(personDTO, person)); - } public void savePerson(PersonDTO personDTO) {