Skip to content

Add entity layer#1

Merged
StoynovAngel merged 2 commits into
mainfrom
feat/entity-db-layer
Mar 30, 2026
Merged

Add entity layer#1
StoynovAngel merged 2 commits into
mainfrom
feat/entity-db-layer

Conversation

@StoynovAngel
Copy link
Copy Markdown
Owner

@StoynovAngel StoynovAngel commented Mar 19, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added driver profile management with vehicle associations
    • Introduced booking system with location tracking and status monitoring
    • Enabled payment processing supporting multiple methods (cards, digital wallets, cash)
    • Added customer rating system for completed orders
    • Enhanced form validation with detailed error feedback
  • Chores

    • Updated build configuration

@coderabbitai

This comment was marked as spam.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (1)
backend/src/main/java/com/angel/autonow/driver/DriverEntity.java (1)

27-32: Avoid Lombok @Data on JPA entities.

Here it will generate equals/hashCode/toString from mutable fields and associations, which is brittle once the persistence state changes and easy to trip with ORM proxies. Prefer @Getter/@Setter plus explicit equality/string configuration, and apply the same change to the other new entities as well.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/main/java/com/angel/autonow/driver/DriverEntity.java` around
lines 27 - 32, Remove Lombok's `@Data` from the DriverEntity class and replace it
with `@Getter` and `@Setter`; add explicit equality and toString configuration by
using Lombok's `@EqualsAndHashCode`(onlyExplicitlyIncluded = true) and
`@ToString`(onlyExplicitlyIncluded = true), annotate the identifier field (e.g.,
the id property) with `@EqualsAndHashCode.Include` and annotate only simple,
non-relational fields you want included in `@ToString`; apply the same replacement
(remove `@Data` -> add `@Getter/`@Setter and explicit `@EqualsAndHashCode/`@ToString
with onlyExplicitlyIncluded=true and includes on id/simple fields) to the other
new JPA entity classes as well to avoid generating equals/hashCode/toString from
mutable associations and proxies.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/src/main/java/com/angel/autonow/driver/DriverEntity.java`:
- Around line 51-55: The expertise Set in DriverEntity is null when using
Lombok's `@Builder` and can cause NPEs on mutations; annotate the field with
`@Builder.Default` and initialize it to an empty HashSet (e.g., new HashSet<>())
so the collection is non-null for operations like expertise.add(...). Keep the
existing JPA annotations (`@ElementCollection`, `@CollectionTable`, `@Enumerated`,
`@Column`) and only add the `@Builder.Default` plus the empty-set initializer to the
expertise field.

In `@backend/src/main/java/com/angel/autonow/order/OrderEntity.java`:
- Around line 60-64: Change the persisted price fields in OrderEntity from
Double to java.math.BigDecimal by replacing the fields estimatedPrice and
finalPrice with BigDecimal types, update their `@Column` definitions to specify
precision and scale (e.g., precision and scale attributes), and modify their
setters (or use `@PrePersist/`@PreUpdate validation) to enforce non-negative
values and normalize scale via setScale(desiredScale, RoundingMode.HALF_UP)
before saving; also update any getters, constructors, and usages of
getEstimatedPrice()/getFinalPrice() and places that construct these values to
use BigDecimal arithmetic instead of double operations.

In `@backend/src/main/java/com/angel/autonow/payment/PaymentEntity.java`:
- Around line 25-31: PaymentEntity currently allows order and user to disagree;
add an invariant check in PaymentEntity to prevent saving inconsistent data by
verifying user.equals(order.getUser()) before persist/update. Implement a
private validation method and annotate it with `@PrePersist` and `@PreUpdate` inside
PaymentEntity that throws an IllegalStateException (or a domain-specific
exception) when order is null, order.getUser() is null, or the two users differ;
alternatively remove the redundant user field and always derive the payer via
getOrder().getUser() if you prefer removing duplication.
- Around line 33-34: Replace the floating-point Double amount in PaymentEntity
with java.math.BigDecimal: change the field type for "amount" in class
PaymentEntity to BigDecimal, update its getter/setter/constructors, and annotate
the `@Column` with an appropriate precision and scale (e.g., precision=19,
scale=2) to enforce fixed-scale monetary values; also ensure any places that
construct or persist PaymentEntity convert/determine scale using
BigDecimal#setScale(RoundingMode) or equivalent. Do the same for the price
fields in OrderEntity (replace Double with BigDecimal, update
getters/setters/constructors, and add matching `@Column` precision/scale) so all
monetary values use BigDecimal consistently.

