Skip to content

Commit

Permalink
Merge branch 'feature/148/update-assignment' into feature/149/delete-…
Browse files Browse the repository at this point in the history
…assignment

# Conflicts:
#	src/main/java/com/ays/assignment/service/AssignmentService.java
  • Loading branch information
AhmetAksunger committed Sep 12, 2023
2 parents 8cf81af + 9a47301 commit c3c5f4d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ays.assignment.model.entity;

import com.ays.assignment.model.dto.request.AssignmentUpdateRequest;
import com.ays.assignment.model.enums.AssignmentStatus;
import com.ays.common.model.entity.BaseEntity;
import com.ays.institution.model.entity.InstitutionEntity;
Expand Down Expand Up @@ -101,13 +100,13 @@ public void reserve(String userId, String institutionId) {
this.institutionId = institutionId;
}

public void updateAssignment(AssignmentUpdateRequest updateRequest) {
this.description = updateRequest.getDescription();
this.firstName = updateRequest.getFirstName();
this.lastName = updateRequest.getLastName();
this.countryCode = updateRequest.getPhoneNumber().getCountryCode();
this.lineNumber = updateRequest.getPhoneNumber().getLineNumber();
this.setPoint(updateRequest.getLongitude(), updateRequest.getLatitude());
public void update(AssignmentEntity assignmentEntity) {
this.description = assignmentEntity.getDescription();
this.firstName = assignmentEntity.getFirstName();
this.lastName = assignmentEntity.getLastName();
this.countryCode = assignmentEntity.getCountryCode();
this.lineNumber = assignmentEntity.getLineNumber();
this.point = assignmentEntity.getPoint();
}

public abstract static class AssignmentEntityBuilder<C extends AssignmentEntity, B extends AssignmentEntityBuilder<C, B>> extends BaseEntity.BaseEntityBuilder<C, B> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.ays.assignment.model.mapper;

import com.ays.assignment.model.dto.request.AssignmentUpdateRequest;
import com.ays.assignment.model.entity.AssignmentEntity;
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;

@Mapper
public interface AssignmentUpdateRequestToAssignmentEntityMapper extends BaseMapper<AssignmentUpdateRequest, AssignmentEntity> {

@Override
@Mapping(target = "countryCode", source = "phoneNumber.countryCode")
@Mapping(target = "lineNumber", source = "phoneNumber.lineNumber")
AssignmentEntity map(AssignmentUpdateRequest source);

@AfterMapping
default void mapLocation(AssignmentUpdateRequest source,
@MappingTarget AssignmentEntity.AssignmentEntityBuilder<?, ?> builder) {
builder.point(source.getLongitude(), source.getLatitude());
}

/**
* Initializes the mapper.
*
* @return the initialized mapper object.
*/
static AssignmentUpdateRequestToAssignmentEntityMapper initialize() {
return Mappers.getMapper(AssignmentUpdateRequestToAssignmentEntityMapper.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface AssignmentService {
* @param id the given Assignment ID
* @param updateRequest the request that contains new assignment information
*/
void updateAssignment(final String id, final AssignmentUpdateRequest updateRequest);
void updateAssignment(String id, AssignmentUpdateRequest updateRequest);

/**
* Delete assignment by Assignment ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.ays.assignment.model.dto.request.AssignmentUpdateRequest;
import com.ays.assignment.model.entity.AssignmentEntity;
import com.ays.assignment.model.mapper.AssignmentEntityToAssignmentMapper;
import com.ays.assignment.model.mapper.AssignmentUpdateRequestToAssignmentEntityMapper;
import com.ays.assignment.repository.AssignmentRepository;
import com.ays.assignment.service.AssignmentService;
import com.ays.assignment.util.exception.AysAssignmentNotExistByIdException;
Expand Down Expand Up @@ -32,6 +33,9 @@ class AssignmentServiceImpl implements AssignmentService {
private final AysIdentity identity;

private static final AssignmentEntityToAssignmentMapper assignmentEntityToAssignmentMapper = AssignmentEntityToAssignmentMapper.initialize();

private static final AssignmentUpdateRequestToAssignmentEntityMapper assignmentUpdateRequestToAssignmentEntityMapper = AssignmentUpdateRequestToAssignmentEntityMapper.initialize();

private static final UserLocationEntityToUserLocationMapper userLocationEntityToUserLocationMapper = UserLocationEntityToUserLocationMapper.initialize();

/**
Expand Down Expand Up @@ -106,7 +110,7 @@ public void updateAssignment(final String id, final AssignmentUpdateRequest upda
.filter(AssignmentEntity::isAvailable)
.orElseThrow(() -> new AysAssignmentNotExistByIdException(id));

assignmentEntity.updateAssignment(updateRequest);
assignmentEntity.update(assignmentUpdateRequestToAssignmentEntityMapper.map(updateRequest));
assignmentRepository.save(assignmentEntity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public AssignmentUpdateRequestBuilder() {

public AssignmentUpdateRequestBuilder withValidFields() {
return this
.withDescription("Updated Description")
.withFirstName("Updated First Name")
.withLastName("Updated Last Name")
.withPhoneNumber(new AysPhoneNumberBuilder()
.withCountryCode("91")
.withLineNumber("9876543210")
Expand All @@ -22,21 +19,6 @@ public AssignmentUpdateRequestBuilder withValidFields() {
.withLongitude(2.0);
}

public AssignmentUpdateRequestBuilder withDescription(String description) {
data.setDescription(description);
return this;
}

public AssignmentUpdateRequestBuilder withFirstName(String firstName) {
data.setFirstName(firstName);
return this;
}

public AssignmentUpdateRequestBuilder withLastName(String lastName) {
data.setLastName(lastName);
return this;
}

public AssignmentUpdateRequestBuilder withPhoneNumber(AysPhoneNumber phoneNumber) {
data.setPhoneNumber(phoneNumber);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ void givenValidAssignmentIdAndAssignmentUpdateRequest_whenAssignmentAvailable_th

Mockito.verify(assignmentRepository, Mockito.times(1))
.findByIdAndInstitutionId(mockAssignmentId, mockInstitutionId);
Mockito.verify(assignmentRepository, Mockito.times(1))
.save(Mockito.any(AssignmentEntity.class));
Mockito.verify(identity, Mockito.times(1))
.getInstitutionId();
Mockito.verify(assignmentRepository, Mockito.times(1))
.save(Mockito.any(AssignmentEntity.class));
}

@Test
Expand Down Expand Up @@ -288,9 +288,9 @@ void givenValidAssignmentIdAndAssignmentUpdateRequest_whenAssignmentNotAvailable

Mockito.verify(assignmentRepository, Mockito.times(1))
.findByIdAndInstitutionId(mockAssignmentId, mockInstitutionId);
Mockito.verify(assignmentRepository, Mockito.never()).save(Mockito.any(AssignmentEntity.class));
Mockito.verify(identity, Mockito.times(1))
.getInstitutionId();
Mockito.verify(assignmentRepository, Mockito.never()).save(Mockito.any(AssignmentEntity.class));
}

@Test
Expand Down

0 comments on commit c3c5f4d

Please sign in to comment.