-
Notifications
You must be signed in to change notification settings - Fork 0
Add entity layer #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ build/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
| .claude | ||
|
|
||
| ### Env ### | ||
| .env | ||
61 changes: 61 additions & 0 deletions
61
backend/src/main/java/com/angel/autonow/driver/DriverEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,65 @@ | ||
| package com.angel.autonow.driver; | ||
|
|
||
| import com.angel.autonow.expertise.ExpertiseType; | ||
| import com.angel.autonow.vehicle.VehicleEntity; | ||
| import jakarta.persistence.*; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Pattern; | ||
| import lombok.AllArgsConstructor; | ||
| import org.hibernate.validator.constraints.URL; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| @Data | ||
| @Entity | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Table(name = "driver") | ||
| public class DriverEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @NotBlank(message = "First name is required") | ||
| @Column(name = "first_name", nullable = false) | ||
| private String firstName; | ||
|
|
||
| @NotBlank(message = "Last name is required") | ||
| @Column(name = "last_name", nullable = false) | ||
| private String lastName; | ||
|
|
||
| @NotBlank(message = "Phone number is required") | ||
| @Pattern(regexp = "^\\+?[0-9]{10,15}$", message = "Phone number must be valid") | ||
| @Column(name = "phone_number", nullable = false) | ||
| private String phoneNumber; | ||
|
|
||
| @NotBlank(message = "License number is required") | ||
| @Column(name = "license_number", unique = true, nullable = false) | ||
| private String licenseNumber; | ||
|
|
||
| @NotNull(message = "Expertise type is required") | ||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "expertise_type", nullable = false) | ||
| private ExpertiseType expertiseType; | ||
|
|
||
| @Column(name = "available") | ||
| private boolean available; | ||
|
|
||
| @URL(message = "Image URL must be valid") | ||
| @Column(name = "image_url") | ||
| private String imageUrl; | ||
|
|
||
| @OneToMany | ||
| @JoinTable( | ||
| name = "driver_vehicles", | ||
| joinColumns = @JoinColumn(name = "driver_id"), | ||
| inverseJoinColumns = @JoinColumn(name = "vehicle_id") | ||
| ) | ||
| private Set<VehicleEntity> vehicles; | ||
| } |
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/com/angel/autonow/exception/GlobalControllerExceptionHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
backend/src/main/java/com/angel/autonow/order/OrderEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package com.angel.autonow.order; | ||
|
|
||
| import com.angel.autonow.driver.DriverEntity; | ||
| import com.angel.autonow.user.UserEntity; | ||
| import com.angel.autonow.vehicle.VehicleEntity; | ||
| import com.angel.autonow.vehicle.VehicleType; | ||
| import jakarta.persistence.*; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Positive; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Data | ||
| @Entity | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Table(name = "orders") | ||
| public class OrderEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @NotNull(message = "User is required") | ||
| @ManyToOne | ||
| @JoinColumn(name = "user_id", nullable = false) | ||
| private UserEntity user; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "driver_id") | ||
| private DriverEntity driver; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "vehicle_id") | ||
| private VehicleEntity vehicle; | ||
|
|
||
| @NotNull(message = "Vehicle type is required") | ||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "vehicle_type", nullable = false) | ||
| private VehicleType vehicleType; | ||
|
|
||
| @NotBlank(message = "Pickup address is required") | ||
| @Column(name = "pickup_address", nullable = false) | ||
| private String pickupAddress; | ||
|
|
||
| @NotNull(message = "Pickup latitude is required") | ||
| @Column(name = "pickup_latitude", nullable = false) | ||
| private Double pickupLatitude; | ||
|
|
||
| @NotNull(message = "Pickup longitude is required") | ||
| @Column(name = "pickup_longitude", nullable = false) | ||
| private Double pickupLongitude; | ||
|
|
||
| @NotBlank(message = "Dropoff address is required") | ||
| @Column(name = "dropoff_address", nullable = false) | ||
| private String dropoffAddress; | ||
|
|
||
| @NotNull(message = "Dropoff latitude is required") | ||
| @Column(name = "dropoff_latitude", nullable = false) | ||
| private Double dropoffLatitude; | ||
|
|
||
| @NotNull(message = "Dropoff longitude is required") | ||
| @Column(name = "dropoff_longitude", nullable = false) | ||
| private Double dropoffLongitude; | ||
|
|
||
| @NotNull(message = "Status is required") | ||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "status", nullable = false) | ||
| private OrderStatus status; | ||
|
|
||
| @Positive(message = "Estimated price must be positive") | ||
| @Column(name = "estimated_price") | ||
| private Double estimatedPrice; | ||
|
|
||
| @Positive(message = "Final price must be positive") | ||
| @Column(name = "final_price") | ||
| private Double finalPrice; | ||
|
|
||
| @Positive(message = "Distance must be positive") | ||
| @Column(name = "distance_km") | ||
| private Double distanceKm; | ||
|
|
||
| @Positive(message = "Estimated duration must be positive") | ||
| @Column(name = "estimated_duration_minutes") | ||
| private Integer estimatedDurationMinutes; | ||
|
|
||
| @Column(name = "special_requirements") | ||
| private String specialRequirements; | ||
|
|
||
| @Column(name = "cancellation_reason") | ||
| private String cancellationReason; | ||
|
|
||
| @Column(name = "created_at", nullable = false, updatable = false) | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @Column(name = "updated_at") | ||
| private LocalDateTime updatedAt; | ||
|
|
||
| @PrePersist | ||
| protected void onCreate() { | ||
| createdAt = LocalDateTime.now(); | ||
| updatedAt = LocalDateTime.now(); | ||
| if (status == null) status = OrderStatus.CREATED; | ||
| } | ||
|
|
||
| @PreUpdate | ||
| protected void onUpdate() { | ||
| updatedAt = LocalDateTime.now(); | ||
| } | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
backend/src/main/java/com/angel/autonow/payment/PaymentEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package com.angel.autonow.payment; | ||
|
|
||
| import com.angel.autonow.order.OrderEntity; | ||
| import jakarta.persistence.*; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Positive; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Data | ||
| @Entity | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Table(name = "payments") | ||
| public class PaymentEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @NotNull(message = "Order is required") | ||
| @OneToOne | ||
| @JoinColumn(name = "order_id", nullable = false, unique = true) | ||
| private OrderEntity order; | ||
|
|
||
| @NotNull(message = "Amount is required") | ||
| @Positive(message = "Amount must be positive") | ||
| @Column(name = "amount", nullable = false) | ||
| private Double amount; | ||
|
StoynovAngel marked this conversation as resolved.
|
||
|
|
||
| @NotNull(message = "Payment method is required") | ||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "payment_method", nullable = false) | ||
| private PaymentMethod paymentMethod; | ||
|
|
||
| @NotNull(message = "Status is required") | ||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "status", nullable = false) | ||
| private PaymentStatus status; | ||
|
|
||
| @Column(name = "transaction_id", unique = true) | ||
| private String transactionId; | ||
|
|
||
| @NotBlank(message = "Currency is required") | ||
| @Size(min = 3, max = 3, message = "Currency must be a 3-letter code") | ||
| @Column(name = "currency", nullable = false) | ||
| private String currency; | ||
|
|
||
| @Column(name = "created_at", nullable = false, updatable = false) | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @Column(name = "updated_at") | ||
| private LocalDateTime updatedAt; | ||
|
|
||
| @PrePersist | ||
| protected void onCreate() { | ||
| createdAt = LocalDateTime.now(); | ||
| updatedAt = LocalDateTime.now(); | ||
| if (status == null) status = PaymentStatus.PENDING; | ||
| if (currency == null) currency = "EUR"; | ||
| } | ||
|
|
||
| @PreUpdate | ||
| protected void onUpdate() { | ||
| updatedAt = LocalDateTime.now(); | ||
| } | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/angel/autonow/payment/PaymentMethod.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.angel.autonow.payment; | ||
|
|
||
| public enum PaymentMethod { | ||
| CASH, | ||
| CREDIT_CARD, | ||
| DEBIT_CARD, | ||
| PAYPAL, | ||
| GOOGLE_PAY, | ||
| APPLE_PAY | ||
| } |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/angel/autonow/payment/PaymentStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.angel.autonow.payment; | ||
|
|
||
| public enum PaymentStatus { | ||
| PENDING, | ||
| COMPLETED, | ||
| FAILED, | ||
| REFUNDED | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.