Skip to content

PRA#02_SpringBoot-AlberteMartinez-CreateUserAPIRest#19

Open
AlberteMB wants to merge 22 commits intoAlbertProfe:masterfrom
AlberteMB:PRA#02-backend-spring
Open

PRA#02_SpringBoot-AlberteMartinez-CreateUserAPIRest#19
AlberteMB wants to merge 22 commits intoAlbertProfe:masterfrom
AlberteMB:PRA#02-backend-spring

Conversation

@AlberteMB
Copy link
Copy Markdown

PRA#02-SpringBoot: Create User API Rest

✅ Completed Tasks

  • Create User entity
  • Implement UserController (REST API controller)
  • Develop UserRepository
  • Configure application properties with a local H2 database
  • Implement UserService
  • Test all endpoints with Postman

📌 Implementation Details

1. Create User Entity

  • I created both entities: User and Word. Initially, I attempted to use Lombok's @Data annotation, but it didn't work as expected, so I manually added all getters and setters.

2. Create UserController

  • I created controllers for both entities.
  • WordController includes all standard CRUD methods.
  • UserController implements CRUD methods along with additional custom endpoints.

3. Implement UserRepository

  • Both UserRepository and WordRepository extend JPA.
  • UserRepository includes custom queries for additional functionality.

4. Configure H2 Database

  • My initial plan was to test with PostgreSQL, but due to time constraints, I opted for H2.
  • I configured H2 with the create-drop strategy since I didn't need persistent data.

5. Develop UserService

  • I first created UserService as an interface and then implemented it in UserServiceImpl.
  • I followed the same approach for WordService and WordServiceImpl.

6. Postman Endpoint Testing

  • I successfully tested all endpoints using Postman.

🚀 Optional Enhancements

  • Implement data seeding using Faker
  • Advanced testing strategies
  • Implement new custom queries
  • Additional improvements

Custom Queries

  • I added custom queries in UserRepository, integrated them into UserService and UserServiceImpl, and exposed them via new endpoints in UserController.

Additional Improvements

  • I added all necessary annotations.
  • I also included an extra validation annotation for password formatting using @Pattern.

Below I add some screenshots.

Application.properties

application-properties

Console - Deleting and Get all words.

Console-Deleting-AllWords

Postman - AllUsers

Postman-AllUsers

Postman - User CreatedAfter

Postman-CreatedAfter

Postman - Delete User

Postman-DeleteUser

Postman - Email Contains

Postman-EmailContains

Postman - Get all active users

Postman-GetAllActiveUsers

Postman - Get User by ID

Postman-GetUserById

Postman - Get user by UserName

Postman-UserByUsername

Postman - UserName Contains

Postman-UserNameContains

Postman - User Count

Postman-UserCount

Postman - User Created

Postman-UserCreated

Postman - Updating User - createdAt

Postman-UpdatingUser-createdAt

Postman - All Words

Postman-AllWords

Postman - Get word by ID

Postman-GetWordById

Postman - Updating Word - Active

Postman-UpdatingWord-Active

Postman - Word created

Postman-WordCreated

Postman - Delete word

Postman-DeleteWord

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.

2 participants