Skip to content

Commit

Permalink
Better use of lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
zouabimourad committed Apr 5, 2021
1 parent ed69014 commit 3ccf9a8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void updatePerson(@RequestBody PersonDTO personDTO) {
public void deletePerson(@PathVariable Long id) {
personService.deletePerson(id);
}

}


13 changes: 3 additions & 10 deletions backend/src/main/java/net/mzouabi/ng2/server/dto/AbstractDTO.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
45 changes: 7 additions & 38 deletions backend/src/main/java/net/mzouabi/ng2/server/dto/PersonDTO.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
@@ -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;

}
36 changes: 7 additions & 29 deletions backend/src/main/java/net/mzouabi/ng2/server/model/Person.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public Optional<PersonDTO> getPerson(Long id) {
public void updatePerson(PersonDTO personDTO) {
personRepository.findById(personDTO.getId())
.ifPresent(person -> personMapper.mapToEntity(personDTO, person));

}

public void savePerson(PersonDTO personDTO) {
Expand Down

0 comments on commit 3ccf9a8

Please sign in to comment.