From 2d77358d50e085e285550ef93e378948e57d0375 Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Wed, 3 Dec 2025 03:15:39 -0300 Subject: [PATCH 1/3] Implement BitDepth Management with CRUD Operations - Add `BitDepth` entity with JPA annotations and database mapping. - Create repository, service, and delegate handlers for BitDepth CRUD operations: `bitdepth.create`, `bitdepth.getAll`, `bitdepth.getById`, `bitdepth.update`, `bitdepth.delete`. - Introduce Protobuf definitions for BitDepth messages. - Register BitDepth service and handlers in `DelegateActionManager`. - Create `BitDepthMapper` to map between Protobuf and entity models. - Enhance error handling and logging for BitDepth operations. --- .../mediamanager/mapper/BitDepthMapper.java | 39 +++++++ .../java/com/mediamanager/model/BitDepth.java | 32 ++++++ .../repository/BitDepthRepository.java | 100 ++++++++++++++++++ .../service/bitdepth/BitDepthService.java | 61 +++++++++++ .../delegate/DelegateActionManager.java | 12 +-- .../bitdepth/CreateBitDepthHandler.java | 51 +++++++++ .../bitdepth/DeleteBitDepthHandler.java | 62 +++++++++++ .../bitdepth/GetBitDepthByIdHandler.java | 56 ++++++++++ .../handler/bitdepth/GetBitDepthHandler.java | 48 +++++++++ .../bitdepth/UpdateBitDepthHandler.java | 65 ++++++++++++ src/main/proto/bitdepth.proto | 53 ++++++++++ 11 files changed, 572 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/mediamanager/mapper/BitDepthMapper.java create mode 100644 src/main/java/com/mediamanager/model/BitDepth.java create mode 100644 src/main/java/com/mediamanager/repository/BitDepthRepository.java create mode 100644 src/main/java/com/mediamanager/service/bitdepth/BitDepthService.java create mode 100644 src/main/java/com/mediamanager/service/delegate/handler/bitdepth/CreateBitDepthHandler.java create mode 100644 src/main/java/com/mediamanager/service/delegate/handler/bitdepth/DeleteBitDepthHandler.java create mode 100644 src/main/java/com/mediamanager/service/delegate/handler/bitdepth/GetBitDepthByIdHandler.java create mode 100644 src/main/java/com/mediamanager/service/delegate/handler/bitdepth/GetBitDepthHandler.java create mode 100644 src/main/java/com/mediamanager/service/delegate/handler/bitdepth/UpdateBitDepthHandler.java create mode 100644 src/main/proto/bitdepth.proto diff --git a/src/main/java/com/mediamanager/mapper/BitDepthMapper.java b/src/main/java/com/mediamanager/mapper/BitDepthMapper.java new file mode 100644 index 0000000..873629c --- /dev/null +++ b/src/main/java/com/mediamanager/mapper/BitDepthMapper.java @@ -0,0 +1,39 @@ +package com.mediamanager.mapper; + +import com.mediamanager.model.BitDepth; +import com.mediamanager.protocol.messages.BitDepthMessages; + +public class BitDepthMapper { + public static BitDepthMessages.BitDepth toProtobuf(BitDepth entity) { + if (entity == null){ + return null; + } + + String value = entity.getValue(); + if (value == null) { + throw new IllegalArgumentException("Bit depth value cannot be null"); + } + BitDepthMessages.BitDepth.Builder builder = BitDepthMessages.BitDepth.newBuilder() + .setValue(value); + + Integer id = entity.getId(); + if (id != null && id > 0) { + builder.setId(id); + } + + return builder.build(); + } + + public static BitDepth toEntity(BitDepthMessages.BitDepth protobuf) { + if (protobuf == null) { + return null; + } + BitDepth entity = new BitDepth(); + + if (protobuf.getId() > 0) { + entity.setId(protobuf.getId()); + } + entity.setValue(protobuf.getValue()); + return entity; + } +} diff --git a/src/main/java/com/mediamanager/model/BitDepth.java b/src/main/java/com/mediamanager/model/BitDepth.java new file mode 100644 index 0000000..3b80217 --- /dev/null +++ b/src/main/java/com/mediamanager/model/BitDepth.java @@ -0,0 +1,32 @@ +package com.mediamanager.model; + +import jakarta.persistence.*; + +@Entity +@Table(name = "bit_depth") +public class BitDepth { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(nullable = false) + private String value; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} + diff --git a/src/main/java/com/mediamanager/repository/BitDepthRepository.java b/src/main/java/com/mediamanager/repository/BitDepthRepository.java new file mode 100644 index 0000000..24b9dc9 --- /dev/null +++ b/src/main/java/com/mediamanager/repository/BitDepthRepository.java @@ -0,0 +1,100 @@ +package com.mediamanager.repository; + +import com.mediamanager.model.BitDepth; +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; +import java.util.Optional; + +public class BitDepthRepository { + private static final Logger logger = LogManager.getLogger(BitDepthRepository.class); + + private final EntityManagerFactory entityManagerFactory; + + public BitDepthRepository(EntityManagerFactory entityManagerFactory) { + this.entityManagerFactory = entityManagerFactory; + } + + public BitDepth save(BitDepth bitDepth) { + logger.debug("Saving BitDepth: {}", bitDepth.getValue()); + EntityManager em = entityManagerFactory.createEntityManager(); + em.getTransaction().begin(); + try { + em.persist(bitDepth); + em.getTransaction().commit(); + logger.debug("BitDepth saved with ID: {}", bitDepth.getId()); + return bitDepth; + } catch (Exception e) { + em.getTransaction().rollback(); + logger.error("Error saving BitDepth", e); + throw e; + } finally { + if (em.isOpen()) em.close(); + } + } + + public List findAll(){ + logger.debug("Finding all BitDepths"); + EntityManager em = entityManagerFactory.createEntityManager(); + try{ + return em.createQuery("SELECT b FROM BitDepth b ORDER BY b.value", BitDepth.class).getResultList(); + }finally { + if (em.isOpen()) em.close(); + } + } + + public Optional findById(Integer id){ + logger.debug("Finding BitDepth by ID: {}", id); + EntityManager em = entityManagerFactory.createEntityManager(); + try{ + BitDepth bitDepth = em.find(BitDepth.class, id); + return Optional.ofNullable(bitDepth); + }finally { + if (em.isOpen()) em.close(); + } + } + + public BitDepth update(BitDepth bitDepth){ + logger.debug("Updating BitDepth ID: {}", bitDepth.getId()); + EntityManager em = entityManagerFactory.createEntityManager(); + em.getTransaction().begin(); + try{ + BitDepth updated = em.merge(bitDepth); + em.getTransaction().commit(); + logger.debug("BitDepth updated successfully"); + return updated; + }catch (Exception e){ + em.getTransaction().rollback(); + logger.error("Error updating BitDepth", e); + throw e; + }finally { + if (em.isOpen()) em.close(); + } + } + + public boolean deleteById(Integer id){ + logger.debug("Deleting BitDepth by ID: {}", id); + EntityManager em = entityManagerFactory.createEntityManager(); + em.getTransaction().begin(); + try{ + BitDepth bitDepth = em.find(BitDepth.class, id); + if (bitDepth == null) { + em.getTransaction().rollback(); + return false; + } + em.remove(bitDepth); + em.getTransaction().commit(); + logger.debug("BitDepth deleted successfully"); + return true; + } catch (Exception e) { + em.getTransaction().rollback(); + logger.error("Error deleting BitDepth", e); + throw e; + }finally { + if (em.isOpen()) em.close(); + } + } +} diff --git a/src/main/java/com/mediamanager/service/bitdepth/BitDepthService.java b/src/main/java/com/mediamanager/service/bitdepth/BitDepthService.java new file mode 100644 index 0000000..495e5d0 --- /dev/null +++ b/src/main/java/com/mediamanager/service/bitdepth/BitDepthService.java @@ -0,0 +1,61 @@ +package com.mediamanager.service.bitdepth; + +import com.mediamanager.model.BitDepth; +import com.mediamanager.repository.BitDepthRepository; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; +import java.util.Optional; + +public class BitDepthService { + private static final Logger logger = LogManager.getLogger(BitDepthService.class); + private final BitDepthRepository bitDepthRepository; + + public BitDepthService(BitDepthRepository bitDepthRepository) { + this.bitDepthRepository = bitDepthRepository; + } + public BitDepth createBitDepth(String value){ + logger.info("Creating bit-depth: {}", value); + if (value == null || value.trim().isEmpty()) { + throw new IllegalArgumentException("Bit-depth value cannot be empty"); + } + BitDepth bitDepth = new BitDepth(); + bitDepth.setValue(value.trim()); + return bitDepthRepository.save(bitDepth); + + } + + public List getAllBitDepths(){ + logger.info("Getting all bit-depths"); + return bitDepthRepository.findAll(); + } + + public Optional getBitDepthById(Integer id){ + logger.info("Getting bit-depth by ID: {}", id); + return bitDepthRepository.findById(id); + } + + public Optional updateBitDepth(Integer id, String value){ + logger.info("Updating bit-depth ID {}: {}", id, value); + + if (value == null || value.trim().isEmpty()) { + throw new IllegalArgumentException("Bit-depth value cannot be empty"); + } + Optional existingBitDepth = bitDepthRepository.findById(id); + if(existingBitDepth.isEmpty()){ + logger.warn("Bit-depth not found with ID: {}", id); + return Optional.empty(); + } + BitDepth bitDepth = existingBitDepth.get(); + bitDepth.setValue(value.trim()); + BitDepth updatedBitDepth = bitDepthRepository.update(bitDepth); + return Optional.of(updatedBitDepth); + + } + + public boolean deleteBitDepth(Integer id){ + logger.info("Deleting bit-depth ID: {}", id); + return bitDepthRepository.deleteById(id); + } +} diff --git a/src/main/java/com/mediamanager/service/delegate/DelegateActionManager.java b/src/main/java/com/mediamanager/service/delegate/DelegateActionManager.java index ee5ae38..338d6a7 100644 --- a/src/main/java/com/mediamanager/service/delegate/DelegateActionManager.java +++ b/src/main/java/com/mediamanager/service/delegate/DelegateActionManager.java @@ -2,10 +2,9 @@ package com.mediamanager.service.delegate; import com.google.protobuf.ByteString; import com.mediamanager.protocol.TransportProtocol; -import com.mediamanager.repository.ComposerRepository; -import com.mediamanager.repository.GenreRepository; +import com.mediamanager.repository.*; +import com.mediamanager.service.bitdepth.BitDepthService; import com.mediamanager.service.composer.ComposerService; -import com.mediamanager.repository.ArtistRepository; import com.mediamanager.repository.GenreRepository; import com.mediamanager.service.artist.ArtistService; import com.mediamanager.service.delegate.annotation.Action; @@ -58,14 +57,13 @@ public class DelegateActionManager { serviceLocator.register(ArtistService.class, artistService); - - - - ComposerRepository composerRepository = new ComposerRepository(entityManagerFactory); ComposerService composerService = new ComposerService(composerRepository); serviceLocator.register(ComposerService.class, composerService); + BitDepthRepository bitDepthRepository = new BitDepthRepository(entityManagerFactory); + BitDepthService bitDepthService = new BitDepthService(bitDepthRepository); + serviceLocator.register(BitDepthService.class, bitDepthService); serviceLocator.logRegisteredServices(); diff --git a/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/CreateBitDepthHandler.java b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/CreateBitDepthHandler.java new file mode 100644 index 0000000..726fa64 --- /dev/null +++ b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/CreateBitDepthHandler.java @@ -0,0 +1,51 @@ +package com.mediamanager.service.delegate.handler.bitdepth; + +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; +import com.mediamanager.mapper.BitDepthMapper; +import com.mediamanager.model.BitDepth; +import com.mediamanager.protocol.TransportProtocol; +import com.mediamanager.protocol.messages.ArtistMessages; +import com.mediamanager.protocol.messages.BitDepthMessages; +import com.mediamanager.service.bitdepth.BitDepthService; +import com.mediamanager.service.delegate.ActionHandler; +import com.mediamanager.service.delegate.annotation.Action; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +@Action("bitdepth.create") +public class CreateBitDepthHandler implements ActionHandler { + private static final Logger logger = LogManager.getLogger(CreateBitDepthHandler.class); + private final BitDepthService bitDepthService; + + public CreateBitDepthHandler(BitDepthService bitDepthService) { + this.bitDepthService = bitDepthService; + } + + @Override + public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException { + try{ + BitDepthMessages.CreateBitDepthRequest createRequest = + BitDepthMessages.CreateBitDepthRequest.parseFrom(requestPayload); + BitDepth bitDepth = bitDepthService.createBitDepth(createRequest.getValue()); + BitDepthMessages.BitDepth BitDepthProto = BitDepthMapper.toProtobuf(bitDepth); + BitDepthMessages.CreateBitDepthResponse createBitDepthResponse = BitDepthMessages.CreateBitDepthResponse.newBuilder() + .setBitdepth(BitDepthProto) + .build(); + return TransportProtocol.Response.newBuilder() + .setPayload(createBitDepthResponse.toByteString()); + } catch (IllegalArgumentException e) { + logger.error("Validation error", e); + return TransportProtocol.Response.newBuilder() + .setStatusCode(400) + .setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage())); + + } catch (Exception e) { + logger.error("Error creating artist", e); + return TransportProtocol.Response.newBuilder() + .setStatusCode(500) + .setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage())); + } + } +} + diff --git a/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/DeleteBitDepthHandler.java b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/DeleteBitDepthHandler.java new file mode 100644 index 0000000..b71a9a1 --- /dev/null +++ b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/DeleteBitDepthHandler.java @@ -0,0 +1,62 @@ +package com.mediamanager.service.delegate.handler.bitdepth; + +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; +import com.mediamanager.protocol.TransportProtocol; +import com.mediamanager.protocol.messages.BitDepthMessages; +import com.mediamanager.service.bitdepth.BitDepthService; +import com.mediamanager.service.delegate.ActionHandler; +import com.mediamanager.service.delegate.annotation.Action; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +@Action("bitdepth.delete") +public class DeleteBitDepthHandler implements ActionHandler { + private static final Logger logger = LogManager.getLogger(DeleteBitDepthHandler.class); + + private final BitDepthService bitDepthService; + + public DeleteBitDepthHandler(BitDepthService bitDepthService) { + this.bitDepthService = bitDepthService; + } + + @Override + public TransportProtocol.Response.Builder handle(ByteString requestPayload) + throws InvalidProtocolBufferException { + + try { + BitDepthMessages.DeleteBitDepthRequest deleteRequest = + BitDepthMessages.DeleteBitDepthRequest.parseFrom(requestPayload); + int id = deleteRequest.getId(); + boolean success = bitDepthService.deleteBitDepth(id); + BitDepthMessages.DeleteBitDepthResponse deleteResponse; + if (success) { + deleteResponse = BitDepthMessages.DeleteBitDepthResponse.newBuilder() + .setSuccess(true) + .setMessage("Bit-Depth deleted successfully") + .build(); + return TransportProtocol.Response.newBuilder() + .setPayload(deleteResponse.toByteString()); + } else { + deleteResponse = BitDepthMessages.DeleteBitDepthResponse.newBuilder() + .setSuccess(false) + .setMessage("Bit-Depth not found") + .build(); + + return TransportProtocol.Response.newBuilder() + .setStatusCode(404) + .setPayload(deleteResponse.toByteString()); + } + } catch (Exception e) { + logger.error("Error deleting bit-depth", e); + BitDepthMessages.DeleteBitDepthResponse deleteResponse = + BitDepthMessages.DeleteBitDepthResponse.newBuilder() + .setSuccess(false) + .setMessage("Error: " + e.getMessage()) + .build(); + return TransportProtocol.Response.newBuilder() + .setStatusCode(500) + .setPayload(deleteResponse.toByteString()); + } + } + } diff --git a/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/GetBitDepthByIdHandler.java b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/GetBitDepthByIdHandler.java new file mode 100644 index 0000000..96e630d --- /dev/null +++ b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/GetBitDepthByIdHandler.java @@ -0,0 +1,56 @@ +package com.mediamanager.service.delegate.handler.bitdepth; + +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; +import com.mediamanager.mapper.BitDepthMapper; +import com.mediamanager.model.BitDepth; +import com.mediamanager.protocol.TransportProtocol; +import com.mediamanager.protocol.messages.BitDepthMessages; +import com.mediamanager.service.bitdepth.BitDepthService; +import com.mediamanager.service.delegate.ActionHandler; +import com.mediamanager.service.delegate.annotation.Action; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Optional; + +@Action(value = "bitdepth.getById") +public class GetBitDepthByIdHandler implements ActionHandler { + private static final Logger logger = LogManager.getLogger(GetBitDepthByIdHandler.class); + private final BitDepthService bitDepthServicee; + + public GetBitDepthByIdHandler(BitDepthService bitDepthServicee) { + this.bitDepthServicee = bitDepthServicee; + } + + @Override + public TransportProtocol.Response.Builder handle(ByteString requestPayload) + throws InvalidProtocolBufferException{ + + try{ + BitDepthMessages.GetBitDepthByIdRequest getByIdRequest = + BitDepthMessages.GetBitDepthByIdRequest.parseFrom(requestPayload); + int id = getByIdRequest.getId(); + + Optional bitDepthOpt = bitDepthServicee.getBitDepthById(id); + + if (bitDepthOpt.isEmpty()){ + logger.warn("BitDepth not found with ID: {}", id); + return TransportProtocol.Response.newBuilder() + .setStatusCode(404) + .setPayload(ByteString.copyFromUtf8("BitDepth not found")); + } + BitDepthMessages.BitDepth bitDepthProto = BitDepthMapper.toProtobuf(bitDepthOpt.get()); + BitDepthMessages.GetBitDepthByIdResponse getByIdResponse = BitDepthMessages.GetBitDepthByIdResponse.newBuilder() + .setBitdepth(bitDepthProto) + .build(); + return TransportProtocol.Response.newBuilder() + .setPayload(getByIdResponse.toByteString()); + } catch (Exception e) { + logger.error("Error getting bit-depth by ID", e); + return TransportProtocol.Response.newBuilder() + .setStatusCode(500) + .setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage())); + } + } +} diff --git a/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/GetBitDepthHandler.java b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/GetBitDepthHandler.java new file mode 100644 index 0000000..71cf92f --- /dev/null +++ b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/GetBitDepthHandler.java @@ -0,0 +1,48 @@ +package com.mediamanager.service.delegate.handler.bitdepth; + +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; +import com.mediamanager.mapper.BitDepthMapper; +import com.mediamanager.model.BitDepth; +import com.mediamanager.protocol.TransportProtocol; +import com.mediamanager.protocol.messages.BitDepthMessages; +import com.mediamanager.service.bitdepth.BitDepthService; +import com.mediamanager.service.delegate.ActionHandler; +import com.mediamanager.service.delegate.annotation.Action; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; + + +@Action("bitdepth.getAll") +public class GetBitDepthHandler implements ActionHandler { + private static final Logger logger = LogManager.getLogger(GetBitDepthHandler.class); + + private final BitDepthService bitDepthService; + + public GetBitDepthHandler(BitDepthService bitDepthService){this.bitDepthService = bitDepthService;} + + @Override + public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException { + try{ + List bitDepths = bitDepthService.getAllBitDepths(); + BitDepthMessages.GetBitDepthsResponse.Builder responseBuilder = BitDepthMessages.GetBitDepthsResponse.newBuilder(); + + for (BitDepth bitDepth : bitDepths) { + BitDepthMessages.BitDepth bitDepthProto = BitDepthMapper.toProtobuf(bitDepth); + responseBuilder.addBitdepths(bitDepthProto); + } + BitDepthMessages.GetBitDepthsResponse getBitDepthsResponse = responseBuilder.build(); + + return TransportProtocol.Response.newBuilder() + .setPayload(getBitDepthsResponse.toByteString()); + + }catch (Exception e){ + logger.error("Error getting bit-depths", e); + return TransportProtocol.Response.newBuilder() + .setStatusCode(500) + .setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage())); + } + } +} diff --git a/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/UpdateBitDepthHandler.java b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/UpdateBitDepthHandler.java new file mode 100644 index 0000000..6150e64 --- /dev/null +++ b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/UpdateBitDepthHandler.java @@ -0,0 +1,65 @@ +package com.mediamanager.service.delegate.handler.bitdepth; + +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; +import com.mediamanager.mapper.BitDepthMapper; +import com.mediamanager.model.BitDepth; +import com.mediamanager.protocol.TransportProtocol; +import com.mediamanager.protocol.messages.BitDepthMessages; +import com.mediamanager.service.bitdepth.BitDepthService; +import com.mediamanager.service.delegate.ActionHandler; +import com.mediamanager.service.delegate.annotation.Action; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Optional; + +@Action("bitdepth.update") +public class UpdateBitDepthHandler implements ActionHandler { + private static final Logger logger = LogManager.getLogger(UpdateBitDepthHandler.class); + private final BitDepthService bitDepthService; + + public UpdateBitDepthHandler(BitDepthService bitDepthService) { + this.bitDepthService = bitDepthService; + } + + @Override + public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException { + try{ + BitDepthMessages.UpdateBitDepthRequest updateRequest = + BitDepthMessages.UpdateBitDepthRequest.parseFrom(requestPayload); + + int id = updateRequest.getId(); + String newValue = updateRequest.getValue(); + + Optional bitDepthOpt = bitDepthService.updateBitDepth(id, newValue); + + if(bitDepthOpt.isEmpty()){ + logger.warn("BitDepth not found with ID: {}", id); + return TransportProtocol.Response.newBuilder() + .setStatusCode(404) + .setPayload(ByteString.copyFromUtf8("Artist not found")); + } + + BitDepthMessages.BitDepth bitDepthProto = BitDepthMapper.toProtobuf(bitDepthOpt.get()); + + BitDepthMessages.UpdateBitDepthResponse updateResponse = BitDepthMessages.UpdateBitDepthResponse.newBuilder() + .setBitdepth(bitDepthProto) + .build(); + + return TransportProtocol.Response.newBuilder() + .setPayload(updateResponse.toByteString()); + + } catch (IllegalArgumentException e){ + logger.error("Validation error", e); + return TransportProtocol.Response.newBuilder() + .setStatusCode(400) + .setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage())); + } catch (Exception e) { + logger.error("Error updating bit-depth", e); + return TransportProtocol.Response.newBuilder() + .setStatusCode(500) + .setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage())); + } + } +} diff --git a/src/main/proto/bitdepth.proto b/src/main/proto/bitdepth.proto new file mode 100644 index 0000000..571dc9a --- /dev/null +++ b/src/main/proto/bitdepth.proto @@ -0,0 +1,53 @@ +syntax = "proto3"; + +option java_package = "com.mediamanager.protocol.messages"; +option java_outer_classname = "BitDepthMessages"; + +package mediamanager.messages; + +message BitDepth { + int32 id = 1; + string value = 2; +} + +message CreateBitDepthRequest { + string value = 1; +} + +message CreateBitDepthResponse { + BitDepth bitdepth = 1; +} + +message GetBitDepthsRequest { + +} + +message GetBitDepthsResponse { + repeated BitDepth bitdepths = 1; +} + +message GetBitDepthByIdRequest { + int32 id = 1; +} + +message GetBitDepthByIdResponse { + BitDepth bitdepth = 1; +} + +message UpdateBitDepthRequest { + int32 id = 1; + string value = 2; // Novo nome +} + +message UpdateBitDepthResponse { + BitDepth bitdepth = 1; +} + +message DeleteBitDepthRequest { + int32 id = 1; +} + +message DeleteBitDepthResponse { + bool success = 1; + string message = 2; +} From cd4b35f3c9ac370927eb33b188a42679b12c6b0f Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Miranda Date: Fri, 5 Dec 2025 04:54:29 -0300 Subject: [PATCH 2/3] Update src/main/java/com/mediamanager/service/delegate/handler/bitdepth/CreateBitDepthHandler.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../delegate/handler/bitdepth/CreateBitDepthHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/CreateBitDepthHandler.java b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/CreateBitDepthHandler.java index 726fa64..e055baf 100644 --- a/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/CreateBitDepthHandler.java +++ b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/CreateBitDepthHandler.java @@ -41,7 +41,8 @@ public class CreateBitDepthHandler implements ActionHandler { .setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage())); } catch (Exception e) { - logger.error("Error creating artist", e); + logger.error("Error creating bit-depth", e); + return TransportProtocol.Response.newBuilder() return TransportProtocol.Response.newBuilder() .setStatusCode(500) .setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage())); From 93c458d85698aafb0eb1befa8c34920f93462adb Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Miranda Date: Fri, 5 Dec 2025 04:54:40 -0300 Subject: [PATCH 3/3] Update src/main/java/com/mediamanager/service/delegate/handler/bitdepth/UpdateBitDepthHandler.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../delegate/handler/bitdepth/UpdateBitDepthHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/UpdateBitDepthHandler.java b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/UpdateBitDepthHandler.java index 6150e64..c786b12 100644 --- a/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/UpdateBitDepthHandler.java +++ b/src/main/java/com/mediamanager/service/delegate/handler/bitdepth/UpdateBitDepthHandler.java @@ -38,7 +38,7 @@ public class UpdateBitDepthHandler implements ActionHandler { logger.warn("BitDepth not found with ID: {}", id); return TransportProtocol.Response.newBuilder() .setStatusCode(404) - .setPayload(ByteString.copyFromUtf8("Artist not found")); + .setPayload(ByteString.copyFromUtf8("BitDepth not found")); } BitDepthMessages.BitDepth bitDepthProto = BitDepthMapper.toProtobuf(bitDepthOpt.get());