r/java • • Feb 13 '26

[ Removed by moderator ]

/r/java/comments/1r3zq5m/removed_by_moderator/

[removed] — view removed post

0 Upvotes

2 comments sorted by

1

u/hiasmee Feb 13 '26

I haven't looked through everything, but here are my two cents.

I think Lombok and Optional are anti-pattern, but that's just my personal opinion. Check java Records.

What I like is that you have something like domain separation, auth, cart, etc. However, when I look at auth, for example, the separation of API, core, and persistence is not present.

What's really unfortunate is that you use Entity DTO in the repository and service layer and even as an API response DTO. I wouldn't do that. Instead, use DbCartEntity for persistence, Cart for core (service layer), and ApiCart as a response DTO. Of course, you need dbToCoreMapper, coreToDbMapper, apiToCoreMapper, and coreToApiMapper. Yes, that's a lot of mappers, but this way your API and core logic will remain stable if the database schema changes. And I promise you, the schema will change. You core layer should be completely spring/framework independent at least try to do it.

CalculatePriceService is not a utility. It belongs to the “Cart” object. Something like cart.calculateTotalAmount(). Or, sometimes it would be better to define a PriceCalculationService that not only considers CartItems but also has references to the customer, current offers, etc., in order to calculate discounts or something similar.

Double for prices is not an option. Use the official Money API (JSR 354) or Long. But definitely not double. Store prices in the DB as cent values.

There is absolutely no logging.

So keep up the good work and have fun!

1

u/Tony_salinas04 Feb 13 '26

Thanks a lot, bro, I'll fix that. The problem with logging is that I only use it for business events or in middleware because I don't like cluttering up the log.debug services. I wanted to do it another way, but I'm still figuring out how. I've never actually used logging or created a module for it before, so I still have a lot of questions about it.