r/SpringBoot • • Dec 30 '24

Full Stack Web Application - Spring, Angular and MySQL

Hello guys,

Hope your are all good. I'm posting on reddit because i'm developing for a while a Full Stack Application, using Spring, Angular and MySQL.

The goal of this application, is to manage all the eletronic equipments of a company and track each equipment (history).

So, i'm also seeking for a job as a dev and i thought this could be a good idea to rich my portfolio experience, since i have none.

So the main goal of the application is:

- User

- Add User

- We can create a user assigning him to a department, location or neither

- Edit User

- Delete User

- View Equipments

- Assign user to an equipment or multiple equipments

- Equiment

- Add Equipment

- We can create a equipmentssigning him to a department, location or neither

- Edit Equipment

- Delete Equipment

- View User owner

- Assign an equipment to an user

This are the main features at the moment, of this application. Later i will do improvements such as:

- Add Spring Security (Implementation of JWT Authentication and Login)

- Add a dashboard for admin, shoqwing cards with stats or graphs (Equipments p/department, Total of Users, Users p/department, Equipment p/status, etc...)

- Implement a notification system, to alert the admin the equipments that are on use or returned from the warranty.

Please, i would love some feedback from you, and i don't mind if my code it's not the best but the logic is there. If u have any thoughts ply don't mind to ask.

All i need is your opinions, improvements, or something i might be doing wrong.

I'm excited to hear from you guys !

Here goes my git hub repo: https://github.com/programtiago/management-app

Wish you the best,

Tiago

31 Upvotes

40 comments sorted by

15

u/WaferIndependent7601 Dec 30 '24
  • Tests are missing

  • As usual: don't put Controllers in Controller package

  • DepartmentController:

    • you're mixing Optionals and nulls

    • getById calls departmentService.getById twice

    • Throwing an Exception will result in a 500. When no department is found you should return a 404

  • If you have only one Implementation, don't create an Interface. Espacially when you're not even using the Interface (DepartmentServiceImpl departmentService)

  • EquipmentController:

    • getting all equipment should (and will) return an empty list when no equipment is present. That's why you should write tests!

    • getById: if id is null you'll get an error (and you're calling the service twice again)

  • Equipment:

    • private String type; //SCANNER, SCREEN, MOUSE, DESKTOP

      • Why don't you use an enum here?

    • Same for the other Strings

    • This class is an entity but you're also using it as DTO

I think you will find several bugs when you start writing tests. The tests can be easy, just do end to end tests.

You should also use flyway or liquibase to create your tables.

Install SonarQube plugin and you will find several other small issues.

Postgres is always better than mysql. Use Postgres if possible.

3

u/Formal_Hippo8991 Dec 30 '24

Thank you u/WaferIndependent7601, you're a machine i see xD The road will be though. Really appreciated with the tips.

2

u/Rich_Weird_5596 Dec 31 '24

Don't put controller in controller package ? Why ? What's the alternative? Vertical slices ? If project grows it can be total hell to maintain.

2

u/WaferIndependent7601 Dec 31 '24

Put it in packages that fit your usecases.

Yes: it’s hell if you have 200 controllers in a controller package.

1

u/Formal_Hippo8991 Dec 31 '24

Ok, i'm understanding but when i had my internship, my mentor teached me on this way, and i see a lot of people doing it, so that's why i created a folder for all the controllers.

1

u/Formal_Hippo8991 Dec 31 '24

Btw, how u would do the documentation, using Swagger ? I already integrated Swagger UI

2

u/WaferIndependent7601 Dec 31 '24

Openapi and swagger, yes. Annotate controller or write api first and generate the controllers from the api

1

u/Formal_Hippo8991 Dec 30 '24

I ended mixing some things on the project, but i think it's normal, it makes part of learning i guess. But i will take your improvements and from the other users and make changes of course.

So i should be doing by now, the test at the same time, it's what you're trying to say to me ? What do you use ?

4

u/WaferIndependent7601 Dec 30 '24

I would start writing tests. Use mockmvc and do some easy tests. Fix the bugs you’ll find. When all tests are green: start refactoring. If you do so you will know that your refactorings are not breaking your tests and you have not changed any behavior

1

u/Formal_Hippo8991 Dec 30 '24

Ok, it will be new to me using mockvc. Anyway, i have to read about it and then i will make end to end tests, as u mentioned.

1

u/[deleted] Dec 30 '24 edited Apr 17 '26

Data brokers and AI scrapers were using my info. Not anymore. Redact let me bulk delete posts across Reddit, Twitter, Discord and Instagram while handling broker opt outs too.

thumb enjoy hungry rich wide boast thought snatch bow vast

1

u/Formal_Hippo8991 Dec 30 '24

Really Thanks, that might be interesting since I never used that on Spring Boot.

2

u/WaferIndependent7601 Dec 31 '24

I was following the test pyramid for a long time. I the read a Reddit post where someone said that he’s not writing many unit tests any more. At first it was like „ok that’s total bs what he says“. After thinking about what tests fail when I realized: unit tests for code coverage are bullshit. Only write unit tests for stuff that calculates some things. Having a test that verifies that service a is called makes not much sense. Write more integration tests and you can refactor way better and faster.

The pyramid is from a time where integration tests were hard to write. If you have a monolith that has no api and you can only write unit tests or frontend tests: you need unit tests. But testing the api is normally enough and good tests there will help you way more.

1

u/[deleted] Jan 01 '25 edited Apr 17 '26

Redact cleaned up all of my comments. Bulk deletion and editing is a feature supported to make sure that AI scrapers can't access my data for training.

consider sugar ten enter subtract governor bear pie detail label

1

u/WaferIndependent7601 Jan 01 '25

If you cannot test it with an integration test, how should it ever happen? There are things like „catch an exception that could occur but will never occur“ like when you have to put null in but you’ll check before that it cannot be null. Is this worth testing?

1

u/[deleted] Jan 01 '25 edited Apr 17 '26

Data brokers and AI scrapers were using my info. Not anymore. Redact let me bulk delete posts across Reddit, Twitter, Discord and Instagram while handling broker opt outs too.

slap liquid fuel waiting file ripe bike society mighty plough

4

u/[deleted] Dec 30 '24 edited Apr 17 '26

Stop letting data brokers profit from your old posts. I used Redact to wipe mine from Reddit. Also supports Twitter, Facebook, Discord, instagram and more in one batch.

squash quickest entertain smell person include silky sulky pot water

2

u/WaferIndependent7601 Dec 30 '24

Java 17 is LTS

1

u/Formal_Hippo8991 Dec 30 '24

So, i will keep with that ! Thanks again

2

u/WaferIndependent7601 Dec 30 '24

Changing it is just one line and you could use the newer features. But it’s up to you. I like to use the newest lts version

1

u/Formal_Hippo8991 Dec 30 '24

U mean, on build.gradle right ?

2

u/WaferIndependent7601 Dec 30 '24

Right and install Java 21 of course

2

u/[deleted] Dec 30 '24 edited Apr 17 '26

Redact decided this post had to go, so away it went. Deleted. Removed. Mass deleted even. Privacy and security are the big wins here.

friendly decide relieved gold cable innate spotted jellyfish history compare

1

u/Formal_Hippo8991 Dec 30 '24

I will take notes and study more. This is way too far to be completed :D

By the way, if you don't mind, how can i put my project in a way more atracctive to the recruiters ?

2

u/[deleted] Dec 30 '24 edited Apr 17 '26

Scrubbed clean. Redact helped me bulk remove years of comments and posts so data brokers and AI crawlers have nothing to feast on.

tease afterthought encourage employ waiting tender roll sand label grey

1

u/Formal_Hippo8991 Dec 30 '24

Right ! I was about to do that, but only on the very final of the project. I was thinking too make the UML Diagram too have a view of the classes and to understand the relationships between entitys.

2

u/[deleted] Dec 30 '24 edited Apr 17 '26

I used Redact to automate removals from databrokers and social networks. This post was among the batch deleted.

salt rustic steep label connect modern selective jeans wide pot

2

u/Formal_Hippo8991 Dec 30 '24

As I said, i have to explore mate. The dev community is awesome ! I will take a look and i will post updates.

1

u/GR-Dev-18 Dec 31 '24 edited Dec 31 '24

Sir can u say where I should add response entity

1

u/[deleted] Dec 31 '24 edited Apr 17 '26

Data Brokers don't stand a chance because I mass delete all of my content using Redact - No AI training on my data, thank you very much.

governor meadow late include swim person spoon grey middle observation

1

u/GR-Dev-18 Dec 31 '24

Sorry, auto correct 😞, anyway thank you

1

u/[deleted] Dec 31 '24 edited Apr 17 '26

If you're reading this, the original post got nuked by Redact. I use it to automatically purge my digital footprint from social networks, people search sites and messaging apps.

jar ten test include point sophisticated angle roof simplistic bedroom

3

u/amulli21 Dec 30 '24

And you somehow managed to forget to include the repo into the post

1

u/Formal_Hippo8991 Dec 30 '24

Uops.. thanks

2

u/Mikey-3198 Dec 30 '24

The handling of not founds is inconsistent. In the DepartmentController there is 3 ways your currently doing this

1 - Returning a list & checking isEmpty then throwing Exception (more on this below)

2 - Returning a null then throwing a ResourceNotFoundException

3 - Catching a ResourceNotFoundException that's thrown by the service then a 404 via a response entity.

I'd look at making this consistent. My preference would be to return an optional from the relevant services then return a ResponseEntity, 404 if its empty or 200 if the action succeeded. Key thing is that this is consistent otherwise it creates a lot of noise.

The endpoints can also be improved to make them more restful. The /all endpoint will throw an exception if getAllDepartments isEmpty. I’d expect this endpoint to simply return an empty list with a HTTP 200, no need to check for empty or throw an exception. Perfectly fine to return an empty collection if no resources exist. I’d also expect this endpoint to just be GET /api/v1/departments i.e no need for “/all” in the route.

Naming wise to create a new resource I'd expect a POST to /api/v1/departments. No need for “/new”.

1

u/Formal_Hippo8991 Dec 30 '24

Thanks u/Mikey-3198 for your reply. You're right, i did a mess on the exceptions and maybe create too much noise on the backend, wich can affect the performance of the responses coming from server. Anyway, thank you for the tips mate :)

2

u/Mikey-3198 Dec 30 '24

your welcome :)

2

u/WaferIndependent7601 Jan 02 '25

So you added your first Test - good start.

Some additions:

  • Do you unserstand what Transactional does on Tests?

  • public not needed on tests (this would be found by sonarqube)

  • Use assertJ, it's easier to use and you can use better methods.

  • One test does nothing.

1

u/Formal_Hippo8991 Jan 02 '25

From what I read, the behavior of Transactional is the “isolation” for a specific test, its transaction but alone. This can be multiples operations on DB and like this we allow the rollback. Am i right ? I assume that isn’t needed. One Test does nothing what you mean ? I know I can have multiple tests scenarios, right ?

1

u/Formal_Hippo8991 Jan 02 '25

Oh i got it ! U saw the commit that had just one test implementation for getting all users… right !