Add entity layer#1
Merged
Merged
Conversation
This comment was marked as spam.
This comment was marked as spam.
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
backend/src/main/java/com/angel/autonow/driver/DriverEntity.java (1)
27-32: Avoid Lombok@Dataon JPA entities.Here it will generate
equals/hashCode/toStringfrom mutable fields and associations, which is brittle once the persistence state changes and easy to trip with ORM proxies. Prefer@Getter/@Setterplus 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
📒 Files selected for processing (7)
backend/.gitignorebackend/src/main/java/com/angel/autonow/driver/DriverEntity.javabackend/src/main/java/com/angel/autonow/order/OrderEntity.javabackend/src/main/java/com/angel/autonow/payment/PaymentEntity.javabackend/src/main/java/com/angel/autonow/payment/PaymentMethod.javabackend/src/main/java/com/angel/autonow/payment/PaymentStatus.javabackend/src/main/java/com/angel/autonow/rating/RatingEntity.java
This was referenced Apr 9, 2026
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary by CodeRabbit
Release Notes
New Features
Chores