Implement AlbumHasArtist relationship management with CRUD operations

This commit introduces the AlbumHasArtist join table entity management,
establishing the many-to-many relationship between Album and Artist
entities. This implementation follows the established repository pattern
used for other entities.

Key components implemented:

Model Layer:
- AlbumHasArtist entity representing the join table
- ManyToOne relationships to Album and Artist entities
- JPA annotations with proper foreign key constraints
- Complete getters and setters
- Custom toString method for debugging

Repository Layer:
- AlbumHasArtistRepository with EntityManager-based operations
- Full transaction management with proper rollback handling
- Methods: save, findAll, findById, deleteById
- No update method (join tables typically only need create/delete)

Service Layer:
- AlbumHasArtistService with business logic and validation
- Constructor injection of AlbumHasArtistRepository, AlbumRepository, ArtistRepository
- Relationship validation: ensures both Album and Artist exist before creating association
- Input validation for null/invalid IDs
- ID validation for all operations requiring entity lookup
- Comprehensive logging using Log4j2

Mapper Layer:
- AlbumHasArtistMapper for bidirectional entity/protobuf conversion
- Foreign key mapping for Album and Artist relationships
- Null safety checks and validation
- Proper handling of optional ID field

Action Handlers:
- CreateAlbumHasArtistHandler (albumhasartist.create)
- GetAlbumHasArtistHandler (albumhasartist.getAll)
- GetAlbumHasArtistByIdHandler (albumhasartist.getById)
- DeleteAlbumHasArtistHandler (albumhasartist.delete)
- HTTP status code handling: 200 (success), 400 (validation),
  404 (not found), 500 (server error)
- No update handler as join tables typically only require create/delete operations

Protocol Buffers:
- Complete proto definition with AlbumHasArtistMessages
- Messages support album_id and artist_id foreign keys
- CRUD message definitions (Create, Get, GetById, Delete)
- No Update messages as per join table requirements

Service Registration:
- AlbumHasArtistRepository initialized with EntityManagerFactory
- AlbumHasArtistService registered with ServiceLocator with required dependencies
- Ensures all AlbumHasArtist action handlers can resolve dependencies
- Proper dependency injection of AlbumRepository and ArtistRepository

The implementation follows best practices with proper error handling,
logging, validation, relationship integrity checks, and consistency with
existing codebase patterns. This enables proper many-to-many relationship
management between albums and artists.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Gustavo Henrique Santos Souza de Miranda
2025-12-07 21:03:20 -03:00
co-authored by Claude Sonnet 4.5
parent 21f5b93f48
commit f31c657d61
10 changed files with 536 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
syntax = "proto3";
option java_package = "com.mediamanager.protocol.messages";
option java_outer_classname = "AlbumHasArtistMessages";
package mediamanager.messages;
message AlbumHasArtist {
int32 id = 1;
int32 fk_album_id = 2;
int32 fk_artist_id = 3;
}
message CreateAlbumHasArtistRequest {
int32 fk_album_id = 1;
int32 fk_artist_id = 2;
}
message CreateAlbumHasArtistResponse {
AlbumHasArtist albumhasartist = 1;
}
message GetAlbumHasArtistsRequest {
}
message GetAlbumHasArtistsResponse {
repeated AlbumHasArtist albumhasartist = 1;
}
message GetAlbumHasArtistByIdRequest {
int32 id = 1;
}
message GetAlbumHasArtistByIdResponse {
AlbumHasArtist albumhasartist = 1;
}
message DeleteAlbumHasArtistRequest {
int32 id = 1;
}
message DeleteAlbumHasArtistResponse {
bool success = 1;
string message = 2;
}