Skip to content

PRA#02_Spring-Boot-LuisLopez-CreateUserAPIRest - #8

Open
Luiscuatro wants to merge 13 commits into
AlbertProfe:backend-spring-bootfrom
Luiscuatro:PRA02-LuisLopez
Open

PRA#02_Spring-Boot-LuisLopez-CreateUserAPIRest#8
Luiscuatro wants to merge 13 commits into
AlbertProfe:backend-spring-bootfrom
Luiscuatro:PRA02-LuisLopez

Conversation

@Luiscuatro

@Luiscuatro Luiscuatro commented Feb 2, 2025

Copy link
Copy Markdown

Summary of Changes in the Repository: PronunciationAppBack

1. User Entity Added

The User entity was introduced to define the basic structure for storing user data. It includes fields like id, name, email, password, and isActive. This seemed like a reasonable starting point for managing users.

2. UserRepository Implemented

A repository class (UserRepository) was created to interact with the database. It provides basic methods such as findAll, findById, save, and deleteById. At this point, it was mainly focused on covering the core operations.

3. UserController Created

A controller (UserController) was developed to handle HTTP requests for user operations. This included methods for creating, retrieving, updating, and deleting users. The implementation was basic, but it covered the necessary functionality.

4. H2 In-Memory Database Configured

The initial setup of the database was done using the H2 in-memory configuration, which seemed easier to work with during development. The local database setup was commented out to keep things simple at this stage.

5. Syntax Fixes

There were a few issues that needed fixing:

  • Missing quotes were corrected in the @GetMapping annotation of the getUserById method in UserController.
  • Incorrect parentheses in the @PostMapping annotation were adjusted to ensure proper functionality.

6. Annotation @Table Added

The @Table annotation was added to the User entity to ensure it mapped correctly to the APP_USERS table in the database. This was necessary to avoid any issues with naming.

7. H2 Database Setup Adjustments

Initially, the Hibernate ddl-auto property was set to create to let the database schema be generated automatically. Later, it was changed to update so that the database would retain data without resetting it every time the application restarted.

8. Getter and Setter for isActive Fixed

The isActive field in the User entity wasn’t working properly at first. After some adjustments, the getter (getActive) and setter (setActive) methods were implemented correctly.

9. Service Layer Implemented

A UserService class was introduced as a layer between the controller and the repository. It helped organize the business logic better and simplified the controller methods.

10. Controller Refactored

The UserController was updated to:

  • Use the UserService for all operations instead of interacting with the repository directly.
  • Add some validation, like checking whether a user exists before updating or deleting.

11. H2 Local Database Configured

The setup was updated to switch from the in-memory database to a local H2 database. This allows data to persist across application restarts, which feels more practical.

12. Endpoints Tested in Postman

The API endpoints were tested in Postman to ensure they worked correctly. This included testing GET, POST, PUT, and DELETE operations. The response codes and functionality were verified during the process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant