Skip to content

Commit

Permalink
pass product test
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzaeimahdi409 committed Aug 3, 2024
1 parent c172fd5 commit 185088d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/com/dishDash/common/dto/LocationDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@NoArgsConstructor
public class LocationDto {
private long id;
private long latitude;
private long longitude;
private float latitude;
private float longitude;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"com.dish_dash.product", "com.dishDash.common"})
@EnableEurekaClient
public class ProductApplication {
public static void main(String[] args) {
Expand Down
3 changes: 2 additions & 1 deletion product/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ spring.datasource.password=
spring.h2.console.enabled=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.show_sql=false
eureka.client.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public interface LocationRepository extends JpaRepository<Location, Long> {

Optional<Location> findByDeliveryID(Long deliveryID);

@Query("UPDATE Location SET latitude =:latitude, longitude =:longitude, timestamp =:timestamp where id=:id")
@Query(
"UPDATE Location SET latitude =:latitude, longitude =:longitude where id=:id")
@Modifying
@Transactional
void modify(@Param("latitude") long latitude, @Param("longitude") long longitude,
@Param("timestamp") long timestamp, @Param("id") long id);
void modify(
@Param("latitude") float latitude, @Param("longitude") float longitude, @Param("id") long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class Location {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

private long latitude;
private long longitude;
private float latitude;
private float longitude;
@UpdateTimestamp private Timestamp timestamp;

@Column(name = "delivery_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.sql.Time;
import java.time.LocalDateTime;

import static com.fasterxml.jackson.databind.type.LogicalType.DateTime;

@Service
@RequiredArgsConstructor
@Slf4j
Expand Down Expand Up @@ -97,12 +92,14 @@ public boolean setLocation(LocationDto locationDto, long deliveryPersonId) {
.findByDeliveryID(deliveryPersonId)
.orElseGet(
() ->
Location.builder()
.deliveryID(deliveryPersonId)
.latitude(locationDto.getLatitude())
.longitude(locationDto.getLongitude())
.build());
locationRepository.modify(locationDto.getLatitude(), locationDto.getLongitude(), System.currentTimeMillis(), location.getId());
locationRepository.save(
Location.builder()
.deliveryID(deliveryPersonId)
.latitude(locationDto.getLatitude())
.longitude(locationDto.getLongitude())
.build()));
locationRepository.modify(
locationDto.getLatitude(), locationDto.getLongitude(), location.getId());

deliveryPerson.setLocation(location);
deliveryPersonRepository.save(deliveryPerson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ void setUp() {
.phoneNumber("PHONE_NUMBER")
.build();

locationDto =
LocationDto.builder().latitude((long) 12.345678).longitude((long) 98.765432).build();
locationDto = LocationDto.builder().latitude(12.345678F).longitude(98.765432F).build();
}

@Test
Expand Down Expand Up @@ -155,12 +154,12 @@ void getDeliveryPersonStatus_ShouldThrowCustomException_WhenDeliveryPersonDoesNo
@Test
void setLocation_ShouldReturnTrue_WhenDeliveryPersonExists() {
DeliveryPerson deliveryPerson =
DeliveryPerson.builder().id(1L).status(DeliveryPersonStatus.ACTIVE).build();
deliveryPersonRepository.save(deliveryPerson);
deliveryPersonRepository.save(
DeliveryPerson.builder().id(1L).status(DeliveryPersonStatus.ACTIVE).build());

boolean result = deliveryPersonService.setLocation(locationDto, 1L);
boolean result = deliveryPersonService.setLocation(locationDto, deliveryPerson.getId());

Location location = locationRepository.findByDeliveryID(1L).orElse(null);
Location location = locationRepository.findByDeliveryID(deliveryPerson.getId()).orElse(null);

assertTrue(result);
assertNotNull(location);
Expand Down

0 comments on commit 185088d

Please sign in to comment.