Skip to content

Commit

Permalink
Merge pull request #9 from zhelemishsh/order_in_process_service
Browse files Browse the repository at this point in the history
Order in process service
  • Loading branch information
zhelemishsh authored Aug 15, 2023
2 parents 138c695 + 74dc050 commit 9af5b42
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pomika.carwashbackend.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.pomika.carwashbackend.model.MapPosition;
import lombok.Getter;

@Getter
Expand All @@ -11,23 +12,23 @@ public class CarWashCreationDto {
@JsonProperty("name") String name,
@JsonProperty("picture") String picture,
@JsonProperty("address") String address,
@JsonProperty("latitude") double latitude,
@JsonProperty("longitude") double longitude
){
@JsonProperty("map_position")MapPositionDto mapPositionDto
){
this.phoneNumber = phoneNumber;
this.password = password;
this.name = name;
this.picture = picture;
this.address = address;
this.latitude = latitude;
this.longitude = longitude;
this.mapPosition = new MapPosition(
mapPositionDto.getLatitude(),
mapPositionDto.getLongitude()
);
}

private final String phoneNumber;
private final String password;
private final String name;
private final String picture;
private final String address;
private final double latitude;
private final double longitude;
private final MapPosition mapPosition;
}
6 changes: 2 additions & 4 deletions src/main/java/com/pomika/carwashbackend/dto/CarWashDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public class CarWashDto {
@JsonProperty("address")
private final String address;

@JsonProperty("latitude")
private final double latitude;
@JsonProperty("map_position")
private final MapPositionDto mapPositionDto;

@JsonProperty("longitude")
private final double longitude;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pomika.carwashbackend.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.pomika.carwashbackend.model.MapPosition;
import lombok.Getter;

@Getter
Expand All @@ -9,19 +10,19 @@ public CarWashUpdateDto(
@JsonProperty("name") String name,
@JsonProperty("picture") String picture,
@JsonProperty("address") String address,
@JsonProperty("latitude") double latitude,
@JsonProperty("longitude") double longitude
@JsonProperty("map_position")MapPositionDto mapPositionDto
){
this.name= name;
this.picture = picture;
this.address = address;
this.latitude = latitude;
this.longitude = longitude;
this.mapPosition = new MapPosition(
mapPositionDto.getLatitude(),
mapPositionDto.getLongitude()
);
}

private final String name;
private final String picture;
private final String address;
private final double latitude;
private final double longitude;
private final MapPosition mapPosition;
}
16 changes: 16 additions & 0 deletions src/main/java/com/pomika/carwashbackend/dto/MapPositionDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pomika.carwashbackend.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class MapPositionDto {

@JsonProperty("latitude")
private double latitude;

@JsonProperty("longitude")
private double longitude;
}
7 changes: 2 additions & 5 deletions src/main/java/com/pomika/carwashbackend/dto/OfferDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ public class OfferDto {
@JsonProperty("car_wash_address")
private final String carWashAddress;

@JsonProperty("latitude")
private final double latitude;

@JsonProperty("longitude")
private final double longitude;
@JsonProperty("map_position")
private final MapPositionDto mapPositionDto;

@JsonProperty("car_wash_name")
private final String carWashName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.pomika.carwashbackend.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.pomika.carwashbackend.model.WashServiceType;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Date;
import java.util.List;

@Getter
@AllArgsConstructor
public class OrderInProcessForCarWashDto {
@JsonProperty("id")
private int id;

@JsonProperty("start_time")
private Date startTime;

@JsonProperty("wash_time")
private int washTime;

@JsonProperty("price")
private int price;

@JsonProperty("car")
private CarDto car;

@JsonProperty("wash_service_types")
private List<WashServiceType> washServiceTypes;

@JsonProperty("user_phone_number")
private String userPhoneNumber;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.pomika.carwashbackend.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.pomika.carwashbackend.model.WashServiceType;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Date;
import java.util.List;

@Getter
@AllArgsConstructor
public class OrderInProcessForUserDto {
@JsonProperty("id")
private int id;

@JsonProperty("start_time")
private Date startTime;

@JsonProperty("wash_time")
private int washTime;

@JsonProperty("price")
private int price;

@JsonProperty("car")
private CarDto car;

@JsonProperty("wash_service_types")
private List<WashServiceType> washServiceTypes;

@JsonProperty("car_wash_name")
private String carWashName;

@JsonProperty("car_wash_address")
private String carWashAddress;

@JsonProperty("map_position")
private MapPositionDto mapPositionDto;

@JsonProperty("car_wash_picture")
private String carWashPicture;

@JsonProperty("car_wash_phone_number")
private String carWashPhoneNumber;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ public OrderSessionCreationDto(
@JsonProperty("endTime") Date endTime,
@JsonProperty("car") CarDto car,
@JsonProperty("wash_services") List<WashServiceType> washServiceTypes,
@JsonProperty("latitude") double latitude,
@JsonProperty("longitude") double longitude,
@JsonProperty("radius") double radius
@JsonProperty("search_area") SearchAreaDto searchAreaDto
){
this.startTime = startTime;
this.endTime = endTime;
this.car = car;
this.washServiceTypes = washServiceTypes;
this.searchArea = new SearchArea(latitude,longitude,radius);
this.searchArea = new SearchArea(
searchAreaDto.getMapPositionDto().getLatitude(),
searchAreaDto.getMapPositionDto().getLongitude(),
searchAreaDto.getRadius());
}

private final Date startTime;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/pomika/carwashbackend/dto/SearchAreaDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.pomika.carwashbackend.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class SearchAreaDto {
@JsonProperty("map_position")
private MapPositionDto mapPositionDto;

@JsonProperty("radius")
private double radius;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pomika.carwashbackend.exception;

public class OrderInProcessServiceException extends RuntimeException{
public OrderInProcessServiceException(String message){
super(message);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/pomika/carwashbackend/model/Car.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Car(int id,
@Column(name = "id")
private int id;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "owner_id")
private UserAccount userAccount;

Expand Down
19 changes: 8 additions & 11 deletions src/main/java/com/pomika/carwashbackend/model/CarWash.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ public CarWash(Account account,
double rating,
String picture,
String address,
double latitude,
double longitude
MapPosition mapPosition
){
this.account = account;
this.name = name;
this.rating = rating;
this.picture = picture;
this.address = address;
this.latitude = latitude;
this.longitude = longitude;
this.mapPosition = mapPosition;
}

@Id
Expand All @@ -50,11 +48,10 @@ public CarWash(Account account,
@Column(name = "address")
private String address;

@Column(name = "latitude")
private double latitude;

@Column(name = "longitude")
private double longitude;


@Embedded
@AttributeOverrides({
@AttributeOverride( name = "latitude", column = @Column(name = "latitude")),
@AttributeOverride( name = "longitude", column = @Column(name = "longitude"))
})
private MapPosition mapPosition;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.pomika.carwashbackend.model;

import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@Embeddable
public class MapPosition {
public MapPosition(){}

private double latitude;
private double longitude;
}
6 changes: 5 additions & 1 deletion src/main/java/com/pomika/carwashbackend/model/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Setter;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -19,13 +20,15 @@ public class Order {
private Map<String, CarWashServicesInOrder> carWashAndServices;
private double bestRating;
private int bestPrice;
private List<WashServiceType> washServiceTypes;

public Order(
int userId,
Date startTime,
Date endTime,
Car car,
Map<String,CarWashServicesInOrder> carWashAndServices
Map<String,CarWashServicesInOrder> carWashAndServices,
List<WashServiceType> washServiceTypes
){
this.userId = userId;
this.startTime = startTime;
Expand All @@ -35,6 +38,7 @@ public Order(
this.bestPrice = 0;
this.bestRating = 0;
this.carWashAndServices = carWashAndServices;
this.washServiceTypes = washServiceTypes;
}

@Override
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/pomika/carwashbackend/model/OrderInProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ public OrderInProcess(){}
public OrderInProcess(Car car,
Date startTime,
CarWash carWash,
List<WashService> washServices){
List<WashServiceType> washServiceTypes,
int price,
int washTime){
this.car = car;
this.startTime = startTime;
this.washServices = washServices;
this.washServiceTypes = washServiceTypes;
this.carWash = carWash;
this.price = price;
this.washTime = washTime;
this.isFinished = false;
}

@Id
Expand All @@ -39,7 +44,15 @@ public OrderInProcess(Car car,
@JoinColumn(name = "car_wash_id")
private CarWash carWash;

@ManyToMany
private List<WashService> washServices;
@Column(name = "wash_service_types")
private List<WashServiceType> washServiceTypes;

@Column(name = "price")
private int price;

@Column(name = "wash_time")
private int washTime;

@Column(name = "is_finished")
private boolean isFinished;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
public interface CarWashRepository extends JpaRepository<CarWash, Integer> {
CarWash findByAccount(Account account);

List<CarWash> findByLatitudeIsBetweenAndLongitudeIsBetween(double latitudeBottom,
List<CarWash> findByMapPosition_LatitudeIsBetweenAndMapPosition_LongitudeIsBetween(double latitudeBottom,
double latitudeTop,
double longitudeBottom,
double longitudeTop);

default List<CarWash> findCarWashesInSquare(double centerLatitude, double centerLongitude, double radius){
double latitudeShift = (180 * radius)/(Math.PI * 6378100);
double longitudeShift = (180 * radius)/(Math.PI * 6356800);
return findByLatitudeIsBetweenAndLongitudeIsBetween(
return findByMapPosition_LatitudeIsBetweenAndMapPosition_LongitudeIsBetween(
centerLatitude - latitudeShift,
centerLatitude + latitudeShift,
centerLongitude - longitudeShift,
Expand Down
Loading

0 comments on commit 9af5b42

Please sign in to comment.