Commisions respone updatede

This commit is contained in:
Filip Izydorczyk 2020-10-15 17:29:40 +02:00
parent 010f0b4566
commit 2b067f63fc
5 changed files with 83 additions and 2 deletions

View File

@ -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<List<Commision>> getAlCommisions() throws UserNotFoundException {
public ResponseEntity<List<CommisionResponse>> getAlCommisions() throws UserNotFoundException {
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
List<Commision> result = this.commisionService.getUsersCommisions(user);
List<CommisionResponse> result = CommisionResponseMappers
.mapToResponse(this.commisionService.getUsersCommisions(user));
return new ResponseEntity<>(result, HttpStatus.OK);
}

View File

@ -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<CommisionResponse> mapToResponse(List<Commision> commisions) {
return commisions.stream().filter(Objects::nonNull).map(CommisionResponse::new).collect(Collectors.toList());
}
}

View File

@ -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;
}
}

View File

@ -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<Commision> coms = Arrays.asList(new Commision(null), new Commision(null));
final List<CommisionResponse> 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()));
}
}

View File

@ -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()));
}
}