In `@backend/src/main/java/com/angel/autonow/rating/RatingEntity.java`:
- Around line 47-48: The rating field in RatingEntity currently accepts any
integer; constrain it to 1..5 by adding validation and a DB check: annotate the
Integer rating field in class RatingEntity with
javax.validation.constraints.@Min(1) and `@Max`(5) (or enforce in the
setter/getter) and add a persistent DB-level check (e.g., Hibernate
`@org.hibernate.annotations.Check` or a columnDefinition CHECK constraint like
"CHECK (rating BETWEEN 1 AND 5)") so both application validation and the
database prevent values outside 1..5.
- Around line 35-45: RatingEntity currently stores independent user and driver
FKs that can diverge from the referenced OrderEntity; remove the redundant
UserEntity user and DriverEntity driver fields from RatingEntity and instead
derive the user/driver from the associated OrderEntity (use
order.getUser()/order.getDriver() wherever consumer code expects rating
user/driver), or alternatively change the mapping to share the same FK with
OrderEntity using a shared primary/foreign key pattern (e.g., `@MapsId`) so
RatingEntity.order is authoritative; update any code that accessed
RatingEntity.user or RatingEntity.driver to use RatingEntity.order.getUser() and
RatingEntity.order.getDriver() (or the new shared-key mapping) and adjust
persistence logic/tests accordingly.

---

Nitpick comments:
In `@backend/src/main/java/com/angel/autonow/driver/DriverEntity.java`:
- Around line 27-32: Remove Lombok's `@Data` from the DriverEntity class and
replace it with `@Getter` and `@Setter`; add explicit equality and toString
configuration by using Lombok's `@EqualsAndHashCode`(onlyExplicitlyIncluded =
true) and `@ToString`(onlyExplicitlyIncluded = true), annotate the identifier
field (e.g., the id property) with `@EqualsAndHashCode.Include` and annotate only
simple, non-relational fields you want included in `@ToString`; apply the same
replacement (remove `@Data` -> add `@Getter/`@Setter and explicit
`@EqualsAndHashCode/`@ToString with onlyExplicitlyIncluded=true and includes on
id/simple fields) to the other new JPA entity classes as well to avoid
generating equals/hashCode/toString from mutable associations and proxies.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 57936007-f6ef-40d0-8587-36c98083f70b

📥 Commits

Reviewing files that changed from the base of the PR and between 048db4b and 30d6a10.

📒 Files selected for processing (7)
  • backend/.gitignore
  • backend/src/main/java/com/angel/autonow/driver/DriverEntity.java
  • backend/src/main/java/com/angel/autonow/order/OrderEntity.java
  • backend/src/main/java/com/angel/autonow/payment/PaymentEntity.java
  • backend/src/main/java/com/angel/autonow/payment/PaymentMethod.java
  • backend/src/main/java/com/angel/autonow/payment/PaymentStatus.java
  • backend/src/main/java/com/angel/autonow/rating/RatingEntity.java

Comment thread backend/src/main/java/com/angel/autonow/driver/DriverEntity.java Outdated
Comment thread backend/src/main/java/com/angel/autonow/order/OrderEntity.java
Comment thread backend/src/main/java/com/angel/autonow/payment/PaymentEntity.java Outdated
Comment thread backend/src/main/java/com/angel/autonow/payment/PaymentEntity.java
Comment thread backend/src/main/java/com/angel/autonow/rating/RatingEntity.java Outdated
Comment thread backend/src/main/java/com/angel/autonow/rating/RatingEntity.java
@StoynovAngel StoynovAngel merged commit 5fc39b8 into main Mar 30, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant