diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index f1be365..ea7d2aa 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -12,6 +12,8 @@ import com.plannaplan.entities.Commision; import com.plannaplan.entities.Groups; import com.plannaplan.entities.User; import com.plannaplan.exceptions.UserNotFoundException; +import com.plannaplan.responses.mappers.CommisionResponseMappers; +import com.plannaplan.responses.models.CommisionResponse; import com.plannaplan.services.AssignmentService; import com.plannaplan.services.CommisionService; import com.plannaplan.services.GroupService; @@ -57,9 +59,10 @@ public class CommisionController extends TokenBasedController { } @GetMapping("/getAllCommisions") - public ResponseEntity> getAlCommisions() throws UserNotFoundException { + public ResponseEntity> getAlCommisions() throws UserNotFoundException { User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException()); - List result = this.commisionService.getUsersCommisions(user); + List result = CommisionResponseMappers + .mapToResponse(this.commisionService.getUsersCommisions(user)); return new ResponseEntity<>(result, HttpStatus.OK); } diff --git a/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java b/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java new file mode 100755 index 0000000..3303e96 --- /dev/null +++ b/restservice/src/main/java/com/plannaplan/responses/mappers/CommisionResponseMappers.java @@ -0,0 +1,14 @@ +package com.plannaplan.responses.mappers; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import com.plannaplan.entities.Commision; +import com.plannaplan.responses.models.CommisionResponse; + +public class CommisionResponseMappers { + public static final List mapToResponse(List commisions) { + return commisions.stream().filter(Objects::nonNull).map(CommisionResponse::new).collect(Collectors.toList()); + } +} diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java new file mode 100755 index 0000000..585d871 --- /dev/null +++ b/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java @@ -0,0 +1,24 @@ +package com.plannaplan.responses.models; + +import java.sql.Timestamp; + +import com.plannaplan.entities.Commision; + +public class CommisionResponse { + private Long id; + private Timestamp commisionDate; + + public CommisionResponse(Commision commision) { + this.id = commision.getId(); + this.commisionDate = commision.getCommisionDate(); + } + + public Timestamp getCommisionDate() { + return commisionDate; + } + + public Long getId() { + return id; + } + +} diff --git a/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java b/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java new file mode 100755 index 0000000..95d02a6 --- /dev/null +++ b/restservice/src/test/java/com/plannaplan/responses/mappers/CommisionResponseMappersTest.java @@ -0,0 +1,23 @@ +package com.plannaplan.responses.mappers; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import com.plannaplan.entities.Commision; +import com.plannaplan.responses.models.CommisionResponse; + +import org.junit.Test; + +public class CommisionResponseMappersTest { + @Test + public void shouldMapListWithEntityToListOfResponses() { + final List coms = Arrays.asList(new Commision(null), new Commision(null)); + final List resposne = CommisionResponseMappers.mapToResponse(coms); + + assertTrue(resposne.get(0) instanceof CommisionResponse); + assertTrue(resposne.get(0).getCommisionDate().equals(coms.get(0).getCommisionDate())); + assertTrue(resposne.get(1).getCommisionDate().equals(coms.get(1).getCommisionDate())); + } +} diff --git a/restservice/src/test/java/com/plannaplan/responses/models/CommisionResponseTest.java b/restservice/src/test/java/com/plannaplan/responses/models/CommisionResponseTest.java new file mode 100755 index 0000000..23edc29 --- /dev/null +++ b/restservice/src/test/java/com/plannaplan/responses/models/CommisionResponseTest.java @@ -0,0 +1,17 @@ +package com.plannaplan.responses.models; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.plannaplan.entities.Commision; + +import org.junit.Test; + +public class CommisionResponseTest { + @Test + public void shouldMapCommisionToResponse() { + final Commision com = new Commision(null); + final CommisionResponse comResponse = new CommisionResponse(com); + + assertTrue(comResponse.getCommisionDate().equals(com.getCommisionDate())); + } +}