mirror of
https://github.com/gmbrax/MediaManager-core.git
synced 2026-11-09 22:10:17 +00:00
This commit introduces significant improvements to the Album entity and its
update functionality, adding bidirectional relationship management with
AlbumHasArtist and implementing proper partial update semantics using
protobuf wrapper types.
Key enhancements:
Model Layer Improvements:
- Added OneToMany relationship from Album to AlbumHasArtist
* Bidirectional mapping with cascade ALL and orphan removal
* Maintains collection of album-artist associations
- Implemented helper methods for artist management:
* addArtist(): creates and adds AlbumHasArtist association
* removeArtist(): removes association by artist ID
* getArtists(): convenience method to extract Artist list from associations
- Added getters/setters for albumArtists collection
- Improved entity relationship management
Service Layer Enhancements:
- Refactored updateAlbum() to support partial updates
- Added boolean flags to control field updates:
* updateYear: controls whether year field should be modified
* updateNumberOfDiscs: controls disc count updates
* updateAlbumType: controls AlbumType relationship updates
* updateAlbumArt: controls AlbumArt relationship updates
- Only updates fields when explicitly provided by client
- Maintains existing values for non-provided fields
- Allows explicit null/removal of optional relationships
- Improved update logic clarity and maintainability
Handler Layer Improvements (UpdateAlbumHandler):
- Integrated protobuf wrapper type handling
- Uses hasYear(), hasNumberOfDiscs(), etc. to detect field presence
- Extracts values from Int32Value wrappers
- Passes presence flags to service layer
- Properly distinguishes between "not provided" and "null/0"
- Improved code formatting and readability
Protocol Buffer Enhancements:
- Added import for google.protobuf.wrappers
- Changed UpdateAlbumRequest optional fields to wrapper types:
* year: int32 → google.protobuf.Int32Value
* number_of_discs: int32 → google.protobuf.Int32Value
* fk_albumtype_id: int32 → google.protobuf.Int32Value
* fk_albumart_id: int32 → google.protobuf.Int32Value
- Enables proper optional field semantics
- Allows clients to omit fields from update requests
- Supports explicit null to remove relationships
Benefits of these changes:
- Proper partial update support: clients can update only specific fields
- Prevents unintended field overwrites with default values
- Bidirectional navigation from Album to Artists
- Cascade operations for album-artist associations
- Cleaner API semantics with explicit field presence detection
- Better alignment with REST PATCH semantics
- Maintains backward compatibility for required fields
Example usage:
- Update only name: provide name, omit other fields
- Remove AlbumType: provide fk_albumtype_id with value 0 or null
- Keep existing year: omit year field from request
- Update multiple fields: provide only the fields to change
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
77 lines
1.5 KiB
Protocol Buffer
77 lines
1.5 KiB
Protocol Buffer
syntax = "proto3";
|
|
|
|
import "google/protobuf/wrappers.proto"; // ← Adicione esse import!
|
|
|
|
option java_package = "com.mediamanager.protocol.messages";
|
|
option java_outer_classname = "AlbumMessages";
|
|
|
|
package mediamanager.messages;
|
|
|
|
message Album {
|
|
int32 id = 1;
|
|
string name = 2;
|
|
int32 year = 3;
|
|
int32 number_of_discs = 4;
|
|
string code = 5;
|
|
bool is_compilation = 6;
|
|
|
|
int32 fk_albumtype_id = 7;
|
|
int32 fk_albumart_id = 8;
|
|
|
|
int64 created_at = 9;
|
|
int64 updated_at = 10;
|
|
}
|
|
|
|
message CreateAlbumRequest {
|
|
string name = 1;
|
|
int32 year = 2;
|
|
int32 number_of_discs = 3;
|
|
string code = 4;
|
|
bool is_compilation = 5;
|
|
int32 fk_albumtype_id = 6;
|
|
int32 fk_albumart_id = 7;
|
|
}
|
|
|
|
message CreateAlbumResponse {
|
|
Album album = 1;
|
|
}
|
|
|
|
message GetAlbumsRequest {
|
|
|
|
}
|
|
|
|
message GetAlbumsResponse {
|
|
repeated Album albums = 1;
|
|
}
|
|
|
|
message GetAlbumByIdRequest {
|
|
int32 id = 1;
|
|
}
|
|
|
|
message GetAlbumByIdResponse {
|
|
Album album = 1;
|
|
}
|
|
|
|
message UpdateAlbumRequest {
|
|
int32 id = 1;
|
|
string name = 2;
|
|
google.protobuf.Int32Value year = 3; // ← Mudou!
|
|
google.protobuf.Int32Value number_of_discs = 4; // ← Mudou!
|
|
string code = 5;
|
|
bool is_compilation = 6;
|
|
google.protobuf.Int32Value fk_albumtype_id = 7; // ← Mudou!
|
|
google.protobuf.Int32Value fk_albumart_id = 8; // ← Mudou!
|
|
}
|
|
|
|
message UpdateAlbumResponse {
|
|
Album album = 1;
|
|
}
|
|
|
|
message DeleteAlbumRequest {
|
|
int32 id = 1;
|
|
}
|
|
|
|
message DeleteAlbumResponse {
|
|
bool success = 1;
|
|
string message = 2;
|
|
} |