From 98646efe0b4f2465379b43decfa20c83d7618a7d Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Mon, 28 Aug 2023 21:05:25 +0300 Subject: [PATCH 01/45] Update SuppressWarnings description --- src/main/java/com/ays/common/model/AysSpecification.java | 2 +- .../com/ays/common/model/dto/response/AysPageResponse.java | 2 +- src/main/java/com/ays/common/util/AysListUtil.java | 2 +- .../model/dto/request/UserSupportStatusUpdateRequest.java | 2 +- .../com/ays/user/model/dto/request/UserUpdateRequest.java | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/ays/common/model/AysSpecification.java b/src/main/java/com/ays/common/model/AysSpecification.java index 1ec719813..bb175523d 100644 --- a/src/main/java/com/ays/common/model/AysSpecification.java +++ b/src/main/java/com/ays/common/model/AysSpecification.java @@ -18,7 +18,7 @@ public class AysSpecification { * A builder class for creating specifications in the context of AysSpecification. * Use this builder to construct predicates based on a provided filter. */ - @SuppressWarnings("unused") + @SuppressWarnings("This method is unused by the application directly but Spring is using it in the background.") public static class AysSpecificationBuilder { /** diff --git a/src/main/java/com/ays/common/model/dto/response/AysPageResponse.java b/src/main/java/com/ays/common/model/dto/response/AysPageResponse.java index a51fcf3d6..1d5d398fe 100644 --- a/src/main/java/com/ays/common/model/dto/response/AysPageResponse.java +++ b/src/main/java/com/ays/common/model/dto/response/AysPageResponse.java @@ -58,7 +58,7 @@ public class AysPageResponse { * * @param The type of content in the response. */ - @SuppressWarnings("unused") + @SuppressWarnings("This method is unused by the application directly but Spring is using it in the background.") public static class AysPageResponseBuilder { /** diff --git a/src/main/java/com/ays/common/util/AysListUtil.java b/src/main/java/com/ays/common/util/AysListUtil.java index a2f732119..4b17db170 100644 --- a/src/main/java/com/ays/common/util/AysListUtil.java +++ b/src/main/java/com/ays/common/util/AysListUtil.java @@ -18,7 +18,7 @@ public class AysListUtil { * @param the type parameter for the class * @return a List of objects of the specified class type */ - @SuppressWarnings({"unchecked", "unused"}) + @SuppressWarnings({"unchecked", "This method is unused by the application directly but Spring is using it in the background."}) public static List to(Object object, Class clazz) { return (List) object; } diff --git a/src/main/java/com/ays/user/model/dto/request/UserSupportStatusUpdateRequest.java b/src/main/java/com/ays/user/model/dto/request/UserSupportStatusUpdateRequest.java index 973756e75..a6de3dee3 100644 --- a/src/main/java/com/ays/user/model/dto/request/UserSupportStatusUpdateRequest.java +++ b/src/main/java/com/ays/user/model/dto/request/UserSupportStatusUpdateRequest.java @@ -25,7 +25,7 @@ public class UserSupportStatusUpdateRequest { private UserSupportStatus supportStatus; @AssertTrue(message = "IS NOT ACCEPTED") - @SuppressWarnings("unused") + @SuppressWarnings("This method is unused by the application directly but Spring is using it in the background.") private boolean isSupportStatusAccepted() { if (ObjectUtils.isEmpty(this.supportStatus)) { diff --git a/src/main/java/com/ays/user/model/dto/request/UserUpdateRequest.java b/src/main/java/com/ays/user/model/dto/request/UserUpdateRequest.java index dd9e6ebe0..21eaefe91 100644 --- a/src/main/java/com/ays/user/model/dto/request/UserUpdateRequest.java +++ b/src/main/java/com/ays/user/model/dto/request/UserUpdateRequest.java @@ -31,7 +31,7 @@ public class UserUpdateRequest { private UserStatus status; @AssertTrue(message = "IS NOT ACCEPTED") - @SuppressWarnings("unused") + @SuppressWarnings("This method is unused by the application directly but Spring is using it in the background.") private boolean isStatusAccepted() { if (ObjectUtils.isEmpty(this.status)) { @@ -43,7 +43,7 @@ private boolean isStatusAccepted() { } @AssertTrue(message = "IS NOT ACCEPTED") - @SuppressWarnings("unused") + @SuppressWarnings("This method is unused by the application directly but Spring is using it in the background.") private boolean isRoleAccepted() { if (ObjectUtils.isEmpty(this.role)) { From 625cc4b73252c0c773c7cf547589d029d7e19c57 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Mon, 28 Aug 2023 21:29:06 +0300 Subject: [PATCH 02/45] Update AssignmentListRequest --- .../dto/request/AssignmentListRequest.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index c7a35f0a5..815fefee6 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -1,16 +1,18 @@ package com.ays.assignment.model.dto.request; import com.ays.assignment.model.enums.AssignmentStatus; +import com.ays.common.model.AysFiltering; import com.ays.common.model.dto.request.AysFilteringRequest; import com.ays.common.model.dto.request.AysPagingRequest; -import com.ays.common.util.validation.EnumValidation; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.validation.Valid; import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Data; import org.springframework.data.jpa.domain.Specification; -import java.util.EnumSet; +import java.util.List; import java.util.Set; /** @@ -21,29 +23,25 @@ @Builder public class AssignmentListRequest extends AysPagingRequest implements AysFilteringRequest { - private AssignmentStatus status; + @Valid + public Filter filter; /** - * Checks if the assignment status is valid. - * - * @return true if the assignment status is valid or null, false otherwise. + * Represents a filtering configuration for assignments based on the class fields. */ - @AssertTrue(message = "IS ASSIGNMENT STATUS NOT ACCEPTED") - private boolean isStatusAccepted() { + @Data + public static class Filter implements AysFiltering { - if (this.status == null) { - return true; - } - EnumSet acceptedAssignmentStatuses = EnumSet.of(AssignmentStatus.AVAILABLE, - AssignmentStatus.RESERVED, - AssignmentStatus.ASSIGNED, - AssignmentStatus.IN_PROGRESS, - AssignmentStatus.DONE - ); - return EnumValidation.anyOf(this.status, acceptedAssignmentStatuses); + /** + * List of assignment statuses used for filtering. + */ + @NotNull + public List statuses; + } + /** * Overrides the {@link AysPagingRequest#isSortPropertyAccepted()} method to validate sorting options * and ensures that no unsupported sorting property is used in the request. @@ -58,22 +56,26 @@ public boolean isSortPropertyAccepted() { return this.isPropertyAccepted(acceptedFilterFields); } + /** - * Converts the request into a JPA Specification that filters assignments based on the specified status, - * if it is provided. + * Converts the request into a JPA Specification that filters assignments based on the specified statuses, + * if they are provided. * * @param clazz the class type of the specification. * @return the generated JPA Specification based on the request filters. */ @Override public Specification toSpecification(Class clazz) { - Specification specification = Specification.where(null); - if (status != null) { - specification = specification.and((root, query, builder) -> - builder.equal(root.get("status"), status)); + if (this.filter == null) { + return Specification.allOf(); } - // Add more filter conditions if needed - return specification; + + return this.filter.statuses.stream() + .map(status -> (Specification) + (root, query, criteriaBuilder) -> criteriaBuilder + .equal(root.get("status"), status)) + .reduce(Specification::or) + .orElse(null); } } From 14d0888f6fab2004d73872b0af84779a9788ceae Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Mon, 28 Aug 2023 21:35:14 +0300 Subject: [PATCH 03/45] Removed Assignment Search Response from the AssignmentResponse --- .../ays/assignment/model/dto/response/AssignmentResponse.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/response/AssignmentResponse.java b/src/main/java/com/ays/assignment/model/dto/response/AssignmentResponse.java index 15131dbe1..59ad6e3ce 100644 --- a/src/main/java/com/ays/assignment/model/dto/response/AssignmentResponse.java +++ b/src/main/java/com/ays/assignment/model/dto/response/AssignmentResponse.java @@ -20,6 +20,4 @@ public class AssignmentResponse extends BaseResponse { private Double longitude; private Double latitude; - private AssignmentSearchResponse assignmentSearchResponse; - } From c9b15677571f359e1e139e7750857aada1095d7a Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Mon, 28 Aug 2023 22:02:32 +0300 Subject: [PATCH 04/45] Define AssignmentsResponse --- .../dto/response/AssignmentsResponse.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java diff --git a/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java b/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java new file mode 100644 index 000000000..6d1ded7bd --- /dev/null +++ b/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java @@ -0,0 +1,30 @@ +package com.ays.assignment.model.dto.response; + +import com.ays.common.model.dto.response.BaseResponse; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.SuperBuilder; + +@Data +@EqualsAndHashCode(callSuper = true) +@SuperBuilder +public class AssignmentsResponse extends BaseResponse { + + private String id; + private String description; + private String firstName; + private String lastName; + private Location location; + private User user; + + private static class Location { + private Double longitude; + private Double latitude; + } + + private static class User { + private String id; + private String firstName; + private String lastName; + } +} From dbfcbb4a1643b86569589017b5fd20f94f40074d Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Mon, 28 Aug 2023 22:04:53 +0300 Subject: [PATCH 05/45] Define getAssignments in AssignmentController --- .../controller/AssignmentController.java | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ays/assignment/controller/AssignmentController.java b/src/main/java/com/ays/assignment/controller/AssignmentController.java index a78c2ca66..7743b500f 100644 --- a/src/main/java/com/ays/assignment/controller/AssignmentController.java +++ b/src/main/java/com/ays/assignment/controller/AssignmentController.java @@ -1,11 +1,14 @@ package com.ays.assignment.controller; import com.ays.assignment.model.Assignment; +import com.ays.assignment.model.dto.request.AssignmentListRequest; import com.ays.assignment.model.dto.request.AssignmentSaveRequest; import com.ays.assignment.model.dto.response.AssignmentResponse; +import com.ays.assignment.model.dto.response.AssignmentsResponse; import com.ays.assignment.model.mapper.AssignmentToAssignmentResponseMapper; import com.ays.assignment.service.AssignmentSaveService; import com.ays.assignment.service.AssignmentService; +import com.ays.common.model.dto.response.AysPageResponse; import com.ays.common.model.dto.response.AysResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -31,21 +34,12 @@ class AssignmentController { private static final AssignmentToAssignmentResponseMapper assignmentToAssignmentResponseMapper = AssignmentToAssignmentResponseMapper.initialize(); - /** - * Saves a new assignment to the system. - * Requires ADMIN authority. - * - * @param saveRequest The request object containing the assignment data to be saved. - * @return A response object containing the saved assignment data. - */ - @PostMapping("/assignment") - @PreAuthorize("hasAnyAuthority('ADMIN')") - public AysResponse saveAssignment(@RequestBody @Valid AssignmentSaveRequest saveRequest) { - assignmentSaveService.saveAssignment(saveRequest); - return AysResponse.SUCCESS; + @GetMapping("/assignments") + @PreAuthorize(("hasAnyAuthority('ADMIN')")) + public AysResponse> getAssignments(@RequestBody @Valid AssignmentListRequest listRequest) { + return null; } - /** * Gets a user by ID. * Requires ADMIN authority. @@ -62,5 +56,19 @@ public AysResponse getAssignmentById(@PathVariable @UUID Str return AysResponse.successOf(assignmentResponse); } + /** + * Saves a new assignment to the system. + * Requires ADMIN authority. + * + * @param saveRequest The request object containing the assignment data to be saved. + * @return A response object containing the saved assignment data. + */ + @PostMapping("/assignment") + @PreAuthorize("hasAnyAuthority('ADMIN')") + public AysResponse saveAssignment(@RequestBody @Valid AssignmentSaveRequest saveRequest) { + assignmentSaveService.saveAssignment(saveRequest); + return AysResponse.SUCCESS; + } + } From 6f28d9ae0c29eaf6a70aa6a495e8d500051fbe6f Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Mon, 28 Aug 2023 23:19:37 +0300 Subject: [PATCH 06/45] Add JavaDoc for getAssignments method --- .../ays/assignment/controller/AssignmentController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/ays/assignment/controller/AssignmentController.java b/src/main/java/com/ays/assignment/controller/AssignmentController.java index 7743b500f..8cd970bd1 100644 --- a/src/main/java/com/ays/assignment/controller/AssignmentController.java +++ b/src/main/java/com/ays/assignment/controller/AssignmentController.java @@ -34,6 +34,13 @@ class AssignmentController { private static final AssignmentToAssignmentResponseMapper assignmentToAssignmentResponseMapper = AssignmentToAssignmentResponseMapper.initialize(); + /** + * Gets an Assignments list based on the specified statuses in the {@link AssignmentListRequest} + * Requires ADMIN authority + * + * @param listRequest The assignment request that contains the status filter + * @return A response object that contains the retrieved assignments' data + */ @GetMapping("/assignments") @PreAuthorize(("hasAnyAuthority('ADMIN')")) public AysResponse> getAssignments(@RequestBody @Valid AssignmentListRequest listRequest) { From f9cbacfc677a977c06164f77814b595e49b8c9cd Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 02:05:05 +0300 Subject: [PATCH 07/45] Define getAssignments in AssignmentService --- .../com/ays/assignment/service/AssignmentService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/ays/assignment/service/AssignmentService.java b/src/main/java/com/ays/assignment/service/AssignmentService.java index a3296cfa7..e51773ab5 100644 --- a/src/main/java/com/ays/assignment/service/AssignmentService.java +++ b/src/main/java/com/ays/assignment/service/AssignmentService.java @@ -2,6 +2,8 @@ import com.ays.assignment.model.Assignment; +import com.ays.assignment.model.dto.request.AssignmentListRequest; +import com.ays.common.model.AysPage; /** * Assignment Save Service to perform assignment related business operations. @@ -15,4 +17,12 @@ public interface AssignmentService { * @return Assignment */ Assignment getAssignmentById(String id); + + /** + * Get Assignments based on the specified filters in the {@link AssignmentListRequest} + * + * @param listRequest The request dto object + * @return Assignments list + */ + AysPage getAssignments(AssignmentListRequest listRequest); } From 00fe7f6f38f29e41fe451082bcc8da074baec4d5 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 02:05:25 +0300 Subject: [PATCH 08/45] Implement getAssignments in AssignmentServiceImpl --- .../service/impl/AssignmentServiceImpl.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java index aca36d5ae..5e495443e 100644 --- a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java +++ b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java @@ -1,15 +1,21 @@ package com.ays.assignment.service.impl; import com.ays.assignment.model.Assignment; +import com.ays.assignment.model.dto.request.AssignmentListRequest; import com.ays.assignment.model.entity.AssignmentEntity; import com.ays.assignment.model.mapper.AssignmentEntityToAssignmentMapper; import com.ays.assignment.repository.AssignmentRepository; import com.ays.assignment.service.AssignmentService; import com.ays.assignment.util.exception.AysAssignmentNotExistByIdException; import com.ays.auth.model.AysIdentity; +import com.ays.common.model.AysPage; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; +import java.util.List; + @Service @RequiredArgsConstructor class AssignmentServiceImpl implements AssignmentService { @@ -35,4 +41,24 @@ public Assignment getAssignmentById(String id) { return assignmentEntityToAssignmentMapper.map(assignmentEntity); } + + @Override + public AysPage getAssignments(AssignmentListRequest listRequest) { + + Specification byStatus = listRequest.toSpecification(AssignmentEntity.class); + Specification byInstitutionId = (root, query, criteriaBuilder) -> { + return criteriaBuilder.equal(root.get("institutionId"),identity.getInstitutionId()); + }; + + Page assignmentEntities = assignmentRepository + .findAll(byStatus.and(byInstitutionId),listRequest.toPageable()); + + List assignments = assignmentEntityToAssignmentMapper.map(assignmentEntities.getContent()); + + return AysPage.of( + listRequest.getFilter(), + assignmentEntities, + assignments + ); + } } From 3813c837c0ac092a2ea1f85629f14367e745b51d Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 02:07:14 +0300 Subject: [PATCH 09/45] Replacing statement lambda with expression lambda in AssignmentServiceImpl --- .../ays/assignment/service/impl/AssignmentServiceImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java index 5e495443e..6120d43ca 100644 --- a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java +++ b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java @@ -46,9 +46,8 @@ public Assignment getAssignmentById(String id) { public AysPage getAssignments(AssignmentListRequest listRequest) { Specification byStatus = listRequest.toSpecification(AssignmentEntity.class); - Specification byInstitutionId = (root, query, criteriaBuilder) -> { - return criteriaBuilder.equal(root.get("institutionId"),identity.getInstitutionId()); - }; + Specification byInstitutionId = (root, query, criteriaBuilder) -> + criteriaBuilder.equal(root.get("institutionId"),identity.getInstitutionId()); Page assignmentEntities = assignmentRepository .findAll(byStatus.and(byInstitutionId),listRequest.toPageable()); From 13120cdf56991c5410b98e2da2539190ba855528 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 02:10:44 +0300 Subject: [PATCH 10/45] JavaDoc for the getAssignments method in AssignmentServiceImpl --- .../ays/assignment/service/impl/AssignmentServiceImpl.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java index 6120d43ca..deb994e39 100644 --- a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java +++ b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java @@ -42,6 +42,12 @@ public Assignment getAssignmentById(String id) { return assignmentEntityToAssignmentMapper.map(assignmentEntity); } + /** + * Retrieves a paginated list of assignments based on the specified filters and the institution's identity. + * + * @param listRequest The request containing filters and pagination parameters. + * @return An {@link AysPage} object containing the filtered assignments. + */ @Override public AysPage getAssignments(AssignmentListRequest listRequest) { From db93be9c4e827f1299a0551cbd0af21319876e20 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 02:26:53 +0300 Subject: [PATCH 11/45] Create AssignmentToAssignmentsResponseMapper --- ...AssignmentToAssignmentsResponseMapper.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java diff --git a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java new file mode 100644 index 000000000..8a0a2152c --- /dev/null +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java @@ -0,0 +1,31 @@ +package com.ays.assignment.model.mapper; + +import com.ays.assignment.model.Assignment; +import com.ays.assignment.model.dto.response.AssignmentsResponse; +import com.ays.common.model.mapper.BaseMapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * AssignmentEntityToAssignmentMapper is an interface that defines the mapping between an {@link Assignment} and an {@link AssignmentsResponse}. + * This interface uses the MapStruct annotation @Mapper to generate an implementation of this interface at compile-time. + *

The class provides a static method {@code initialize()} that returns an instance of the generated mapper implementation. + *

The interface extends the MapStruct interface {@link BaseMapper}, which defines basic mapping methods. + * The interface adds no additional mapping methods, but simply defines the types to be used in the mapping process. + */ +public interface AssignmentToAssignmentsResponseMapper extends BaseMapper { + + @Override + @Mapping(target = "location.longitude", source = "point.coordinates.y") + @Mapping(target = "location.latitude", source = "point.coordinates.x") + AssignmentsResponse map(Assignment source); + + /** + * Initializes the mapper. + * + * @return the initialized mapper object. + */ + static AssignmentEntityToAssignmentMapper initialize() { + return Mappers.getMapper(AssignmentEntityToAssignmentMapper.class); + } +} From 08b4f64f020d553963eaf203a55b0c7ca86b0e12 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 02:29:57 +0300 Subject: [PATCH 12/45] Update initialize method in AssignmentToAssignmentsResponseMapper --- .../model/mapper/AssignmentToAssignmentsResponseMapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java index 8a0a2152c..b517fb0f5 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java @@ -25,7 +25,7 @@ public interface AssignmentToAssignmentsResponseMapper extends BaseMapper Date: Tue, 29 Aug 2023 03:14:23 +0300 Subject: [PATCH 13/45] Add lombok constructors to AssignmentListRequest & Filter --- .../dto/request/AssignmentListRequest.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index 815fefee6..d61cf4aa2 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -8,8 +8,7 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.AssertTrue; import jakarta.validation.constraints.NotNull; -import lombok.Builder; -import lombok.Data; +import lombok.*; import org.springframework.data.jpa.domain.Specification; import java.util.List; @@ -20,16 +19,21 @@ * This class extends the {@link AysPagingRequest} class and adds additional validation rules for sorting. */ @Data +@EqualsAndHashCode(callSuper = true) +@AllArgsConstructor +@NoArgsConstructor @Builder public class AssignmentListRequest extends AysPagingRequest implements AysFilteringRequest { @Valid - public Filter filter; + private Filter filter; /** * Represents a filtering configuration for assignments based on the class fields. */ @Data + @AllArgsConstructor + @NoArgsConstructor public static class Filter implements AysFiltering { @@ -70,12 +74,10 @@ public Specification toSpecification(Class clazz) { return Specification.allOf(); } - return this.filter.statuses.stream() - .map(status -> (Specification) - (root, query, criteriaBuilder) -> criteriaBuilder - .equal(root.get("status"), status)) - .reduce(Specification::or) - .orElse(null); + return this.filter.statuses.stream().map(status -> + (Specification) (root, query, criteriaBuilder) -> + criteriaBuilder.equal(root.get("status"), status)) + .reduce(Specification::or).orElse(null); } } From 6e8054be40a1c2e77e7dbf9a8e87f9d2559ca177 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 03:26:16 +0300 Subject: [PATCH 14/45] Update AssignmentToAssignmentsResponseMapper --- .../mapper/AssignmentToAssignmentsResponseMapper.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java index b517fb0f5..be0d67e6c 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java @@ -3,6 +3,7 @@ import com.ays.assignment.model.Assignment; import com.ays.assignment.model.dto.response.AssignmentsResponse; import com.ays.common.model.mapper.BaseMapper; +import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @@ -13,11 +14,13 @@ *

The interface extends the MapStruct interface {@link BaseMapper}, which defines basic mapping methods. * The interface adds no additional mapping methods, but simply defines the types to be used in the mapping process. */ + +@Mapper public interface AssignmentToAssignmentsResponseMapper extends BaseMapper { @Override - @Mapping(target = "location.longitude", source = "point.coordinates.y") - @Mapping(target = "location.latitude", source = "point.coordinates.x") + @Mapping(target = "location.longitude", source = "point.y") + @Mapping(target = "location.latitude", source = "point.x") AssignmentsResponse map(Assignment source); /** From cbe3c0c317b58f702cd297505194857d517a5824 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 03:26:42 +0300 Subject: [PATCH 15/45] Add Getter & Setter for the inner classes in AssignmentsResponse --- .../model/dto/response/AssignmentsResponse.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java b/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java index 6d1ded7bd..d9071063a 100644 --- a/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java +++ b/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java @@ -3,6 +3,8 @@ import com.ays.common.model.dto.response.BaseResponse; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; import lombok.experimental.SuperBuilder; @Data @@ -17,12 +19,16 @@ public class AssignmentsResponse extends BaseResponse { private Location location; private User user; - private static class Location { + @Getter + @Setter + public static class Location { private Double longitude; private Double latitude; } - private static class User { + @Getter + @Setter + public static class User { private String id; private String firstName; private String lastName; From 7871f43503174fb2286a69bb10b4f31f04280c96 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 03:27:29 +0300 Subject: [PATCH 16/45] Update getAssignments in AssignmentController --- .../assignment/controller/AssignmentController.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/controller/AssignmentController.java b/src/main/java/com/ays/assignment/controller/AssignmentController.java index 8cd970bd1..c03d5b6aa 100644 --- a/src/main/java/com/ays/assignment/controller/AssignmentController.java +++ b/src/main/java/com/ays/assignment/controller/AssignmentController.java @@ -6,8 +6,10 @@ import com.ays.assignment.model.dto.response.AssignmentResponse; import com.ays.assignment.model.dto.response.AssignmentsResponse; import com.ays.assignment.model.mapper.AssignmentToAssignmentResponseMapper; +import com.ays.assignment.model.mapper.AssignmentToAssignmentsResponseMapper; import com.ays.assignment.service.AssignmentSaveService; import com.ays.assignment.service.AssignmentService; +import com.ays.common.model.AysPage; import com.ays.common.model.dto.response.AysPageResponse; import com.ays.common.model.dto.response.AysResponse; import jakarta.validation.Valid; @@ -33,7 +35,7 @@ class AssignmentController { private final AssignmentService assignmentService; private static final AssignmentToAssignmentResponseMapper assignmentToAssignmentResponseMapper = AssignmentToAssignmentResponseMapper.initialize(); - + private static final AssignmentToAssignmentsResponseMapper assignmentToAssignmentsResponseMapper = AssignmentToAssignmentsResponseMapper.initialize(); /** * Gets an Assignments list based on the specified statuses in the {@link AssignmentListRequest} * Requires ADMIN authority @@ -44,7 +46,14 @@ class AssignmentController { @GetMapping("/assignments") @PreAuthorize(("hasAnyAuthority('ADMIN')")) public AysResponse> getAssignments(@RequestBody @Valid AssignmentListRequest listRequest) { - return null; + final AysPage pageOfAssignments = assignmentService.getAssignments(listRequest); + final AysPageResponse pageOfAssignmentsResponse = AysPageResponse + .builder() + .of(pageOfAssignments) + .content(assignmentToAssignmentsResponseMapper.map(pageOfAssignments.getContent())) + .filteredBy(listRequest.getFilter()) + .build(); + return AysResponse.successOf(pageOfAssignmentsResponse); } /** From 21b18360ee60b7500f7b61bf608203012e87b56c Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 15:21:37 +0300 Subject: [PATCH 17/45] Add phoneNumber filter to AssignmentListRequest --- .../dto/request/AssignmentListRequest.java | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index d61cf4aa2..1f352c270 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -2,12 +2,12 @@ import com.ays.assignment.model.enums.AssignmentStatus; import com.ays.common.model.AysFiltering; +import com.ays.common.model.AysPhoneNumber; import com.ays.common.model.dto.request.AysFilteringRequest; import com.ays.common.model.dto.request.AysPagingRequest; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.validation.Valid; import jakarta.validation.constraints.AssertTrue; -import jakarta.validation.constraints.NotNull; import lombok.*; import org.springframework.data.jpa.domain.Specification; @@ -40,9 +40,9 @@ public static class Filter implements AysFiltering { /** * List of assignment statuses used for filtering. */ - @NotNull - public List statuses; + private List statuses; + private AysPhoneNumber phoneNumber; } @@ -62,22 +62,48 @@ public boolean isSortPropertyAccepted() { /** - * Converts the request into a JPA Specification that filters assignments based on the specified statuses, - * if they are provided. + * Converts the request into a JPA Specification that filters assignments based on the specified + * statuses and phoneNumber, if they are provided. * * @param clazz the class type of the specification. * @return the generated JPA Specification based on the request filters. */ @Override public Specification toSpecification(Class clazz) { + if (this.filter == null) { return Specification.allOf(); } - return this.filter.statuses.stream().map(status -> - (Specification) (root, query, criteriaBuilder) -> - criteriaBuilder.equal(root.get("status"), status)) - .reduce(Specification::or).orElse(null); + Specification specification = Specification.where(null); + + if (this.filter.phoneNumber != null) { + + if (this.filter.phoneNumber.getLineNumber() != null) { + Specification lineNumberSpecification = (root, query, criteriaBuilder) -> + criteriaBuilder.equal(root.get("lineNumber"), this.filter.phoneNumber.getLineNumber()); + + specification = specification.and(lineNumberSpecification); + } + + if (this.filter.phoneNumber.getCountryCode() != null) { + Specification countryCodeSpecification = (root, query, criteriaBuilder) + -> criteriaBuilder.equal(root.get("countryCode"), this.filter.phoneNumber.getCountryCode()); + + specification = specification.and(countryCodeSpecification); + } + } + + if (this.filter.statuses != null) { + Specification statusSpecification = this.filter.statuses.stream().map(status -> + (Specification) (root, query, criteriaBuilder) -> + criteriaBuilder.equal(root.get("status"), status)) + .reduce(Specification::or).orElse(null); + + specification = specification.and(statusSpecification); + } + + return specification; } } From cfa373ae68af56e067da47f8e61bfc0666f89517 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 15:21:48 +0300 Subject: [PATCH 18/45] Implement the phoneNumber filter in AssignmentServiceImpl --- .../ays/assignment/service/impl/AssignmentServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java index deb994e39..697327cd5 100644 --- a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java +++ b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java @@ -51,12 +51,12 @@ public Assignment getAssignmentById(String id) { @Override public AysPage getAssignments(AssignmentListRequest listRequest) { - Specification byStatus = listRequest.toSpecification(AssignmentEntity.class); + Specification byStatusAndPhoneNumber = listRequest.toSpecification(AssignmentEntity.class); Specification byInstitutionId = (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("institutionId"),identity.getInstitutionId()); Page assignmentEntities = assignmentRepository - .findAll(byStatus.and(byInstitutionId),listRequest.toPageable()); + .findAll(byStatusAndPhoneNumber.and(byInstitutionId),listRequest.toPageable()); List assignments = assignmentEntityToAssignmentMapper.map(assignmentEntities.getContent()); From e26493b322c8d7b2a337d18774097e5f31f1602e Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 22:22:36 +0300 Subject: [PATCH 19/45] Update JavaDoc for getAssignments --- .../com/ays/assignment/controller/AssignmentController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ays/assignment/controller/AssignmentController.java b/src/main/java/com/ays/assignment/controller/AssignmentController.java index c03d5b6aa..3b751bc4e 100644 --- a/src/main/java/com/ays/assignment/controller/AssignmentController.java +++ b/src/main/java/com/ays/assignment/controller/AssignmentController.java @@ -36,12 +36,14 @@ class AssignmentController { private static final AssignmentToAssignmentResponseMapper assignmentToAssignmentResponseMapper = AssignmentToAssignmentResponseMapper.initialize(); private static final AssignmentToAssignmentsResponseMapper assignmentToAssignmentsResponseMapper = AssignmentToAssignmentsResponseMapper.initialize(); + /** - * Gets an Assignments list based on the specified statuses in the {@link AssignmentListRequest} + * Gets an Assignments list based on the specified filters in the {@link AssignmentListRequest} * Requires ADMIN authority * * @param listRequest The assignment request that contains the status filter * @return A response object that contains the retrieved assignments' data + * @see AssignmentListRequest */ @GetMapping("/assignments") @PreAuthorize(("hasAnyAuthority('ADMIN')")) From 62efd396ffdd286f9cb9e7df120cd30b83f02717 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 22:22:55 +0300 Subject: [PATCH 20/45] Add if status empty check --- .../ays/assignment/model/dto/request/AssignmentListRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index 1f352c270..3af2b7f98 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -94,7 +94,7 @@ public Specification toSpecification(Class clazz) { } } - if (this.filter.statuses != null) { + if (this.filter.statuses != null && !this.filter.statuses.isEmpty()) { Specification statusSpecification = this.filter.statuses.stream().map(status -> (Specification) (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("status"), status)) From ac6422825f3732857290f597c751af4c19c93d3a Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 22:23:56 +0300 Subject: [PATCH 21/45] Fixed typo --- .../com/ays/assignment/controller/AssignmentController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ays/assignment/controller/AssignmentController.java b/src/main/java/com/ays/assignment/controller/AssignmentController.java index 3b751bc4e..0739acd7e 100644 --- a/src/main/java/com/ays/assignment/controller/AssignmentController.java +++ b/src/main/java/com/ays/assignment/controller/AssignmentController.java @@ -46,7 +46,7 @@ class AssignmentController { * @see AssignmentListRequest */ @GetMapping("/assignments") - @PreAuthorize(("hasAnyAuthority('ADMIN')")) + @PreAuthorize("hasAnyAuthority('ADMIN')") public AysResponse> getAssignments(@RequestBody @Valid AssignmentListRequest listRequest) { final AysPage pageOfAssignments = assignmentService.getAssignments(listRequest); final AysPageResponse pageOfAssignmentsResponse = AysPageResponse From 50adc5bf4458e4fe3ebe76b7addff24875148cc5 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 22:39:26 +0300 Subject: [PATCH 22/45] Create AssignmentListRequestBuilder --- .../request/AssignmentListRequestBuilder.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java diff --git a/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java b/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java new file mode 100644 index 000000000..e61a40c3f --- /dev/null +++ b/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java @@ -0,0 +1,43 @@ +package com.ays.assignment.model.dto.request; + +import com.ays.assignment.model.enums.AssignmentStatus; +import com.ays.common.model.AysPhoneNumberBuilder; +import com.ays.common.model.TestDataBuilder; + +import java.util.List; + +public class AssignmentListRequestBuilder extends TestDataBuilder { + + public AssignmentListRequestBuilder() { + super(AssignmentListRequest.class); + } + + public AssignmentListRequestBuilder withStatus() { + + data.setFilter(new AssignmentListRequest.Filter(List.of(AssignmentStatus.AVAILABLE, AssignmentStatus.ASSIGNED) + , null)); + + return this; + } + + public AssignmentListRequestBuilder withPhoneNumber() { + + AysPhoneNumberBuilder phoneNumberBuilder = new AysPhoneNumberBuilder().withValidFields(); + + data.setFilter(new AssignmentListRequest.Filter(null + , phoneNumberBuilder.build())); + + return this; + } + + public AssignmentListRequestBuilder withPhoneNumberAndStatus() { + + AysPhoneNumberBuilder phoneNumberBuilder = new AysPhoneNumberBuilder().withValidFields(); + + data.setFilter(new AssignmentListRequest.Filter(List.of(AssignmentStatus.AVAILABLE, AssignmentStatus.ASSIGNED) + , phoneNumberBuilder.build())); + + return this; + } + +} From 4260cae9d281b96b07df0fa887a0c45c7496eeb9 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 23:43:37 +0300 Subject: [PATCH 23/45] Update AssignmentListRequestBuilder --- .../request/AssignmentListRequestBuilder.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java b/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java index e61a40c3f..b36fa0e7e 100644 --- a/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java +++ b/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java @@ -1,8 +1,8 @@ package com.ays.assignment.model.dto.request; import com.ays.assignment.model.enums.AssignmentStatus; -import com.ays.common.model.AysPhoneNumberBuilder; -import com.ays.common.model.TestDataBuilder; +import com.ays.common.model.*; +import com.ays.user.model.dto.request.UserListRequestBuilder; import java.util.List; @@ -12,6 +12,27 @@ public AssignmentListRequestBuilder() { super(AssignmentListRequest.class); } + public AssignmentListRequestBuilder withValidValuesForStatus() { + return this + .withStatus() + .withPagination(new AysPagingBuilder().withValidValues().build()) + .withSort(null); + } + + public AssignmentListRequestBuilder withValidValuesForPhoneNumber() { + return this + .withPhoneNumber() + .withPagination(new AysPagingBuilder().withValidValues().build()) + .withSort(null); + } + + public AssignmentListRequestBuilder withValidValues() { + return this + .withPhoneNumberAndStatus() + .withPagination(new AysPagingBuilder().withValidValues().build()) + .withSort(null); + } + public AssignmentListRequestBuilder withStatus() { data.setFilter(new AssignmentListRequest.Filter(List.of(AssignmentStatus.AVAILABLE, AssignmentStatus.ASSIGNED) @@ -40,4 +61,13 @@ public AssignmentListRequestBuilder withPhoneNumberAndStatus() { return this; } + public AssignmentListRequestBuilder withPagination(AysPaging aysPaging) { + data.setPagination(aysPaging); + return this; + } + + public AssignmentListRequestBuilder withSort(List sorting) { + data.setSort(sorting); + return this; + } } From 88aebbc02f09f6806720f809b86def70581a1c19 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 23:44:23 +0300 Subject: [PATCH 24/45] Handled givenAssignmentListRequest_whenAssignmentStatusIsAvailable_thenReturnAysPageAssignmentResponse --- .../impl/AssignmentServiceImplTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java index 0a5394979..ddd14f85c 100644 --- a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java +++ b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java @@ -2,19 +2,29 @@ import com.ays.AbstractUnitTest; import com.ays.assignment.model.Assignment; +import com.ays.assignment.model.dto.request.AssignmentListRequest; +import com.ays.assignment.model.dto.request.AssignmentListRequestBuilder; import com.ays.assignment.model.entity.AssignmentEntity; import com.ays.assignment.model.entity.AssignmentEntityBuilder; import com.ays.assignment.model.mapper.AssignmentEntityToAssignmentMapper; import com.ays.assignment.repository.AssignmentRepository; import com.ays.assignment.util.exception.AysAssignmentNotExistByIdException; import com.ays.auth.model.AysIdentity; +import com.ays.common.model.AysPage; +import com.ays.common.model.AysPageBuilder; import com.ays.common.util.AysRandomUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import java.util.Collections; +import java.util.List; import java.util.Optional; @@ -93,4 +103,33 @@ void givenAssignmentId_whenAssignmentNotFound_thenThrowAysAssignmentNotExistById Mockito.verify(identity, Mockito.times(1)) .getInstitutionId(); } + + @Test + void givenAssignmentListRequest_whenAssignmentStatusIsAvailable_thenReturnAysPageAssignmentResponse() { + + // Given + String mockInstitutionId = AysRandomUtil.generateUUID(); + + AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder().withValidValuesForStatus().build(); + + List mockAssignmentEntities = Collections.singletonList(new AssignmentEntityBuilder() + .withValidFields().build()); + Page mockPageAssignmentEntities = new PageImpl<>(mockAssignmentEntities); + + List mockAssignments = ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER.map(mockAssignmentEntities); + AysPage mockAysPageAssignments = AysPage.of(assignmentListRequest.getFilter(), mockPageAssignmentEntities, mockAssignments); + + // When + Mockito.when(identity.getInstitutionId()).thenReturn(mockInstitutionId); + Mockito.when(assignmentRepository.findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class))) + .thenReturn(mockPageAssignmentEntities); + + // Then + AysPage aysPageAssignment = assignmentService.getAssignments(assignmentListRequest); + + AysPageBuilder.assertEquals(mockAysPageAssignments, aysPageAssignment); + + Mockito.verify(assignmentRepository, Mockito.times(1)) + .findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class)); + } } \ No newline at end of file From dfe780d2f4b6f240330d318b1a380263d335c943 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 29 Aug 2023 23:49:04 +0300 Subject: [PATCH 25/45] Handled givenAssignmentListRequest_whenPhoneNumberIsAvailable_thenReturnAysPageAssignmentResponse & givenAssignmentListRequest_whenAssignmentStatusAndPhoneNumberAvailable_thenReturnAysPageAssignmentResponse --- .../impl/AssignmentServiceImplTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java index ddd14f85c..0ab75b223 100644 --- a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java +++ b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java @@ -132,4 +132,62 @@ void givenAssignmentListRequest_whenAssignmentStatusIsAvailable_thenReturnAysPag Mockito.verify(assignmentRepository, Mockito.times(1)) .findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class)); } + + @Test + void givenAssignmentListRequest_whenPhoneNumberIsAvailable_thenReturnAysPageAssignmentResponse() { + + // Given + String mockInstitutionId = AysRandomUtil.generateUUID(); + + AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder().withValidValuesForPhoneNumber().build(); + + List mockAssignmentEntities = Collections.singletonList(new AssignmentEntityBuilder() + .withValidFields().build()); + Page mockPageAssignmentEntities = new PageImpl<>(mockAssignmentEntities); + + List mockAssignments = ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER.map(mockAssignmentEntities); + AysPage mockAysPageAssignments = AysPage.of(assignmentListRequest.getFilter(), mockPageAssignmentEntities, mockAssignments); + + // When + Mockito.when(identity.getInstitutionId()).thenReturn(mockInstitutionId); + Mockito.when(assignmentRepository.findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class))) + .thenReturn(mockPageAssignmentEntities); + + // Then + AysPage aysPageAssignment = assignmentService.getAssignments(assignmentListRequest); + + AysPageBuilder.assertEquals(mockAysPageAssignments, aysPageAssignment); + + Mockito.verify(assignmentRepository, Mockito.times(1)) + .findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class)); + } + + @Test + void givenAssignmentListRequest_whenAssignmentStatusAndPhoneNumberAvailable_thenReturnAysPageAssignmentResponse() { + + // Given + String mockInstitutionId = AysRandomUtil.generateUUID(); + + AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder().withValidValuesForPhoneNumber().build(); + + List mockAssignmentEntities = Collections.singletonList(new AssignmentEntityBuilder() + .withValidFields().build()); + Page mockPageAssignmentEntities = new PageImpl<>(mockAssignmentEntities); + + List mockAssignments = ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER.map(mockAssignmentEntities); + AysPage mockAysPageAssignments = AysPage.of(assignmentListRequest.getFilter(), mockPageAssignmentEntities, mockAssignments); + + // When + Mockito.when(identity.getInstitutionId()).thenReturn(mockInstitutionId); + Mockito.when(assignmentRepository.findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class))) + .thenReturn(mockPageAssignmentEntities); + + // Then + AysPage aysPageAssignment = assignmentService.getAssignments(assignmentListRequest); + + AysPageBuilder.assertEquals(mockAysPageAssignments, aysPageAssignment); + + Mockito.verify(assignmentRepository, Mockito.times(1)) + .findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class)); + } } \ No newline at end of file From f5139014011cb67c28e7aa005189b7d78b3db1c0 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 30 Aug 2023 15:13:26 +0300 Subject: [PATCH 26/45] Add isEmpty check for the fields countryCode & lineNumber in AssignmentListRequest - toSpecification --- .../assignment/model/dto/request/AssignmentListRequest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index 3af2b7f98..0f99247be 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -79,14 +79,14 @@ public Specification toSpecification(Class clazz) { if (this.filter.phoneNumber != null) { - if (this.filter.phoneNumber.getLineNumber() != null) { + if (this.filter.phoneNumber.getLineNumber() != null && !this.filter.phoneNumber.getLineNumber().isEmpty()) { Specification lineNumberSpecification = (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("lineNumber"), this.filter.phoneNumber.getLineNumber()); specification = specification.and(lineNumberSpecification); } - if (this.filter.phoneNumber.getCountryCode() != null) { + if (this.filter.phoneNumber.getCountryCode() != null && !this.filter.phoneNumber.getCountryCode().isEmpty()) { Specification countryCodeSpecification = (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("countryCode"), this.filter.phoneNumber.getCountryCode()); From 9360480e81ab1f3f973d5828cc4c56447d28d6dc Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 30 Aug 2023 16:16:55 +0300 Subject: [PATCH 27/45] Handle givenValidAssignmentListRequest_whenAssignmentsFound_thenReturnAysPageResponseOfAssignmentsResponse --- .../dto/request/AssignmentListRequest.java | 7 +-- .../controller/AssignmentControllerTest.java | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index 0f99247be..9a4a59682 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -18,8 +18,8 @@ * Represents a request object for fetching a list of user assignment with pagination,sorting and filtering options * This class extends the {@link AysPagingRequest} class and adds additional validation rules for sorting. */ -@Data -@EqualsAndHashCode(callSuper = true) +@Getter +@Setter @AllArgsConstructor @NoArgsConstructor @Builder @@ -31,7 +31,8 @@ public class AssignmentListRequest extends AysPagingRequest implements AysFilter /** * Represents a filtering configuration for assignments based on the class fields. */ - @Data + @Getter + @Setter @AllArgsConstructor @NoArgsConstructor public static class Filter implements AysFiltering { diff --git a/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java b/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java index b0d87567c..6d99ab63a 100644 --- a/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java +++ b/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java @@ -3,13 +3,22 @@ import com.ays.AbstractRestControllerTest; import com.ays.assignment.model.Assignment; import com.ays.assignment.model.AssignmentBuilder; +import com.ays.assignment.model.dto.request.AssignmentListRequest; +import com.ays.assignment.model.dto.request.AssignmentListRequestBuilder; import com.ays.assignment.model.dto.request.AssignmentSaveRequest; import com.ays.assignment.model.dto.request.AssignmentSaveRequestBuilder; import com.ays.assignment.model.dto.response.AssignmentResponse; +import com.ays.assignment.model.dto.response.AssignmentsResponse; +import com.ays.assignment.model.entity.AssignmentEntity; +import com.ays.assignment.model.entity.AssignmentEntityBuilder; +import com.ays.assignment.model.mapper.AssignmentEntityToAssignmentMapper; import com.ays.assignment.model.mapper.AssignmentToAssignmentResponseMapper; +import com.ays.assignment.model.mapper.AssignmentToAssignmentsResponseMapper; import com.ays.assignment.service.AssignmentSaveService; import com.ays.assignment.service.AssignmentService; +import com.ays.common.model.AysPage; import com.ays.common.model.AysPhoneNumberBuilder; +import com.ays.common.model.dto.response.AysPageResponse; import com.ays.common.model.dto.response.AysResponse; import com.ays.common.model.dto.response.AysResponseBuilder; import com.ays.common.util.AysRandomUtil; @@ -19,9 +28,13 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import java.util.List; + class AssignmentControllerTest extends AbstractRestControllerTest { @@ -35,7 +48,9 @@ class AssignmentControllerTest extends AbstractRestControllerTest { private static final AssignmentToAssignmentResponseMapper ASSIGNMENT_TO_ASSIGNMENT_RESPONSE_MAPPER = AssignmentToAssignmentResponseMapper.initialize(); + private static final AssignmentEntityToAssignmentMapper ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER = AssignmentEntityToAssignmentMapper.initialize(); + private static final AssignmentToAssignmentsResponseMapper ASSIGNMENT_TO_ASSIGNMENTS_RESPONSE_MAPPER = AssignmentToAssignmentsResponseMapper.initialize(); @Test void givenValidAssignmentSaveRequest_whenAssignmentSaved_thenReturnAssignmentSavedResponse() throws Exception { // Given @@ -157,5 +172,39 @@ void givenValidAssignmentId_whenUnauthorizedForGettingAssignmentById_thenReturnA .doesNotExist()); } + @Test + void givenValidAssignmentListRequest_whenAssignmentsFound_thenReturnAysPageResponseOfAssignmentsResponse() throws Exception { + + // Given + AssignmentListRequest mockListRequest = new AssignmentListRequestBuilder().withValidValues().build(); + + // When + List mockAssignmentEntities = AssignmentEntityBuilder.generateValidAssignmentEntities(1); + Page mockPageAssignmentEntities = new PageImpl<>(mockAssignmentEntities); + List mockAssignments = ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER.map(mockAssignmentEntities); + AysPage mockAysPageOfAssignments = AysPage + .of(mockListRequest.getFilter(),mockPageAssignmentEntities,mockAssignments); + + Mockito.when(assignmentService.getAssignments(mockListRequest)).thenReturn(mockAysPageOfAssignments); + // Then + String endpoint = BASE_PATH.concat("/assignments"); + List mockAssignmentsResponse = ASSIGNMENT_TO_ASSIGNMENTS_RESPONSE_MAPPER.map(mockAssignments); + AysPageResponse pageOfAssignmentsResponse = AysPageResponse.builder() + .of(mockAysPageOfAssignments) + .content(mockAssignmentsResponse) + .build(); + + AysResponse> mockAysResponse = AysResponse.successOf(pageOfAssignmentsResponse); + mockMvc.perform(AysMockMvcRequestBuilders + .get(endpoint,mockAdminUserToken.getAccessToken(),mockListRequest)) + .andDo(MockMvcResultHandlers.print()) + .andExpect(AysMockResultMatchersBuilders.status().isOk()) + .andExpect(AysMockResultMatchersBuilders.time().isNotEmpty()) + .andExpect(AysMockResultMatchersBuilders.httpStatus().value(mockAysResponse.getHttpStatus().getReasonPhrase())) + .andExpect(AysMockResultMatchersBuilders.isSuccess().value(mockAysResponse.getIsSuccess())) + .andExpect(AysMockResultMatchersBuilders.response().isNotEmpty()); + + Mockito.verify(assignmentService,Mockito.times(1)).getAssignments(mockListRequest); + } } From 62d3a53e814586cdc17ee1a85591520be6db243f Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Fri, 1 Sep 2023 01:42:48 +0300 Subject: [PATCH 28/45] Handled givenValidAssignmentListRequest_whenUserUnauthorizedForListing_thenReturnAccessDeniedException --- .../controller/AssignmentControllerTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java b/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java index 6d99ab63a..733465f59 100644 --- a/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java +++ b/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java @@ -207,4 +207,25 @@ void givenValidAssignmentListRequest_whenAssignmentsFound_thenReturnAysPageRespo Mockito.verify(assignmentService,Mockito.times(1)).getAssignments(mockListRequest); } + + @Test + void givenValidAssignmentListRequest_whenUserUnauthorizedForListing_thenReturnAccessDeniedException() throws Exception{ + + // Given + AssignmentListRequest mockListRequest = new AssignmentListRequestBuilder().withValidValues().build(); + + // Then + String endpoint = BASE_PATH.concat("/assignments"); + AysResponse mockResponse = AysResponseBuilder.FORBIDDEN; + + mockMvc.perform(AysMockMvcRequestBuilders + .get(endpoint,mockUserToken.getAccessToken(),mockListRequest)) + .andDo(MockMvcResultHandlers.print()) + .andExpect(AysMockResultMatchersBuilders.status().isForbidden()) + .andExpect(AysMockResultMatchersBuilders.time().isNotEmpty()) + .andExpect(AysMockResultMatchersBuilders.httpStatus().value(mockResponse.getHttpStatus().name())) + .andExpect(AysMockResultMatchersBuilders.isSuccess().value(mockResponse.getIsSuccess())) + .andExpect(AysMockResultMatchersBuilders.response().doesNotExist()); + + } } From ca3a54721b180c9ba4b4c2e1af3e82556f02d366 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Fri, 1 Sep 2023 01:45:07 +0300 Subject: [PATCH 29/45] Changed GET to POST in the method "getAssignments" --- .../com/ays/assignment/controller/AssignmentController.java | 2 +- .../ays/assignment/controller/AssignmentControllerTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ays/assignment/controller/AssignmentController.java b/src/main/java/com/ays/assignment/controller/AssignmentController.java index 0739acd7e..6567127c9 100644 --- a/src/main/java/com/ays/assignment/controller/AssignmentController.java +++ b/src/main/java/com/ays/assignment/controller/AssignmentController.java @@ -45,7 +45,7 @@ class AssignmentController { * @return A response object that contains the retrieved assignments' data * @see AssignmentListRequest */ - @GetMapping("/assignments") + @PostMapping("/assignments") @PreAuthorize("hasAnyAuthority('ADMIN')") public AysResponse> getAssignments(@RequestBody @Valid AssignmentListRequest listRequest) { final AysPage pageOfAssignments = assignmentService.getAssignments(listRequest); diff --git a/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java b/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java index 733465f59..e4203df0f 100644 --- a/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java +++ b/src/test/java/com/ays/assignment/controller/AssignmentControllerTest.java @@ -197,7 +197,7 @@ void givenValidAssignmentListRequest_whenAssignmentsFound_thenReturnAysPageRespo AysResponse> mockAysResponse = AysResponse.successOf(pageOfAssignmentsResponse); mockMvc.perform(AysMockMvcRequestBuilders - .get(endpoint,mockAdminUserToken.getAccessToken(),mockListRequest)) + .post(endpoint,mockAdminUserToken.getAccessToken(),mockListRequest)) .andDo(MockMvcResultHandlers.print()) .andExpect(AysMockResultMatchersBuilders.status().isOk()) .andExpect(AysMockResultMatchersBuilders.time().isNotEmpty()) @@ -219,7 +219,7 @@ void givenValidAssignmentListRequest_whenUserUnauthorizedForListing_thenReturnAc AysResponse mockResponse = AysResponseBuilder.FORBIDDEN; mockMvc.perform(AysMockMvcRequestBuilders - .get(endpoint,mockUserToken.getAccessToken(),mockListRequest)) + .post(endpoint,mockUserToken.getAccessToken(),mockListRequest)) .andDo(MockMvcResultHandlers.print()) .andExpect(AysMockResultMatchersBuilders.status().isForbidden()) .andExpect(AysMockResultMatchersBuilders.time().isNotEmpty()) From 9a4fdc712c94aa5c508fc24f890c9c50a911bdda Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Fri, 1 Sep 2023 01:46:17 +0300 Subject: [PATCH 30/45] Resolved the latitude & longitude mistake --- .../model/mapper/AssignmentToAssignmentsResponseMapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java index be0d67e6c..79a94064c 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java @@ -19,8 +19,8 @@ public interface AssignmentToAssignmentsResponseMapper extends BaseMapper { @Override - @Mapping(target = "location.longitude", source = "point.y") - @Mapping(target = "location.latitude", source = "point.x") + @Mapping(target = "location.longitude", source = "point.x") + @Mapping(target = "location.latitude", source = "point.y") AssignmentsResponse map(Assignment source); /** From e9c0e296cb6eb73254736d8c9bbb99a8c80587fb Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Fri, 1 Sep 2023 20:46:44 +0300 Subject: [PATCH 31/45] Add End-To-End tests --- .../controller/AssignmentSystemTest.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/src/test/java/com/ays/assignment/controller/AssignmentSystemTest.java b/src/test/java/com/ays/assignment/controller/AssignmentSystemTest.java index 7dadeb29d..fd342b0f5 100644 --- a/src/test/java/com/ays/assignment/controller/AssignmentSystemTest.java +++ b/src/test/java/com/ays/assignment/controller/AssignmentSystemTest.java @@ -3,11 +3,18 @@ import com.ays.AbstractSystemTest; import com.ays.assignment.model.Assignment; import com.ays.assignment.model.AssignmentBuilder; +import com.ays.assignment.model.dto.request.AssignmentListRequest; +import com.ays.assignment.model.dto.request.AssignmentListRequestBuilder; import com.ays.assignment.model.dto.request.AssignmentSaveRequest; import com.ays.assignment.model.dto.request.AssignmentSaveRequestBuilder; import com.ays.assignment.model.dto.response.AssignmentResponse; +import com.ays.assignment.model.entity.AssignmentEntity; +import com.ays.assignment.model.entity.AssignmentEntityBuilder; +import com.ays.assignment.model.mapper.AssignmentEntityToAssignmentMapper; import com.ays.assignment.model.mapper.AssignmentToAssignmentResponseMapper; +import com.ays.common.model.AysPage; import com.ays.common.model.AysPhoneNumberBuilder; +import com.ays.common.model.dto.response.AysPageResponse; import com.ays.common.model.dto.response.AysResponse; import com.ays.common.model.dto.response.AysResponseBuilder; import com.ays.common.util.AysRandomUtil; @@ -16,15 +23,20 @@ import com.ays.util.AysMockResultMatchersBuilders; import com.ays.util.AysTestData; import org.junit.jupiter.api.Test; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import java.util.List; + class AssignmentSystemTest extends AbstractSystemTest { private static final String BASE_PATH = "/api/v1"; private static final AssignmentToAssignmentResponseMapper ASSIGNMENT_TO_ASSIGNMENT_RESPONSE_MAPPER = AssignmentToAssignmentResponseMapper.initialize(); + private static final AssignmentEntityToAssignmentMapper ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER = AssignmentEntityToAssignmentMapper.initialize(); @Test void givenValidAssignmentSaveRequest_whenAssignmentSaved_thenReturnAssignmentSavedResponse() throws Exception { @@ -140,4 +152,69 @@ void givenValidAssignmentId_whenUnauthorizedForGettingAssignmentById_thenReturnA .doesNotExist()); } + @Test + void givenValidAssignmentListRequest_whenAssignmentsFound_thenReturnAssignmentsResponse() throws Exception { + + // Given + AssignmentListRequest listRequest = new AssignmentListRequestBuilder().withValidValues().build(); + + List assignmentEntities = AssignmentEntityBuilder.generateValidAssignmentEntities(1); + Page pageOfAssignmentEntities = new PageImpl<>(assignmentEntities); + List assignments = ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER.map(assignmentEntities); + AysPage aysPageOfAssignments = AysPage.of(pageOfAssignmentEntities,assignments); + AysPageResponse aysPageResponseOfAssignments = AysPageResponse.builder() + .of(aysPageOfAssignments).build(); + + // Then + String endpoint = BASE_PATH.concat("/assignments"); + MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders + .post(endpoint,adminUserTokenOne.getAccessToken(),listRequest); + + AysResponse> response = AysResponse.successOf(aysPageResponseOfAssignments); + + mockMvc.perform(mockHttpServletRequestBuilder) + .andDo(MockMvcResultHandlers.print()) + .andExpect(AysMockResultMatchersBuilders.status().isOk()) + .andExpect(AysMockResultMatchersBuilders.time() + .isNotEmpty()) + .andExpect(AysMockResultMatchersBuilders.httpStatus() + .value(response.getHttpStatus().name())) + .andExpect(AysMockResultMatchersBuilders.isSuccess() + .value(response.getIsSuccess())) + .andExpect(AysMockResultMatchersBuilders.response() + .isNotEmpty()); + } + + @Test + void givenValidAssignmentListRequest_whenUserUnauthorizedForListing_thenReturnAccessDeniedException() throws Exception { + + // Given + AssignmentListRequest listRequest = new AssignmentListRequestBuilder().withValidValues().build(); + + List assignmentEntities = AssignmentEntityBuilder.generateValidAssignmentEntities(1); + Page pageOfAssignmentEntities = new PageImpl<>(assignmentEntities); + List assignments = ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER.map(assignmentEntities); + AysPage aysPageOfAssignments = AysPage.of(pageOfAssignmentEntities,assignments); + AysPageResponse aysPageResponseOfAssignments = AysPageResponse.builder() + .of(aysPageOfAssignments).build(); + + // Then + String endpoint = BASE_PATH.concat("/assignments"); + MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders + .post(endpoint,userTokenOne.getAccessToken(),listRequest); + + AysResponse response = AysResponseBuilder.FORBIDDEN; + + mockMvc.perform(mockHttpServletRequestBuilder) + .andDo(MockMvcResultHandlers.print()) + .andExpect(AysMockResultMatchersBuilders.status().isForbidden()) + .andExpect(AysMockResultMatchersBuilders.time() + .isNotEmpty()) + .andExpect(AysMockResultMatchersBuilders.httpStatus() + .value(response.getHttpStatus().name())) + .andExpect(AysMockResultMatchersBuilders.isSuccess() + .value(response.getIsSuccess())) + .andExpect(AysMockResultMatchersBuilders.response() + .doesNotExist()); + } } From a97a0ce7fb3cd5397e2b979892433704e184779f Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Sat, 2 Sep 2023 23:02:55 +0300 Subject: [PATCH 32/45] AssignmentSystemTest Update --- .../ays/assignment/controller/AssignmentSystemTest.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/test/java/com/ays/assignment/controller/AssignmentSystemTest.java b/src/test/java/com/ays/assignment/controller/AssignmentSystemTest.java index fd342b0f5..102aa687c 100644 --- a/src/test/java/com/ays/assignment/controller/AssignmentSystemTest.java +++ b/src/test/java/com/ays/assignment/controller/AssignmentSystemTest.java @@ -191,13 +191,6 @@ void givenValidAssignmentListRequest_whenUserUnauthorizedForListing_thenReturnAc // Given AssignmentListRequest listRequest = new AssignmentListRequestBuilder().withValidValues().build(); - List assignmentEntities = AssignmentEntityBuilder.generateValidAssignmentEntities(1); - Page pageOfAssignmentEntities = new PageImpl<>(assignmentEntities); - List assignments = ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER.map(assignmentEntities); - AysPage aysPageOfAssignments = AysPage.of(pageOfAssignmentEntities,assignments); - AysPageResponse aysPageResponseOfAssignments = AysPageResponse.builder() - .of(aysPageOfAssignments).build(); - // Then String endpoint = BASE_PATH.concat("/assignments"); MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders From b5d18d5018cc6753ef9076e99e8d0d7e6134f931 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Sat, 2 Sep 2023 23:06:25 +0300 Subject: [PATCH 33/45] Fixed AssignmentToAssignmentResponseMapper --- .../model/mapper/AssignmentToAssignmentResponseMapper.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java index 2739a28f7..0175c4fca 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java @@ -2,8 +2,10 @@ import com.ays.assignment.model.Assignment; import com.ays.assignment.model.dto.response.AssignmentResponse; +import com.ays.assignment.model.dto.response.AssignmentsResponse; import com.ays.common.model.mapper.BaseMapper; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; /** @@ -16,6 +18,11 @@ @Mapper public interface AssignmentToAssignmentResponseMapper extends BaseMapper { + @Override + @Mapping(target = "longitude", source = "point.x") + @Mapping(target = "latitude", source = "point.y") + AssignmentResponse map(Assignment source); + /** * Initializes the mapper. * From 354b5b27d0a635d6105b96ed9711fdc282956bab Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 5 Sep 2023 19:26:48 +0300 Subject: [PATCH 34/45] Replace AysPhoneNumber with an inner class "PhoneNumber" & validate --- .../model/dto/request/AssignmentListRequest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index 9a4a59682..0248043d8 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -2,12 +2,12 @@ import com.ays.assignment.model.enums.AssignmentStatus; import com.ays.common.model.AysFiltering; -import com.ays.common.model.AysPhoneNumber; import com.ays.common.model.dto.request.AysFilteringRequest; import com.ays.common.model.dto.request.AysPagingRequest; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.validation.Valid; import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.Digits; import lombok.*; import org.springframework.data.jpa.domain.Specification; @@ -43,9 +43,20 @@ public static class Filter implements AysFiltering { */ private List statuses; - private AysPhoneNumber phoneNumber; + @Valid + private PhoneNumber phoneNumber; } + @Getter + @Setter + public static class PhoneNumber { + + @Digits(integer = 7, fraction = 0, message = "MUST BE 7-DIGIT NUMBER") + private String countryCode; + + @Digits(integer = 13, fraction = 0, message = "MUST BE 13-DIGIT NUMBER") + private String lineNumber; + } /** * Overrides the {@link AysPagingRequest#isSortPropertyAccepted()} method to validate sorting options From d48210cfcc4981d659f4708c48926951a2c46a70 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Tue, 5 Sep 2023 19:29:15 +0300 Subject: [PATCH 35/45] Add AssignmentStatus to AssignmentsResponse --- .../ays/assignment/model/dto/response/AssignmentsResponse.java | 2 ++ .../model/mapper/AssignmentToAssignmentsResponseMapper.java | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java b/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java index d9071063a..bb9038a3e 100644 --- a/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java +++ b/src/main/java/com/ays/assignment/model/dto/response/AssignmentsResponse.java @@ -1,5 +1,6 @@ package com.ays.assignment.model.dto.response; +import com.ays.assignment.model.enums.AssignmentStatus; import com.ays.common.model.dto.response.BaseResponse; import lombok.Data; import lombok.EqualsAndHashCode; @@ -13,6 +14,7 @@ public class AssignmentsResponse extends BaseResponse { private String id; + private AssignmentStatus status; private String description; private String firstName; private String lastName; diff --git a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java index 79a94064c..2ead79619 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java @@ -21,6 +21,7 @@ public interface AssignmentToAssignmentsResponseMapper extends BaseMapper Date: Tue, 5 Sep 2023 20:00:18 +0300 Subject: [PATCH 36/45] Fixed AysPhoneNumber bug in AssignmentListRequestBuilder --- .../model/dto/request/AssignmentListRequest.java | 2 ++ .../dto/request/AssignmentListRequestBuilder.java | 13 ++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index 0248043d8..83df06a00 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -49,6 +49,8 @@ public static class Filter implements AysFiltering { @Getter @Setter + @AllArgsConstructor + @NoArgsConstructor public static class PhoneNumber { @Digits(integer = 7, fraction = 0, message = "MUST BE 7-DIGIT NUMBER") diff --git a/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java b/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java index b36fa0e7e..997402d49 100644 --- a/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java +++ b/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java @@ -1,8 +1,10 @@ package com.ays.assignment.model.dto.request; import com.ays.assignment.model.enums.AssignmentStatus; -import com.ays.common.model.*; -import com.ays.user.model.dto.request.UserListRequestBuilder; +import com.ays.common.model.AysPaging; +import com.ays.common.model.AysPagingBuilder; +import com.ays.common.model.AysSorting; +import com.ays.common.model.TestDataBuilder; import java.util.List; @@ -43,20 +45,17 @@ public AssignmentListRequestBuilder withStatus() { public AssignmentListRequestBuilder withPhoneNumber() { - AysPhoneNumberBuilder phoneNumberBuilder = new AysPhoneNumberBuilder().withValidFields(); data.setFilter(new AssignmentListRequest.Filter(null - , phoneNumberBuilder.build())); + , new AssignmentListRequest.PhoneNumber("90", "1234567890"))); return this; } public AssignmentListRequestBuilder withPhoneNumberAndStatus() { - AysPhoneNumberBuilder phoneNumberBuilder = new AysPhoneNumberBuilder().withValidFields(); - data.setFilter(new AssignmentListRequest.Filter(List.of(AssignmentStatus.AVAILABLE, AssignmentStatus.ASSIGNED) - , phoneNumberBuilder.build())); + , new AssignmentListRequest.PhoneNumber("90", "1234567890"))); return this; } From 0bc891ee83512f0615017fa916b919d006dadecb Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 14:00:36 +0300 Subject: [PATCH 37/45] Optimize status null & empty check --- .../assignment/model/dto/request/AssignmentListRequest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index 83df06a00..a9e32b226 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -9,6 +9,7 @@ import jakarta.validation.constraints.AssertTrue; import jakarta.validation.constraints.Digits; import lombok.*; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.data.jpa.domain.Specification; import java.util.List; @@ -108,7 +109,7 @@ public Specification toSpecification(Class clazz) { } } - if (this.filter.statuses != null && !this.filter.statuses.isEmpty()) { + if (!CollectionUtils.isEmpty(this.filter.statuses)) { Specification statusSpecification = this.filter.statuses.stream().map(status -> (Specification) (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("status"), status)) From a5f60402517bb42ce73dff43641d0fa074a26922 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 14:06:15 +0300 Subject: [PATCH 38/45] Remove unnecessary status mapping in AssignmentToAssignmentsResponseMapper --- .../model/mapper/AssignmentToAssignmentsResponseMapper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java index 2ead79619..79a94064c 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentsResponseMapper.java @@ -21,7 +21,6 @@ public interface AssignmentToAssignmentsResponseMapper extends BaseMapper Date: Wed, 6 Sep 2023 14:11:48 +0300 Subject: [PATCH 39/45] Replace Collections.singletonList with List.of --- .../assignment/service/impl/AssignmentServiceImplTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java index 0ab75b223..0d6e0ea8e 100644 --- a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java +++ b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java @@ -23,7 +23,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; -import java.util.Collections; import java.util.List; import java.util.Optional; @@ -112,7 +111,7 @@ void givenAssignmentListRequest_whenAssignmentStatusIsAvailable_thenReturnAysPag AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder().withValidValuesForStatus().build(); - List mockAssignmentEntities = Collections.singletonList(new AssignmentEntityBuilder() + List mockAssignmentEntities = List.of(new AssignmentEntityBuilder() .withValidFields().build()); Page mockPageAssignmentEntities = new PageImpl<>(mockAssignmentEntities); @@ -141,7 +140,7 @@ void givenAssignmentListRequest_whenPhoneNumberIsAvailable_thenReturnAysPageAssi AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder().withValidValuesForPhoneNumber().build(); - List mockAssignmentEntities = Collections.singletonList(new AssignmentEntityBuilder() + List mockAssignmentEntities = List.of(new AssignmentEntityBuilder() .withValidFields().build()); Page mockPageAssignmentEntities = new PageImpl<>(mockAssignmentEntities); @@ -170,7 +169,7 @@ void givenAssignmentListRequest_whenAssignmentStatusAndPhoneNumberAvailable_then AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder().withValidValuesForPhoneNumber().build(); - List mockAssignmentEntities = Collections.singletonList(new AssignmentEntityBuilder() + List mockAssignmentEntities = List.of(new AssignmentEntityBuilder() .withValidFields().build()); Page mockPageAssignmentEntities = new PageImpl<>(mockAssignmentEntities); From af7d41873480761058894eb2149403b9e5e02cc6 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 14:21:08 +0300 Subject: [PATCH 40/45] Reformat AssignmentServiceImplTest --- .../ays/assignment/service/impl/AssignmentServiceImplTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java index 0d6e0ea8e..6e30b0b0e 100644 --- a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java +++ b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java @@ -189,4 +189,5 @@ void givenAssignmentListRequest_whenAssignmentStatusAndPhoneNumberAvailable_then Mockito.verify(assignmentRepository, Mockito.times(1)) .findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class)); } + } \ No newline at end of file From d738ba77abe4f09959ee82a3231c07e7b071b51e Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 15:34:48 +0300 Subject: [PATCH 41/45] Change AssignmentListRequestBuilder and its implementations --- .../service/impl/AssignmentServiceImplTest.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java index 6e30b0b0e..742f36aeb 100644 --- a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java +++ b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java @@ -109,7 +109,10 @@ void givenAssignmentListRequest_whenAssignmentStatusIsAvailable_thenReturnAysPag // Given String mockInstitutionId = AysRandomUtil.generateUUID(); - AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder().withValidValuesForStatus().build(); + AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder() + .withValidValues() + .withPhoneNumber(null) + .build(); List mockAssignmentEntities = List.of(new AssignmentEntityBuilder() .withValidFields().build()); @@ -138,7 +141,10 @@ void givenAssignmentListRequest_whenPhoneNumberIsAvailable_thenReturnAysPageAssi // Given String mockInstitutionId = AysRandomUtil.generateUUID(); - AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder().withValidValuesForPhoneNumber().build(); + AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder() + .withValidValues() + .withStatuses(null) + .build(); List mockAssignmentEntities = List.of(new AssignmentEntityBuilder() .withValidFields().build()); @@ -167,7 +173,9 @@ void givenAssignmentListRequest_whenAssignmentStatusAndPhoneNumberAvailable_then // Given String mockInstitutionId = AysRandomUtil.generateUUID(); - AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder().withValidValuesForPhoneNumber().build(); + AssignmentListRequest assignmentListRequest = new AssignmentListRequestBuilder() + .withValidValues() + .build(); List mockAssignmentEntities = List.of(new AssignmentEntityBuilder() .withValidFields().build()); From ddd19ea94f89e73b7b65e4c43f76775417fee97f Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 15:36:01 +0300 Subject: [PATCH 42/45] [FORGOT TO COMMIT] Change AssignmentListRequestBuilder --- .../request/AssignmentListRequestBuilder.java | 44 ++++++------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java b/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java index 997402d49..02aee6694 100644 --- a/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java +++ b/src/test/java/com/ays/assignment/model/dto/request/AssignmentListRequestBuilder.java @@ -14,49 +14,32 @@ public AssignmentListRequestBuilder() { super(AssignmentListRequest.class); } - public AssignmentListRequestBuilder withValidValuesForStatus() { - return this - .withStatus() - .withPagination(new AysPagingBuilder().withValidValues().build()) - .withSort(null); - } - - public AssignmentListRequestBuilder withValidValuesForPhoneNumber() { - return this - .withPhoneNumber() - .withPagination(new AysPagingBuilder().withValidValues().build()) - .withSort(null); - } - public AssignmentListRequestBuilder withValidValues() { return this - .withPhoneNumberAndStatus() + .initializeFilter() + .withStatuses(List.of(AssignmentStatus.AVAILABLE, AssignmentStatus.ASSIGNED)) + .withPhoneNumber(new AssignmentListRequest.PhoneNumber("90", "1234567890")) .withPagination(new AysPagingBuilder().withValidValues().build()) .withSort(null); } - public AssignmentListRequestBuilder withStatus() { - - data.setFilter(new AssignmentListRequest.Filter(List.of(AssignmentStatus.AVAILABLE, AssignmentStatus.ASSIGNED) - , null)); - + private AssignmentListRequestBuilder initializeFilter() { + data.setFilter(new AssignmentListRequest.Filter()); return this; } - public AssignmentListRequestBuilder withPhoneNumber() { - - - data.setFilter(new AssignmentListRequest.Filter(null - , new AssignmentListRequest.PhoneNumber("90", "1234567890"))); - + public AssignmentListRequestBuilder withFilter(AssignmentListRequest.Filter filter) { + data.setFilter(filter); return this; } - public AssignmentListRequestBuilder withPhoneNumberAndStatus() { - - data.setFilter(new AssignmentListRequest.Filter(List.of(AssignmentStatus.AVAILABLE, AssignmentStatus.ASSIGNED) - , new AssignmentListRequest.PhoneNumber("90", "1234567890"))); + public AssignmentListRequestBuilder withStatuses(List statuses) { + data.getFilter().setStatuses(statuses); + return this; + } + public AssignmentListRequestBuilder withPhoneNumber(AssignmentListRequest.PhoneNumber phoneNumber) { + data.getFilter().setPhoneNumber(phoneNumber); return this; } @@ -69,4 +52,5 @@ public AssignmentListRequestBuilder withSort(List sorting) { data.setSort(sorting); return this; } + } From b8704b380ef3b55c19a0f10674d63fba1cb19c56 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 15:40:59 +0300 Subject: [PATCH 43/45] Remove unnecessary isEmpty checks --- .../model/dto/request/AssignmentListRequest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index a9e32b226..dcf20c6c5 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -21,6 +21,7 @@ */ @Getter @Setter +@EqualsAndHashCode(callSuper = true) @AllArgsConstructor @NoArgsConstructor @Builder @@ -94,14 +95,14 @@ public Specification toSpecification(Class clazz) { if (this.filter.phoneNumber != null) { - if (this.filter.phoneNumber.getLineNumber() != null && !this.filter.phoneNumber.getLineNumber().isEmpty()) { + if (this.filter.phoneNumber.getLineNumber() != null) { Specification lineNumberSpecification = (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("lineNumber"), this.filter.phoneNumber.getLineNumber()); specification = specification.and(lineNumberSpecification); } - if (this.filter.phoneNumber.getCountryCode() != null && !this.filter.phoneNumber.getCountryCode().isEmpty()) { + if (this.filter.phoneNumber.getCountryCode() != null) { Specification countryCodeSpecification = (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("countryCode"), this.filter.phoneNumber.getCountryCode()); @@ -109,7 +110,7 @@ public Specification toSpecification(Class clazz) { } } - if (!CollectionUtils.isEmpty(this.filter.statuses)) { + if (!CollectionUtils.isEmpty(this.filter.getStatuses())) { Specification statusSpecification = this.filter.statuses.stream().map(status -> (Specification) (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("status"), status)) From 0a00e10800b326e3312472d0cf753a312112cfa6 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 15:47:06 +0300 Subject: [PATCH 44/45] Verify identity.getInstitutionId --- .../ays/assignment/service/impl/AssignmentServiceImpl.java | 7 +++++-- .../assignment/service/impl/AssignmentServiceImplTest.java | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java index 697327cd5..42e1e0c41 100644 --- a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java +++ b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java @@ -51,12 +51,14 @@ public Assignment getAssignmentById(String id) { @Override public AysPage getAssignments(AssignmentListRequest listRequest) { + String institutionId = identity.getInstitutionId(); + Specification byStatusAndPhoneNumber = listRequest.toSpecification(AssignmentEntity.class); Specification byInstitutionId = (root, query, criteriaBuilder) -> - criteriaBuilder.equal(root.get("institutionId"),identity.getInstitutionId()); + criteriaBuilder.equal(root.get("institutionId"), institutionId); Page assignmentEntities = assignmentRepository - .findAll(byStatusAndPhoneNumber.and(byInstitutionId),listRequest.toPageable()); + .findAll(byStatusAndPhoneNumber.and(byInstitutionId), listRequest.toPageable()); List assignments = assignmentEntityToAssignmentMapper.map(assignmentEntities.getContent()); @@ -66,4 +68,5 @@ public AysPage getAssignments(AssignmentListRequest listRequest) { assignments ); } + } diff --git a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java index 742f36aeb..f1ec86bc6 100644 --- a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java +++ b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java @@ -133,6 +133,7 @@ void givenAssignmentListRequest_whenAssignmentStatusIsAvailable_thenReturnAysPag Mockito.verify(assignmentRepository, Mockito.times(1)) .findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class)); + Mockito.verify(identity, Mockito.times(1)).getInstitutionId(); } @Test @@ -165,6 +166,7 @@ void givenAssignmentListRequest_whenPhoneNumberIsAvailable_thenReturnAysPageAssi Mockito.verify(assignmentRepository, Mockito.times(1)) .findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class)); + Mockito.verify(identity, Mockito.times(1)).getInstitutionId(); } @Test @@ -196,6 +198,7 @@ void givenAssignmentListRequest_whenAssignmentStatusAndPhoneNumberAvailable_then Mockito.verify(assignmentRepository, Mockito.times(1)) .findAll(Mockito.any(Specification.class), Mockito.any(Pageable.class)); + Mockito.verify(identity, Mockito.times(1)).getInstitutionId(); } } \ No newline at end of file From 46772a817860bcd228bdf02d75535d73e1b9ff45 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 16:13:52 +0300 Subject: [PATCH 45/45] Removed EqualsAndHashCode (was causing tests to fail) --- .../ays/assignment/model/dto/request/AssignmentListRequest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java index dcf20c6c5..406ff6886 100644 --- a/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java +++ b/src/main/java/com/ays/assignment/model/dto/request/AssignmentListRequest.java @@ -21,7 +21,6 @@ */ @Getter @Setter -@EqualsAndHashCode(callSuper = true) @AllArgsConstructor @NoArgsConstructor @Builder