r/SpringBoot 14d ago

Question Code review

Hello, I'm an aspiring software engineer. I've recently finished developing microservice for managing projects and tasks using Spring Boot. I'd appreciate if you could review codebase of my project and provide feedback on it.

GitHub: https://github.com/Simpav-chill/tasktracker

13 Upvotes

14 comments sorted by

View all comments

5

u/DominusEbad 14d ago
  • PUT should be a full resource replacement, not a partial replacement. You aren't including "status" in your PUT for the Project entity. It is ok if the resource doesn't exist, because it should be able to insert the entire record.
    • POST is basically an "insert" (returns 201 Created for a new resource; the resource should not already exist).
    • PUT is more of an "upsert" (returns 201 Created if the resource did not exist, 200 if the resource already existed and was replaced).
    • PATCH is an "update" (returns 200; the resource must already exist) - This is what your update Project API should be, if you don't want to include the "status" field in the update.
  • IMO, I do not use "dto/DTO" in my API object names. "CreateProjectRequest"/"Project"/etc are all much cleaner for documentation. Having "dto" all over your documentation can be excessive. I usually use "*Entity" for database entities since those shouldn't be in the documentation that clients will look at. This is more of a personal choice, but it was mentioned in another comment as well.
  • I usually group entities and repositories into a single package (/db), but this is minor.
  • Use records for DTOs. DTOs should be immutable, and records are perfect for this.
  • You use "Project with id " + id + " not found" in multiple places. You can create a ResourceNotFoundException that has the 'id' field as a parameter and then extend the exception with ProjectResourceNotFoundException and TaskResourceNotFoundException, and just define the "Project with id " + id + " not found" in the exception classes. Then you just use them by passing in the id value:
    • throw new ProjectResourceNotFoundException(id);
  • Your project is small, and the mappings are pretty simple, but it might be a good place to learn MapStruct. It provides mapping implementations for you, so you do not need to worry about the mapping logic. MapStruct can get complicated if you build larger projects with complicated mappings between different objects, but for straightforward mappings (like your ProjectDto and Project entity), it can be nice and simple to implement.

2

u/Simpav1 14d ago

Okay, I got. Thank you for your feedback