r/SpringBoot • • Jun 12 '24

My First Spring boot project and my first reddit post

I mainly created projects using the MERN stack but recently found myself leaning towards Spring. This is my first personal project in Spring after completing Chad Darby's Udemy course and watching a bit of Bouali Ali's YouTube channel.

If you could spare some time, I would really appreciate any kind of feedback, advice, and guidance. Any mistakes I have made, or anything that I could or should change?

Here's my repo:

https://github.com/D1SCR3DIT/Employee_Management_System/tree/main

23 Upvotes

17 comments sorted by

2

u/thesarfo Jun 13 '24

Validate all your request DTOs for instance with @NotBlank and other annotations

And validate the DTO in your controller with @Valid annotations

Also you need to have more robust error handling

1

u/TheUnknown_73 Jun 13 '24

Okay got it. I kinda had an idea that the project was lacking in validation and error handling but since I am new to Springboot I really couldn't find a proper resource to learn that

2

u/thesarfo Jun 13 '24

this article pretty much covers the basics of validation

As for error handling, for starters , every error you throw in your Service classes should also be defined in your GlobalException handler, where you return an error response and an appropriate message and http status.

1

u/TheUnknown_73 Jun 13 '24

Thank you so much Just a side question. Does it make a difference if I add these annotations in the entity class itself instead of the DTOs

2

u/thesarfo Jun 13 '24

If you add annotations on the DTOs, you can still add them on the Entity class, because the DTOs are just a small chunk of an Entity, so you can add the annotations to the other fields in the Entity which are not inside the DTO.

Other than that it shouldn’t make a difference, I’ve seen people add annotations on both DTOs and Entities, it’s even more efficient imo

1

u/TheUnknown_73 Jun 13 '24

Okay I understand. Thanks a lot

1

u/escape_r00m Jun 13 '24

please help me how to learn spring boot in depth which resources are good ?

2

u/thesarfo Jun 13 '24

Spring Start Here by Laur Spilca, Spring Academy has some good courses, Dan Vega YouTube channel also has great videos

1

u/LookAtYourEyes Jun 12 '24

Maybe I'm missing something, haven't read through your whole project yet but what is this doing in your EmployeeController?

private EmployeeDTO employeeResponse(Employee employee) {

return new EmployeeDTO(

employee.getId(),

employee.getFirstName(),

employee.getLastName(),

employee.getUsername(),

employee.getEmail(),

employee.getRole(),

employee.getProjectId()

);

}

I don't see it being using anywhere else in the controller, and usually DTOs are mapped or created at the service layer. I might be missing something though.

1

u/TheUnknown_73 Jun 13 '24

I initially had all the logic in the controller layer itself and then later shifted all the logic part to the service layer. Must have forgotten to remove this function from the controller while I was doing that. I'll remove it now

2

u/[deleted] Jun 12 '24

RemindMe! 2 days

2

u/nightmare_0204 Jun 13 '24

What is the use of this project in our life? I guess this project is implemented in the course itself. Please correct me if I am wrong.

You can utilise this knowledge to build something unique on your own which can be utilised in your day to day life and also by others.

I hope my opinion will help you.