Skip to content

Commit

Permalink
Merge pull request #145 from Elwizzy12/feature/setup-mapstruct-in-bac…
Browse files Browse the repository at this point in the history
…kend

Setup mapstruct into backend
  • Loading branch information
kouamschekina authored Jun 19, 2024
2 parents 31d7543 + 83da8cd commit f3f54ba
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
13 changes: 13 additions & 0 deletions power-pay-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<properties>
<java.version>17</java.version>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
<api-package>com.adorsys.gis.powerpay.api</api-package>
</properties>

Expand Down Expand Up @@ -110,6 +111,18 @@
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<!-- MapStruct -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.4.2.Final</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.adorsys.gis.powerpay.powerpaybackend;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class MapstructTest {

@Test
public void testmapStruct() {
Person person = new Person();
person.setName("John Doe");

PersonDto personDto = PersonMapper.INSTANCE.personToPersonDto(person);

System.out.println("Person DTO Full Name: " + personDto.getFullName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.adorsys.gis.powerpay.powerpaybackend;

public class Person {
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.adorsys.gis.powerpay.powerpaybackend;

// PersonDto.java
public class PersonDto {
private String fullName;

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.adorsys.gis.powerpay.powerpaybackend;

// PersonMapper.java
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper(componentModel = "spring")
public interface PersonMapper {
PersonMapper INSTANCE = Mappers.getMapper(PersonMapper.class);

@Mapping(source = "name", target = "fullName")
PersonDto personToPersonDto(Person person);
}

0 comments on commit f3f54ba

Please sign in to comment.