From ddc811acd47494238e5dcd54c495c9519c62af3a Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 18:55:41 +0300 Subject: [PATCH 01/13] Add userLocation to Assignment --- src/main/java/com/ays/assignment/model/Assignment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/ays/assignment/model/Assignment.java b/src/main/java/com/ays/assignment/model/Assignment.java index 7ab447ecb..be29aadee 100644 --- a/src/main/java/com/ays/assignment/model/Assignment.java +++ b/src/main/java/com/ays/assignment/model/Assignment.java @@ -4,6 +4,7 @@ import com.ays.common.model.AysPhoneNumber; import com.ays.common.model.BaseDomainModel; import com.ays.institution.model.Institution; +import com.ays.location.model.UserLocation; import com.ays.user.model.User; import lombok.Data; import lombok.EqualsAndHashCode; @@ -27,6 +28,7 @@ public class Assignment extends BaseDomainModel { private AssignmentStatus status; private User user; + private UserLocation userLocation; private Institution institution; } From 5b89ae007f9a122ad800d5ab2a5bd3dcb2d5826e Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 18:55:59 +0300 Subject: [PATCH 02/13] Update AssignmentEntityToAssignmentMapper --- .../model/mapper/AssignmentEntityToAssignmentMapper.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/mapper/AssignmentEntityToAssignmentMapper.java b/src/main/java/com/ays/assignment/model/mapper/AssignmentEntityToAssignmentMapper.java index 2959e2296..d909d2427 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentEntityToAssignmentMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentEntityToAssignmentMapper.java @@ -18,8 +18,10 @@ public interface AssignmentEntityToAssignmentMapper extends BaseMapper { @Override - @Mapping(target = "phoneNumber.countryCode", source = "source.countryCode") - @Mapping(target = "phoneNumber.lineNumber", source = "source.lineNumber") + @Mapping(target = "phoneNumber.countryCode", source = "countryCode") + @Mapping(target = "phoneNumber.lineNumber", source = "lineNumber") + @Mapping(target = "user.phoneNumber.countryCode", source = "user.countryCode") + @Mapping(target = "user.phoneNumber.lineNumber", source = "user.lineNumber") Assignment map(AssignmentEntity source); /** From 460400a18ed27d59e73d2fbd80dc364a6800a5c3 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 18:56:22 +0300 Subject: [PATCH 03/13] Update AssignmentResponse --- .../dto/response/AssignmentResponse.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 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 59ad6e3ce..2e7aba6d1 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 @@ -1,8 +1,11 @@ package com.ays.assignment.model.dto.response; +import com.ays.assignment.model.enums.AssignmentStatus; +import com.ays.common.model.AysPhoneNumber; import com.ays.common.model.dto.response.BaseResponse; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.Setter; import lombok.experimental.SuperBuilder; /** @@ -15,9 +18,31 @@ public class AssignmentResponse extends BaseResponse { private String id; private String description; + private AssignmentStatus status; private String firstName; private String lastName; - private Double longitude; - private Double latitude; + private AysPhoneNumber phoneNumber; + private Location location; + private User user; + + @Getter + @Setter + public static class User { + + private String id; + private String firstName; + private String lastName; + private AysPhoneNumber phoneNumber; + private Location location; + + } + + @Getter + @Setter + public static class Location { + private Double longitude; + private Double latitude; + + } } From a0c5f9ea34e8e7b3edfebe4cddca9d5be92f6c26 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 18:56:45 +0300 Subject: [PATCH 04/13] Update AssignmentServiceImpl --- .../service/impl/AssignmentServiceImpl.java | 13 +++++++++++-- 1 file changed, 11 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 aca36d5ae..8e554a539 100644 --- a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java +++ b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java @@ -7,6 +7,9 @@ import com.ays.assignment.service.AssignmentService; import com.ays.assignment.util.exception.AysAssignmentNotExistByIdException; import com.ays.auth.model.AysIdentity; +import com.ays.location.model.UserLocation; +import com.ays.location.model.mapper.UserLocationEntityToUserLocationMapper; +import com.ays.location.repository.UserLocationRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -15,11 +18,12 @@ class AssignmentServiceImpl implements AssignmentService { private final AssignmentRepository assignmentRepository; + private final UserLocationRepository userLocationRepository; private final AysIdentity identity; private static final AssignmentEntityToAssignmentMapper assignmentEntityToAssignmentMapper = AssignmentEntityToAssignmentMapper.initialize(); - + private static final UserLocationEntityToUserLocationMapper userLocationEntityToUserLocationMapper = UserLocationEntityToUserLocationMapper.initialize(); /** * Retrieves an assignment by their ID. * @@ -33,6 +37,11 @@ public Assignment getAssignmentById(String id) { final AssignmentEntity assignmentEntity = assignmentRepository.findByIdAndInstitutionId(id, identity.getInstitutionId()) .orElseThrow(() -> new AysAssignmentNotExistByIdException(id)); - return assignmentEntityToAssignmentMapper.map(assignmentEntity); + Assignment assignment = assignmentEntityToAssignmentMapper.map(assignmentEntity); + UserLocation userLocation = userLocationEntityToUserLocationMapper.map(userLocationRepository + .findByUserId(assignmentEntity.getUserId()).orElse(null)); + assignment.setUserLocation(userLocation); + + return assignment; } } From e649ab3381690800de6fb473fddd282a26586f5a Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 18:57:06 +0300 Subject: [PATCH 05/13] Update AssignmentToAssignmentResponseMapper --- .../model/mapper/AssignmentToAssignmentResponseMapper.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 7ec13941e..351029f5b 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java @@ -18,8 +18,10 @@ public interface AssignmentToAssignmentResponseMapper extends BaseMapper { @Override - @Mapping(target = "longitude", source = "source.point.x") - @Mapping(target = "latitude", source = "source.point.y") + @Mapping(target = "location.longitude", source = "point.x") + @Mapping(target = "location.latitude", source = "point.y") + @Mapping(target = "user.location.longitude", source = "userLocation.point.x") + @Mapping(target = "user.location.latitude", source = "userLocation.point.y") AssignmentResponse map(Assignment source); /** From fd60d0e72478da23574212eac5f5795db26e4ba8 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 21:33:54 +0300 Subject: [PATCH 06/13] Create UserLocationEntityBuilder --- .../entity/UserLocationEntityBuilder.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/com/ays/location/model/entity/UserLocationEntityBuilder.java diff --git a/src/test/java/com/ays/location/model/entity/UserLocationEntityBuilder.java b/src/test/java/com/ays/location/model/entity/UserLocationEntityBuilder.java new file mode 100644 index 000000000..a7b9ff671 --- /dev/null +++ b/src/test/java/com/ays/location/model/entity/UserLocationEntityBuilder.java @@ -0,0 +1,45 @@ +package com.ays.location.model.entity; + +import com.ays.common.model.TestDataBuilder; +import com.ays.user.model.entity.UserEntity; +import com.ays.user.model.entity.UserEntityBuilder; + +public class UserLocationEntityBuilder extends TestDataBuilder { + + public UserLocationEntityBuilder() { + super(UserLocationEntity.class); + } + + public UserLocationEntityBuilder withValidFields() { + + UserEntity userEntity = new UserEntityBuilder() + .withValidFields() + .build(); + + return this + .withId(1L) + .withUserId(userEntity.getId()) + .withUser(userEntity) + .withPoint(1.0, 2.0); + } + + public UserLocationEntityBuilder withId(Long id) { + data.setId(id); + return this; + } + + public UserLocationEntityBuilder withUserId(String userId) { + data.setUserId(userId); + return this; + } + + public UserLocationEntityBuilder withUser(UserEntity userEntity) { + data.setUser(userEntity); + return this; + } + + public UserLocationEntityBuilder withPoint(Double longitude, Double latitude) { + data.setPoint(longitude, latitude); + return this; + } +} From 5f861e319f8165efbcecb5146a8da9e9ea485134 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Wed, 6 Sep 2023 21:34:49 +0300 Subject: [PATCH 07/13] Update AssignmentServiceImplTest --- .../service/impl/AssignmentServiceImplTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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..e83376896 100644 --- a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java +++ b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java @@ -9,6 +9,11 @@ import com.ays.assignment.util.exception.AysAssignmentNotExistByIdException; import com.ays.auth.model.AysIdentity; import com.ays.common.util.AysRandomUtil; +import com.ays.location.model.UserLocation; +import com.ays.location.model.entity.UserLocationEntity; +import com.ays.location.model.entity.UserLocationEntityBuilder; +import com.ays.location.model.mapper.UserLocationEntityToUserLocationMapper; +import com.ays.location.repository.UserLocationRepository; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -26,11 +31,14 @@ class AssignmentServiceImplTest extends AbstractUnitTest { @Mock private AssignmentRepository assignmentRepository; + @Mock + private UserLocationRepository userLocationRepository; + @Mock private AysIdentity identity; private static final AssignmentEntityToAssignmentMapper ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER = AssignmentEntityToAssignmentMapper.initialize(); - + private static final UserLocationEntityToUserLocationMapper USER_LOCATION_ENTITY_TO_USER_LOCATION_MAPPER = UserLocationEntityToUserLocationMapper.initialize(); @Test void givenAssignmentId_whenGetAssignment_thenReturnAssignment() { @@ -42,14 +50,18 @@ void givenAssignmentId_whenGetAssignment_thenReturnAssignment() { .withValidFields() .withInstitutionId(mockInstitutionId).build(); String mockAssignmentId = mockAssignmentEntity.getId(); + UserLocationEntity mockUserLocationEntity = new UserLocationEntityBuilder().withValidFields().build(); + UserLocation mockUserLocation = USER_LOCATION_ENTITY_TO_USER_LOCATION_MAPPER.map(mockUserLocationEntity); Assignment mockAssignment = ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER.map(mockAssignmentEntity); + mockAssignment.setUserLocation(mockUserLocation); // When Mockito.when(identity.getInstitutionId()) .thenReturn(mockInstitutionId); Mockito.when(assignmentRepository.findByIdAndInstitutionId(Mockito.anyString(), Mockito.anyString())) .thenReturn(Optional.of(mockAssignmentEntity)); + Mockito.when(userLocationRepository.findByUserId(Mockito.anyString())).thenReturn(Optional.of(mockUserLocationEntity)); // Then Assignment assignment = assignmentService.getAssignmentById(mockAssignmentId); @@ -61,6 +73,7 @@ void givenAssignmentId_whenGetAssignment_thenReturnAssignment() { Assertions.assertEquals(mockAssignment.getPhoneNumber().getLineNumber(), assignment.getPhoneNumber().getLineNumber()); Assertions.assertEquals(mockAssignment.getStatus(), assignment.getStatus()); Assertions.assertEquals(mockAssignment.getPoint(), assignment.getPoint()); + Assertions.assertEquals(mockAssignment.getUserLocation(), assignment.getUserLocation()); Mockito.verify(assignmentRepository, Mockito.times(1)) .findByIdAndInstitutionId(mockAssignmentId, mockInstitutionId); From d4acd313e1b4b2feaa0b74bb46adefc61201cfd2 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Thu, 7 Sep 2023 15:47:53 +0300 Subject: [PATCH 08/13] Add AfterMapping to AssignmentToAssignmentResponseMapper --- .../dto/response/AssignmentResponse.java | 6 ++-- .../AssignmentToAssignmentResponseMapper.java | 33 +++++++++++++++++-- 2 files changed, 34 insertions(+), 5 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 2e7aba6d1..bf2fd3305 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 @@ -3,9 +3,7 @@ import com.ays.assignment.model.enums.AssignmentStatus; import com.ays.common.model.AysPhoneNumber; import com.ays.common.model.dto.response.BaseResponse; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; +import lombok.*; import lombok.experimental.SuperBuilder; /** @@ -27,6 +25,7 @@ public class AssignmentResponse extends BaseResponse { @Getter @Setter + @Builder public static class User { private String id; @@ -39,6 +38,7 @@ public static class User { @Getter @Setter + @Builder public static class Location { private Double longitude; private Double latitude; 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 351029f5b..1e7bff57b 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java @@ -3,8 +3,10 @@ import com.ays.assignment.model.Assignment; import com.ays.assignment.model.dto.response.AssignmentResponse; import com.ays.common.model.mapper.BaseMapper; +import org.mapstruct.AfterMapping; import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; import org.mapstruct.factory.Mappers; /** @@ -20,10 +22,37 @@ public interface AssignmentToAssignmentResponseMapper extends BaseMapper targetBuilder) { + if (source.getUser() != null && source.getUserLocation() != null) { + + AssignmentResponse.Location userLocation = AssignmentResponse.Location + .builder() + .longitude(source.getUserLocation().getPoint().getX()) + .latitude(source.getUserLocation().getPoint().getY()) + .build(); + + AssignmentResponse.User user = AssignmentResponse.User.builder() + .id(source.getUser().getId()) + .firstName(source.getFirstName()) + .lastName(source.getLastName()) + .phoneNumber(source.getPhoneNumber()) + .location(userLocation) + .build(); + + targetBuilder.user(user).build(); + } + } + /** * Initializes the mapper. * From 9a85fca131e8ea846e43e5c9a19a010e4a96478d Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Thu, 7 Sep 2023 15:55:32 +0300 Subject: [PATCH 09/13] Reformat --- .../assignment/model/dto/response/AssignmentResponse.java | 5 ++++- .../model/mapper/AssignmentToAssignmentResponseMapper.java | 2 +- .../ays/assignment/service/impl/AssignmentServiceImpl.java | 2 ++ .../assignment/service/impl/AssignmentServiceImplTest.java | 1 + .../ays/location/model/entity/UserLocationEntityBuilder.java | 1 + 5 files changed, 9 insertions(+), 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 bf2fd3305..f76d90b18 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 @@ -3,7 +3,10 @@ import com.ays.assignment.model.enums.AssignmentStatus; import com.ays.common.model.AysPhoneNumber; import com.ays.common.model.dto.response.BaseResponse; -import lombok.*; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; import lombok.experimental.SuperBuilder; /** 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 1e7bff57b..642a40274 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java @@ -27,7 +27,7 @@ public interface AssignmentToAssignmentResponseMapper extends BaseMapper Date: Thu, 7 Sep 2023 22:02:24 +0300 Subject: [PATCH 10/13] Remove UserLocation from Assignment --- src/main/java/com/ays/assignment/model/Assignment.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/ays/assignment/model/Assignment.java b/src/main/java/com/ays/assignment/model/Assignment.java index be29aadee..7ab447ecb 100644 --- a/src/main/java/com/ays/assignment/model/Assignment.java +++ b/src/main/java/com/ays/assignment/model/Assignment.java @@ -4,7 +4,6 @@ import com.ays.common.model.AysPhoneNumber; import com.ays.common.model.BaseDomainModel; import com.ays.institution.model.Institution; -import com.ays.location.model.UserLocation; import com.ays.user.model.User; import lombok.Data; import lombok.EqualsAndHashCode; @@ -28,7 +27,6 @@ public class Assignment extends BaseDomainModel { private AssignmentStatus status; private User user; - private UserLocation userLocation; private Institution institution; } From 4a1bbe82c0cba19b9a0158c1c8bc6589f8965a6d Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Thu, 7 Sep 2023 22:03:07 +0300 Subject: [PATCH 11/13] Add Location inner class to User --- src/main/java/com/ays/user/model/User.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ays/user/model/User.java b/src/main/java/com/ays/user/model/User.java index 11c07fdd7..ce4381171 100644 --- a/src/main/java/com/ays/user/model/User.java +++ b/src/main/java/com/ays/user/model/User.java @@ -6,9 +6,9 @@ import com.ays.user.model.enums.UserRole; import com.ays.user.model.enums.UserStatus; import com.ays.user.model.enums.UserSupportStatus; -import lombok.Data; -import lombok.EqualsAndHashCode; +import lombok.*; import lombok.experimental.SuperBuilder; +import org.locationtech.jts.geom.Point; /** * User Domain Model to perform data transfer from service layer to controller @@ -27,7 +27,22 @@ public class User extends BaseDomainModel { private UserStatus status; private UserSupportStatus supportStatus; private AysPhoneNumber phoneNumber; + private Location location; private Institution institution; + @Getter + @Builder + public static class Location { + private Double longitude; + private Double latitude; + } + + public void setLocation(Point point) { + this.location = Location.builder() + .longitude(point.getX()) + .latitude(point.getY()) + .build(); + } + } From deae80225bdd06743d29f0b6b2954331e7fa86dc Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Thu, 7 Sep 2023 22:03:48 +0300 Subject: [PATCH 12/13] Apply User class changes to their implementations --- .../dto/response/AssignmentResponse.java | 1 - .../AssignmentToAssignmentResponseMapper.java | 31 ------------------- .../service/impl/AssignmentServiceImpl.java | 17 ++++++++-- .../impl/AssignmentServiceImplTest.java | 7 +++-- 4 files changed, 19 insertions(+), 37 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 f76d90b18..6270634e1 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 @@ -40,7 +40,6 @@ public static class User { } @Getter - @Setter @Builder public static class Location { private Double longitude; 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 642a40274..7d4b2d210 100644 --- a/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java +++ b/src/main/java/com/ays/assignment/model/mapper/AssignmentToAssignmentResponseMapper.java @@ -3,10 +3,8 @@ import com.ays.assignment.model.Assignment; import com.ays.assignment.model.dto.response.AssignmentResponse; import com.ays.common.model.mapper.BaseMapper; -import org.mapstruct.AfterMapping; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.MappingTarget; import org.mapstruct.factory.Mappers; /** @@ -24,35 +22,6 @@ public interface AssignmentToAssignmentResponseMapper extends BaseMapper targetBuilder) { - if (source.getUser() != null && source.getUserLocation() != null) { - - AssignmentResponse.Location userLocation = AssignmentResponse.Location - .builder() - .longitude(source.getUserLocation().getPoint().getX()) - .latitude(source.getUserLocation().getPoint().getY()) - .build(); - - AssignmentResponse.User user = AssignmentResponse.User.builder() - .id(source.getUser().getId()) - .firstName(source.getFirstName()) - .lastName(source.getLastName()) - .phoneNumber(source.getPhoneNumber()) - .location(userLocation) - .build(); - - targetBuilder.user(user).build(); - } - } - /** * Initializes the mapper. * 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 d64a228ab..f926b23af 100644 --- a/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java +++ b/src/main/java/com/ays/assignment/service/impl/AssignmentServiceImpl.java @@ -8,11 +8,14 @@ import com.ays.assignment.util.exception.AysAssignmentNotExistByIdException; import com.ays.auth.model.AysIdentity; import com.ays.location.model.UserLocation; +import com.ays.location.model.entity.UserLocationEntity; import com.ays.location.model.mapper.UserLocationEntityToUserLocationMapper; import com.ays.location.repository.UserLocationRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service @RequiredArgsConstructor class AssignmentServiceImpl implements AssignmentService { @@ -39,9 +42,17 @@ public Assignment getAssignmentById(String id) { .orElseThrow(() -> new AysAssignmentNotExistByIdException(id)); Assignment assignment = assignmentEntityToAssignmentMapper.map(assignmentEntity); - UserLocation userLocation = userLocationEntityToUserLocationMapper.map(userLocationRepository - .findByUserId(assignmentEntity.getUserId()).orElse(null)); - assignment.setUserLocation(userLocation); + + Optional optionalUserLocationEntity = userLocationRepository + .findByUserId(assignmentEntity.getUserId()); + + if (optionalUserLocationEntity.isPresent()) { + + UserLocation userLocation = userLocationEntityToUserLocationMapper + .map(optionalUserLocationEntity.get()); + + assignment.getUser().setLocation(userLocation.getPoint()); + } return assignment; } 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 f3fe1b5ed..a2646d5ca 100644 --- a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java +++ b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java @@ -54,7 +54,7 @@ void givenAssignmentId_whenGetAssignment_thenReturnAssignment() { UserLocation mockUserLocation = USER_LOCATION_ENTITY_TO_USER_LOCATION_MAPPER.map(mockUserLocationEntity); Assignment mockAssignment = ASSIGNMENT_ENTITY_TO_ASSIGNMENT_MAPPER.map(mockAssignmentEntity); - mockAssignment.setUserLocation(mockUserLocation); + mockAssignment.getUser().setLocation(mockUserLocation.getPoint()); // When Mockito.when(identity.getInstitutionId()) @@ -73,7 +73,10 @@ void givenAssignmentId_whenGetAssignment_thenReturnAssignment() { Assertions.assertEquals(mockAssignment.getPhoneNumber().getLineNumber(), assignment.getPhoneNumber().getLineNumber()); Assertions.assertEquals(mockAssignment.getStatus(), assignment.getStatus()); Assertions.assertEquals(mockAssignment.getPoint(), assignment.getPoint()); - Assertions.assertEquals(mockAssignment.getUserLocation(), assignment.getUserLocation()); + Assertions.assertEquals(mockAssignment.getUser().getLocation().getLongitude(), + assignment.getUser().getLocation().getLongitude()); + Assertions.assertEquals(mockAssignment.getUser().getLocation().getLatitude(), + assignment.getUser().getLocation().getLatitude()); Mockito.verify(assignmentRepository, Mockito.times(1)) .findByIdAndInstitutionId(mockAssignmentId, mockInstitutionId); From c8ad375358f6d3146692a21202bae0cbf092ae35 Mon Sep 17 00:00:00 2001 From: AhmetAksunger Date: Thu, 7 Sep 2023 22:07:40 +0300 Subject: [PATCH 13/13] Reformat --- .../ays/assignment/service/impl/AssignmentServiceImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a2646d5ca..aa6a10421 100644 --- a/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java +++ b/src/test/java/com/ays/assignment/service/impl/AssignmentServiceImplTest.java @@ -110,4 +110,4 @@ void givenAssignmentId_whenAssignmentNotFound_thenThrowAysAssignmentNotExistById .getInstitutionId(); } -} \ No newline at end of file +}