From 07291cb9f5cd2acae77499d5d0fbdd08600c2006 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Fri, 21 Aug 2026 16:46:37 +0200 Subject: [PATCH 1/5] feat(service): add crud service structure --- .../vulpes/backend/service/CrudService.java | 66 +++++++++ .../service/impl/AbstractCrudService.java | 125 ++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 src/main/java/net/onelitefeather/vulpes/backend/service/CrudService.java create mode 100644 src/main/java/net/onelitefeather/vulpes/backend/service/impl/AbstractCrudService.java diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/CrudService.java b/src/main/java/net/onelitefeather/vulpes/backend/service/CrudService.java new file mode 100644 index 0000000..b45b1cd --- /dev/null +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/CrudService.java @@ -0,0 +1,66 @@ +package net.onelitefeather.vulpes.backend.service; + +import io.micronaut.data.model.Page; +import io.micronaut.data.model.Pageable; + +import java.util.List; +import java.util.Optional; + +/** + * Generic CRUD service interface providing common persistence operations. + * + * @param the entity type + * @param the entity identifier type + * @param the request DTO type + * @param the response DTO interface type + * @param the concrete success response DTO type + */ +public interface CrudService { + + /** + * Creates a new entity from the given request DTO. + * + * @param dto the request DTO + * @return the created entity mapped to the success DTO + */ + SUCCESS create(REQ dto); + + /** + * Updates an existing entity with the data from the given request DTO. + * + * @param dto the request DTO + * @return the updated entity mapped to the success DTO, or an error DTO if not found + */ + RES update(REQ dto); + + /** + * Deletes an entity by its identifier. + * + * @param id the identifier of the entity to delete + * @return the deleted entity mapped to the success DTO, or an error DTO if not found + */ + RES delete(ID id); + + /** + * Deletes all entities. + * + * @return a list containing the result (or empty list) + */ + List deleteAll(); + + /** + * Retrieves all entities with pagination support. + * + * @param pageable pagination details + * @return a page of success DTOs + */ + Page getAll(Pageable pageable); + + /** + * Finds an entity by its identifier. + * + * @param id the identifier to look for + * @return an optional containing the entity if present + */ + Optional findById(ID id); +} diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AbstractCrudService.java b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AbstractCrudService.java new file mode 100644 index 0000000..c414f95 --- /dev/null +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AbstractCrudService.java @@ -0,0 +1,125 @@ +package net.onelitefeather.vulpes.backend.service.impl; + +import io.micronaut.data.model.Page; +import io.micronaut.data.model.Pageable; +import io.micronaut.data.repository.PageableRepository; +import net.onelitefeather.vulpes.backend.service.CrudService; + +import java.util.List; +import java.util.Optional; +import java.util.function.Function; + +/** + * Abstract generic implementation of the {@link CrudService} interface. + * + * @param the entity type + * @param the identifier type + * @param the request DTO type + * @param the response DTO interface type + * @param the concrete success response DTO type + */ +public abstract class AbstractCrudService + implements CrudService { + + protected final PageableRepository repository; + protected final Function toEntityMapper; + protected final Function toSuccessDtoMapper; + protected final Function toListSuccessDtoMapper; + protected final Function idExtractor; + protected final Function errorDtoFactory; + protected final String entityName; + + /** + * Constructs a new AbstractCrudService with identical mapping for single and list representations. + * + * @param repository the pageable repository + * @param toEntityMapper function to convert a request DTO to an entity + * @param toSuccessDtoMapper function to convert an entity to a success DTO + * @param idExtractor function to extract the ID from a request DTO + * @param errorDtoFactory function to create an error response DTO from an error message + * @param entityName the human-readable entity name for error messages + */ + protected AbstractCrudService( + PageableRepository repository, + Function toEntityMapper, + Function toSuccessDtoMapper, + Function idExtractor, + Function errorDtoFactory, + String entityName + ) { + this(repository, toEntityMapper, toSuccessDtoMapper, toSuccessDtoMapper, idExtractor, errorDtoFactory, entityName); + } + + /** + * Constructs a new AbstractCrudService with custom mapping for single and list representations. + * + * @param repository the pageable repository + * @param toEntityMapper function to convert a request DTO to an entity + * @param toSuccessDtoMapper function to convert an entity to a single success DTO + * @param toListSuccessDtoMapper function to convert an entity to a list success DTO + * @param idExtractor function to extract the ID from a request DTO + * @param errorDtoFactory function to create an error response DTO from an error message + * @param entityName the human-readable entity name for error messages + */ + protected AbstractCrudService( + PageableRepository repository, + Function toEntityMapper, + Function toSuccessDtoMapper, + Function toListSuccessDtoMapper, + Function idExtractor, + Function errorDtoFactory, + String entityName + ) { + this.repository = repository; + this.toEntityMapper = toEntityMapper; + this.toSuccessDtoMapper = toSuccessDtoMapper; + this.toListSuccessDtoMapper = toListSuccessDtoMapper; + this.idExtractor = idExtractor; + this.errorDtoFactory = errorDtoFactory; + this.entityName = entityName; + } + + @Override + public SUCCESS create(REQ dto) { + E entity = toEntityMapper.apply(dto); + E saved = repository.save(entity); + return toSuccessDtoMapper.apply(saved); + } + + @Override + public RES update(REQ dto) { + ID id = idExtractor.apply(dto); + if (id == null || repository.findById(id).isEmpty()) { + return errorDtoFactory.apply(entityName + " not found"); + } + E entity = toEntityMapper.apply(dto); + E updated = repository.update(entity); + return toSuccessDtoMapper.apply(updated); + } + + @Override + public RES delete(ID id) { + Optional existing = repository.findById(id); + if (existing.isPresent()) { + repository.deleteById(id); + return toSuccessDtoMapper.apply(existing.get()); + } + return errorDtoFactory.apply(entityName + " not found"); + } + + @Override + public List deleteAll() { + repository.deleteAll(); + return List.of(); + } + + @Override + public Page getAll(Pageable pageable) { + return repository.findAll(pageable).map(toListSuccessDtoMapper::apply); + } + + @Override + public Optional findById(ID id) { + return repository.findById(id); + } +} From df8d0d73bd43dd2a0efc9dc925df8ec0d9ce2a98 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Fri, 21 Aug 2026 16:46:57 +0200 Subject: [PATCH 2/5] chore(service): update service layer --- .../backend/service/AttributeService.java | 52 +---------- .../vulpes/backend/service/FontService.java | 67 +++------------ .../vulpes/backend/service/ItemService.java | 86 ++++++------------- .../backend/service/NotificationService.java | 53 +----------- .../vulpes/backend/service/SoundService.java | 55 +----------- .../service/impl/AttributeServiceImpl.java | 66 +++----------- .../backend/service/impl/FontServiceImpl.java | 71 ++++----------- .../backend/service/impl/ItemServiceImpl.java | 86 ++++++------------- .../service/impl/NotificationServiceImpl.java | 65 +++----------- .../service/impl/SoundServiceImpl.java | 75 ++++------------ 10 files changed, 124 insertions(+), 552 deletions(-) diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/AttributeService.java b/src/main/java/net/onelitefeather/vulpes/backend/service/AttributeService.java index 819f31c..a96e966 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/AttributeService.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/AttributeService.java @@ -1,63 +1,13 @@ package net.onelitefeather.vulpes.backend.service; -import io.micronaut.data.model.Page; -import io.micronaut.data.model.Pageable; import net.onelitefeather.vulpes.api.model.AttributeEntity; import net.onelitefeather.vulpes.backend.domain.attribute.AttributeModelDTO; import net.onelitefeather.vulpes.backend.domain.attribute.AttributeModelResponseDTO; -import java.util.List; -import java.util.Optional; import java.util.UUID; /** * Service interface for managing attributes. */ -public interface AttributeService { - - /** - * Creates a new attribute. - * - * @param attributeModelDTO the attribute data to create - * @return the created attribute response - */ - AttributeModelResponseDTO.AttributeModelDTO createAttribute(AttributeModelDTO attributeModelDTO); - - /** - * Updates an existing attribute. - * - * @param attributeModelDTO the attribute data to update - * @return the updated attribute response or an error response if the attribute doesn't exist - */ - AttributeModelResponseDTO updateAttribute(AttributeModelDTO attributeModelDTO); - - /** - * Deletes an attribute by its ID. - * - * @param id the ID of the attribute to delete - * @return the deleted attribute response or an error response if the attribute doesn't exist - */ - AttributeModelResponseDTO deleteAttribute(UUID id); - - /** - * Deletes all attributes. - * - * @return an empty list - */ - List deleteAllAttributes(); - - /** - * Gets all attributes. - * - * @return a list of all attributes - */ - Page getAllAttributes(Pageable pageable); - - /** - * Finds an attribute by its ID. - * - * @param id the ID of the attribute to find - * @return an optional containing the attribute if found, or empty if not found - */ - Optional findAttributeById(UUID id); +public interface AttributeService extends CrudService { } \ No newline at end of file diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/FontService.java b/src/main/java/net/onelitefeather/vulpes/backend/service/FontService.java index f3fe392..68042e1 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/FontService.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/FontService.java @@ -9,65 +9,17 @@ import net.onelitefeather.vulpes.backend.domain.font.FontStringResponseDTO; import java.util.List; -import java.util.Optional; import java.util.UUID; /** - * Service interface for managing fonts. + * Service interface for managing fonts and font characters. */ -public interface FontService { - - /** - * Creates a new font. - * - * @param fontModelDTO the font data to create - * @return the created font response - */ - FontModelResponseDTO.FontModelDTO createFont(FontModelDTO fontModelDTO); - - /** - * Updates an existing font. - * - * @param fontModelDTO the font data to update - * @return the updated font response or an error response if the font doesn't exist - */ - FontModelResponseDTO updateFont(FontModelDTO fontModelDTO); - - /** - * Deletes a font by its ID. - * - * @param id the ID of the font to delete - * @return the deleted font response or an error response if the font doesn't exist - */ - FontModelResponseDTO deleteFont(UUID id); - - /** - * Deletes all fonts. - * - * @return an empty list - */ - List deleteAllFonts(); - - /** - * Gets all fonts with pagination. - * - * @param pageable pagination information - * @return a page of fonts - */ - Page getAllFonts(Pageable pageable); - - /** - * Finds a font by its ID. - * - * @param id the ID of the font to find - * @return an optional containing the font if found, or empty if not found - */ - Optional findFontById(UUID id); +public interface FontService extends CrudService { /** * Gets the characters of a font by its ID. * - * @param id the ID of the font + * @param id the ID of the font * @param pageable pagination information * @return a list of characters */ @@ -75,15 +27,17 @@ public interface FontService { /** * Updates the character of a font by its ID. - * @param id the ID of the font + * + * @param id the ID of the font * @param charModel the new character to set * @return the updated character */ FontStringResponseDTO updateCharByFontId(UUID id, FontStringDTO charModel); /** - * Create the character of a font by its ID. - * @param id the ID of the font + * Creates the character of a font by its ID. + * + * @param id the ID of the font * @param charModel the new character to set * @return the updated character */ @@ -91,15 +45,16 @@ public interface FontService { /** * Deletes the character of a font by its ID. + * * @param fontId the ID of the font - * @param charId the id of the character to delete + * @param charId the ID of the character to delete * @return the deleted character */ FontStringResponseDTO deleteCharByFontId(UUID fontId, UUID charId); - /** * Deletes all characters of a font by its ID. + * * @param fontId the ID of the font * @return the list of deleted characters */ diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/ItemService.java b/src/main/java/net/onelitefeather/vulpes/backend/service/ItemService.java index d9713c7..ca27a3e 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/ItemService.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/ItemService.java @@ -13,65 +13,17 @@ import net.onelitefeather.vulpes.backend.domain.item.ItemModelResponseDTO; import java.util.List; -import java.util.Optional; import java.util.UUID; /** * Service interface for managing items. */ -public interface ItemService { - - /** - * Creates a new item. - * - * @param itemModelDTO the item data to create - * @return the created item response - */ - ItemModelResponseDTO.ItemModelDTO createItem(ItemModelDTO itemModelDTO); - - /** - * Updates an existing item. - * - * @param itemModelDTO the item data to update - * @return the updated item response or an error response if the item doesn't exist - */ - ItemModelResponseDTO updateItem(ItemModelDTO itemModelDTO); - - /** - * Deletes an item by its ID. - * - * @param id the ID of the item to delete - * @return the deleted item response or an error response if the item doesn't exist - */ - ItemModelResponseDTO deleteItem(UUID id); - - /** - * Deletes all items. - * - * @return an empty list - */ - List deleteAllItems(); - - /** - * Gets all items with pagination. - * - * @param pageable pagination information - * @return a page of items - */ - Page getAllItems(Pageable pageable); - - /** - * Finds an item by its ID. - * - * @param id the ID of the item to find - * @return an optional containing the item if found, or empty if not found - */ - Optional findItemById(UUID id); +public interface ItemService extends CrudService { /** * Gets the flags of an item by its ID. * - * @param id the ID of the item + * @param id the ID of the item * @param pageable pagination information * @return a list of flags */ @@ -79,7 +31,8 @@ public interface ItemService { /** * Creates the flag of an item by its ID. - * @param id the ID of the item to update the flag of + * + * @param id the ID of the item to update the flag of * @param itemFlagDTO the flag to create * @return the created flag */ @@ -87,7 +40,8 @@ public interface ItemService { /** * Delete the flag of an item by its ID. - * @param id the ID of the item to update the flag of + * + * @param id the ID of the item to update the flag of * @param flagId the flag to delete * @return the deleted flag */ @@ -95,6 +49,7 @@ public interface ItemService { /** * Delete the flags of an item by its ID. + * * @param id the ID of the item to update the flags of * @return the deleted flags */ @@ -102,7 +57,8 @@ public interface ItemService { /** * Updates the flag of an item by its ID. - * @param id the ID of the item to update the flag of + * + * @param id the ID of the item to update the flag of * @param flag the new flag to set * @return the updated flag */ @@ -111,7 +67,7 @@ public interface ItemService { /** * Gets the enchantments of an item by its ID. * - * @param id the ID of the item + * @param id the ID of the item * @param pageable pagination information * @return a map of enchantment names to levels */ @@ -119,7 +75,8 @@ public interface ItemService { /** * Updates the enchantments of an item by its ID. - * @param id the ID of the item to update the enchantments of + * + * @param id the ID of the item to update the enchantments of * @param enchantment the enchantments to update * @return the updated enchantments */ @@ -127,7 +84,8 @@ public interface ItemService { /** * Creates the enchantments of an item by its ID. - * @param id the ID of the item to update the enchantments of + * + * @param id the ID of the item to update the enchantments of * @param enchantment the enchantments to create * @return the created enchantment */ @@ -135,7 +93,8 @@ public interface ItemService { /** * Delete the enchantment of an item by its ID. - * @param id the ID of the item to update the enchantments of + * + * @param id the ID of the item to update the enchantments of * @param enchantment the enchantment to delete * @return the deleted enchantment */ @@ -143,6 +102,7 @@ public interface ItemService { /** * Delete the enchantments of an item by its ID. + * * @param id the ID of the item to update the enchantments of * @return the deleted enchantment */ @@ -151,7 +111,7 @@ public interface ItemService { /** * Gets the lore of an item by its ID. * - * @param id the ID of the item + * @param id the ID of the item * @param pageable pagination information * @return a list of lore lines */ @@ -159,7 +119,8 @@ public interface ItemService { /** * Updates the lore of an item by its ID. - * @param id the ID of the item to update the lore of + * + * @param id the ID of the item to update the lore of * @param loreDto the lore to update * @return the updated lore */ @@ -167,7 +128,8 @@ public interface ItemService { /** * Creates the lore of an item by its ID. - * @param id the ID of the item to update the lore of item + * + * @param id the ID of the item to update the lore of item * @param loreDto the lore to create * @return the created lore */ @@ -175,7 +137,8 @@ public interface ItemService { /** * Delete the enchantment of an item by its ID. - * @param id the ID of the item to update the enchantments of + * + * @param id the ID of the item to update the enchantments of * @param loreId the enchantment to delete * @return the deleted enchantment */ @@ -183,6 +146,7 @@ public interface ItemService { /** * Delete the lore of an item by its ID. + * * @param id the ID of the item to update the lore of * @return the deleted lore */ diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/NotificationService.java b/src/main/java/net/onelitefeather/vulpes/backend/service/NotificationService.java index 4b6bb5d..6b11c0d 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/NotificationService.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/NotificationService.java @@ -1,64 +1,13 @@ package net.onelitefeather.vulpes.backend.service; -import io.micronaut.data.model.Page; -import io.micronaut.data.model.Pageable; import net.onelitefeather.vulpes.api.model.NotificationEntity; import net.onelitefeather.vulpes.backend.domain.notification.NotificationModelDTO; import net.onelitefeather.vulpes.backend.domain.notification.NotificationModelResponseDTO; -import java.util.List; -import java.util.Optional; import java.util.UUID; /** * Service interface for managing notifications. */ -public interface NotificationService { - - /** - * Creates a new notification. - * - * @param notificationModelDTO the notification data to create - * @return the created notification response - */ - NotificationModelResponseDTO.NotificationModelDTO createNotification(NotificationModelDTO notificationModelDTO); - - /** - * Updates an existing notification. - * - * @param notificationModelDTO the notification data to update - * @return the updated notification response or an error response if the notification doesn't exist - */ - NotificationModelResponseDTO updateNotification(NotificationModelDTO notificationModelDTO); - - /** - * Deletes a notification by its ID. - * - * @param id the ID of the notification to delete - * @return the deleted notification response or an error response if the notification doesn't exist - */ - NotificationModelResponseDTO deleteNotification(UUID id); - - /** - * Deletes all notifications. - * - * @return an empty list - */ - List deleteAllNotifications(); - - /** - * Gets all notifications with pagination. - * - * @param pageable pagination information - * @return a page of notifications - */ - Page getAllNotifications(Pageable pageable); - - /** - * Finds a notification by its ID. - * - * @param id the ID of the notification to find - * @return an optional containing the notification if found, or empty if not found - */ - Optional findNotificationById(UUID id); +public interface NotificationService extends CrudService { } \ No newline at end of file diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/SoundService.java b/src/main/java/net/onelitefeather/vulpes/backend/service/SoundService.java index 6d1a1c8..f5294bd 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/SoundService.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/SoundService.java @@ -7,65 +7,18 @@ import net.onelitefeather.vulpes.backend.domain.sound.SoundFileSourceDTO; import net.onelitefeather.vulpes.backend.domain.sound.SoundResponseDTO; -import java.util.List; -import java.util.Optional; import java.util.UUID; /** - * Service interface for managing sound events. + * Service interface for managing sound events and sound sources. */ -public interface SoundService { - - /** - * Creates a new sound event. - * - * @param soundEventDTO the sound event data to create - * @return the created sound event response - */ - SoundResponseDTO createSoundEvent(SoundEventDTO soundEventDTO); - - /** - * Updates an existing sound event. - * - * @param soundEventDTO the sound event data to update - * @return the updated sound event response or an error response if the sound event doesn't exist - */ - SoundResponseDTO updateSoundEvent(SoundEventDTO soundEventDTO); - - /** - * Deletes a sound event by its ID. - * - * @param id the ID of the sound event to delete - * @return the deleted sound event response or an error response if the sound event doesn't exist - */ - SoundResponseDTO deleteSoundEvent(UUID id); - - /** - * Deletes all sound events. - * - * @return an empty list - */ - List deleteAllSoundEvents(); - - /** - * Gets all sound events. - * - * @return a list of all sound events - */ - Page getAllSoundEvents(Pageable pageable); - - /** - * Finds a sound event by its ID. - * - * @param id the ID of the sound event to find - * @return an optional containing the sound event if found, or empty if not found - */ - Optional findSoundEventById(UUID id); +public interface SoundService extends CrudService { /** * Gets all sound file sources by an ID. * - * @param id the ID of the sound event + * @param id the ID of the sound event + * @param pageable pagination details * @return the sound event response with sources */ Page getSoundSourcesById(UUID id, Pageable pageable); diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AttributeServiceImpl.java b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AttributeServiceImpl.java index 1c211c5..b282d87 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AttributeServiceImpl.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AttributeServiceImpl.java @@ -1,7 +1,5 @@ package net.onelitefeather.vulpes.backend.service.impl; -import io.micronaut.data.model.Page; -import io.micronaut.data.model.Pageable; import jakarta.inject.Inject; import jakarta.inject.Singleton; import net.onelitefeather.vulpes.api.model.AttributeEntity; @@ -10,65 +8,25 @@ import net.onelitefeather.vulpes.backend.domain.attribute.AttributeModelResponseDTO; import net.onelitefeather.vulpes.backend.service.AttributeService; -import java.util.List; -import java.util.Optional; import java.util.UUID; /** - * Implementation of the AttributeService interface. + * Implementation of the {@link AttributeService} interface. */ @Singleton -public class AttributeServiceImpl implements AttributeService { - - private final AttributeRepository attributeRepository; +public class AttributeServiceImpl + extends AbstractCrudService + implements AttributeService { @Inject public AttributeServiceImpl(AttributeRepository attributeRepository) { - this.attributeRepository = attributeRepository; - } - - @Override - public AttributeModelResponseDTO.AttributeModelDTO createAttribute(AttributeModelDTO attributeModelDTO) { - AttributeEntity attributeModel = attributeModelDTO.toAttributeModel(); - AttributeEntity savedAttributeModel = attributeRepository.save(attributeModel); - return AttributeModelResponseDTO.AttributeModelDTO.create(savedAttributeModel); - } - - @Override - public AttributeModelResponseDTO updateAttribute(AttributeModelDTO attributeModelDTO) { - Optional modelOptional = attributeRepository.findById(attributeModelDTO.id()); - if (modelOptional.isEmpty()) { - return new AttributeModelResponseDTO.AttributeModelErrorDTO("Attribute not found"); - } - AttributeEntity attributeModel = attributeModelDTO.toAttributeModel(); - attributeModel = attributeRepository.update(attributeModel); - return AttributeModelResponseDTO.AttributeModelDTO.create(attributeModel); - } - - @Override - public AttributeModelResponseDTO deleteAttribute(UUID id) { - Optional attributeModel = attributeRepository.findById(id); - if (attributeModel.isPresent()) { - attributeRepository.deleteById(id); - return AttributeModelResponseDTO.AttributeModelDTO.create(attributeModel.get()); - } - return new AttributeModelResponseDTO.AttributeModelErrorDTO("Attribute not found"); - } - - @Override - public List deleteAllAttributes() { - attributeRepository.deleteAll(); - return List.of(); - } - - @Override - public Page getAllAttributes(Pageable pageable) { - return attributeRepository.findAll(pageable) - .map(AttributeModelResponseDTO.AttributeModelDTO::create); - } - - @Override - public Optional findAttributeById(UUID id) { - return attributeRepository.findById(id); + super( + attributeRepository, + AttributeModelDTO::toAttributeModel, + AttributeModelResponseDTO.AttributeModelDTO::create, + AttributeModelDTO::id, + AttributeModelResponseDTO.AttributeModelErrorDTO::new, + "Attribute" + ); } } \ No newline at end of file diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/FontServiceImpl.java b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/FontServiceImpl.java index 7f914c4..1d50fe0 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/FontServiceImpl.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/FontServiceImpl.java @@ -15,69 +15,32 @@ import net.onelitefeather.vulpes.backend.service.FontService; import java.util.List; -import java.util.Optional; import java.util.UUID; /** - * Implementation of the FontService interface. + * Implementation of the {@link FontService} interface. */ @Singleton -public class FontServiceImpl implements FontService { +public class FontServiceImpl + extends AbstractCrudService + implements FontService { - private final FontRepository fontRepository; private final FontStringRepository fontStringRepository; @Inject public FontServiceImpl(FontRepository fontRepository, FontStringRepository fontStringRepository) { - this.fontRepository = fontRepository; + super( + fontRepository, + FontModelDTO::toFontModel, + FontModelResponseDTO.FontModelDTO::createDTOWithChars, + FontModelResponseDTO.FontModelDTO::createDTO, + FontModelDTO::id, + FontModelResponseDTO.FontModelErrorDTO::new, + "Font" + ); this.fontStringRepository = fontStringRepository; } - @Override - public FontModelResponseDTO.FontModelDTO createFont(FontModelDTO fontModelDTO) { - FontEntity fontModel = fontModelDTO.toFontModel(); - FontEntity savedFontModel = fontRepository.save(fontModel); - return FontModelResponseDTO.FontModelDTO.createDTOWithChars(savedFontModel); - } - - @Override - public FontModelResponseDTO updateFont(FontModelDTO fontModelDTO) { - Optional modelOptional = fontRepository.findById(fontModelDTO.id()); - if (modelOptional.isEmpty()) { - return new FontModelResponseDTO.FontModelErrorDTO("Font not found"); - } - FontEntity fontModel = fontModelDTO.toFontModel(); - var updatedFontModel = fontRepository.update(fontModel); - return FontModelResponseDTO.FontModelDTO.createDTOWithChars(updatedFontModel); - } - - @Override - public FontModelResponseDTO deleteFont(UUID id) { - Optional model = fontRepository.findById(id); - if (model.isPresent()) { - fontRepository.deleteById(id); - FontEntity fontModel = model.get(); - return FontModelResponseDTO.FontModelDTO.createDTO(fontModel); - } - return new FontModelResponseDTO.FontModelErrorDTO("Font not found"); - } - - @Override - public List deleteAllFonts() { - fontRepository.deleteAll(); - return List.of(); - } - - @Override - public Page getAllFonts(Pageable pageable) { - return fontRepository.findAll(pageable).map(FontModelResponseDTO.FontModelDTO::createDTO); - } - - @Override - public Optional findFontById(UUID id) { - return fontRepository.findById(id); - } - @Override public Page findCharsByFontId(UUID id, Pageable pageable) { return this.fontStringRepository.findCharsByFontId(id, pageable).map(FontStringResponseDTO.FontStringDTO::createDTO); @@ -86,7 +49,7 @@ public Page findCharsByFontId(UUID id, Pageable pageable) @Transactional @Override public FontStringResponseDTO updateCharByFontId(UUID id, FontStringDTO charModel) { - var byId = this.fontRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new FontStringResponseDTO.FontStringErrorDTO("Font not found"); } @@ -100,7 +63,7 @@ public FontStringResponseDTO updateCharByFontId(UUID id, FontStringDTO charModel @Transactional @Override public FontStringResponseDTO createCharByFontId(UUID id, FontStringDTO charModel) { - var byId = this.fontRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new FontStringResponseDTO.FontStringErrorDTO("Font not found"); } @@ -113,7 +76,7 @@ public FontStringResponseDTO createCharByFontId(UUID id, FontStringDTO charModel @Override public FontStringResponseDTO deleteCharByFontId(UUID fontId, UUID charId) { - var byId = this.fontRepository.findById(fontId); + var byId = this.repository.findById(fontId); if (byId.isEmpty()) { return new FontStringResponseDTO.FontStringErrorDTO("Font not found"); } @@ -132,7 +95,7 @@ public FontStringResponseDTO deleteCharByFontId(UUID fontId, UUID charId) { @Override public List deleteAllCharByFontId(UUID fontId) { - var byId = this.fontRepository.findById(fontId); + var byId = this.repository.findById(fontId); if (byId.isEmpty()) { return List.of(); } diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/ItemServiceImpl.java b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/ItemServiceImpl.java index 9740b0d..fb6e5a6 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/ItemServiceImpl.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/ItemServiceImpl.java @@ -6,7 +6,6 @@ import jakarta.inject.Singleton; import net.onelitefeather.vulpes.api.model.ItemEntity; import net.onelitefeather.vulpes.api.model.item.ItemEnchantmentEntity; -import net.onelitefeather.vulpes.api.model.item.ItemLoreEntity; import net.onelitefeather.vulpes.api.repository.ItemRepository; import net.onelitefeather.vulpes.api.repository.item.ItemEnchantmentRepository; import net.onelitefeather.vulpes.api.repository.item.ItemFlagRepository; @@ -22,17 +21,17 @@ import net.onelitefeather.vulpes.backend.service.ItemService; import java.util.List; -import java.util.Optional; import java.util.UUID; /** - * Implementation of the ItemService interface. + * Implementation of the {@link ItemService} interface. */ @Singleton -public class ItemServiceImpl implements ItemService { +public class ItemServiceImpl + extends AbstractCrudService + implements ItemService { private static final String GENERIC_ERROR = "Item not found"; - private final ItemRepository itemRepository; private final ItemEnchantmentRepository itemEnchantmentRepository; private final ItemLoreRepository itemLoreRepository; private final ItemFlagRepository itemFlagRepository; @@ -42,56 +41,19 @@ public ItemServiceImpl(ItemRepository itemRepository, ItemEnchantmentRepository itemEnchantmentRepository, ItemLoreRepository itemLoreRepository, ItemFlagRepository itemFlagRepository) { - this.itemRepository = itemRepository; + super( + itemRepository, + ItemModelDTO::toItemEntity, + ItemModelResponseDTO.ItemModelDTO::createDTO, + ItemModelDTO::id, + ItemModelResponseDTO.ItemModelErrorDTO::new, + "Item" + ); this.itemEnchantmentRepository = itemEnchantmentRepository; this.itemLoreRepository = itemLoreRepository; this.itemFlagRepository = itemFlagRepository; } - @Override - public ItemModelResponseDTO.ItemModelDTO createItem(ItemModelDTO itemModelDTO) { - ItemEntity itemModel = itemModelDTO.toItemEntity(); - ItemEntity savedItemModel = itemRepository.save(itemModel); - return ItemModelResponseDTO.ItemModelDTO.createDTO(savedItemModel); - } - - @Override - public ItemModelResponseDTO updateItem(ItemModelDTO itemModelDTO) { - Optional existingItem = itemRepository.findById(itemModelDTO.id()); - if (existingItem.isEmpty()) { - return new ItemModelResponseDTO.ItemModelErrorDTO("Item not found"); - } - ItemEntity itemModel = itemModelDTO.toItemEntity(); - ItemEntity updatedItemModel = itemRepository.update(itemModel); - return ItemModelResponseDTO.ItemModelDTO.createDTO(updatedItemModel); - } - - @Override - public ItemModelResponseDTO deleteItem(UUID id) { - Optional model = itemRepository.findById(id); - if (model.isPresent()) { - itemRepository.deleteById(id); - return ItemModelResponseDTO.ItemModelDTO.createDTO(model.get()); - } - return new ItemModelResponseDTO.ItemModelErrorDTO("Item not found"); - } - - @Override - public List deleteAllItems() { - itemRepository.deleteAll(); - return List.of(); - } - - @Override - public Page getAllItems(Pageable pageable) { - return itemRepository.findAll(pageable).map(ItemModelResponseDTO.ItemModelDTO::createDTO); - } - - @Override - public Optional findItemById(UUID id) { - return itemRepository.findById(id); - } - @Override public Page findEnchantmentsById(UUID id, Pageable pageable) { return this.itemEnchantmentRepository.findEnchantmentsById(id, pageable).map(ItemEnchantmentResponseDTO.ItemEnchantmentDTO::createDTO); @@ -104,7 +66,7 @@ public Page findFlagsById(UUID id, Pageable pageable) { @Override public ItemFlagResponseDTO createFlagById(UUID id, ItemFlagDTO itemFlagDTO) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new ItemFlagResponseDTO.ItemFlagErrorDTO(GENERIC_ERROR); } @@ -117,7 +79,7 @@ public ItemFlagResponseDTO createFlagById(UUID id, ItemFlagDTO itemFlagDTO) { @Override public ItemFlagResponseDTO deleteFlagById(UUID id, UUID flagId) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new ItemFlagResponseDTO.ItemFlagErrorDTO(GENERIC_ERROR); } @@ -136,7 +98,7 @@ public ItemFlagResponseDTO deleteFlagById(UUID id, UUID flagId) { @Override public List deleteAllFlagsById(UUID id) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return List.of(); } @@ -155,7 +117,7 @@ public Page findLoreById(UUID id, Pageable pageable) { @Override public ItemLoreResponseDTO updateLoreById(UUID id, ItemLoreDTO lore) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new ItemLoreResponseDTO.ItemLoreErrorDTO(GENERIC_ERROR); } @@ -168,7 +130,7 @@ public ItemLoreResponseDTO updateLoreById(UUID id, ItemLoreDTO lore) { @Override public ItemLoreResponseDTO createLoreById(UUID id, ItemLoreDTO loreDto) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new ItemLoreResponseDTO.ItemLoreErrorDTO(GENERIC_ERROR); } @@ -181,7 +143,7 @@ public ItemLoreResponseDTO createLoreById(UUID id, ItemLoreDTO loreDto) { @Override public ItemLoreResponseDTO deleteLoreById(UUID id, UUID loreId) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new ItemLoreResponseDTO.ItemLoreErrorDTO(GENERIC_ERROR); } @@ -200,7 +162,7 @@ public ItemLoreResponseDTO deleteLoreById(UUID id, UUID loreId) { @Override public List deleteAllLoreById(UUID id) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return List.of(); } @@ -214,7 +176,7 @@ public List deleteAllLoreById(UUID id) { @Override public ItemEnchantmentResponseDTO updateEnchantmentById(UUID id, ItemEnchantmentDTO enchantment) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new ItemEnchantmentResponseDTO.ItemEnchantmentErrorDTO(GENERIC_ERROR); } @@ -227,7 +189,7 @@ public ItemEnchantmentResponseDTO updateEnchantmentById(UUID id, ItemEnchantment @Override public ItemEnchantmentResponseDTO createEnchantmentById(UUID id, ItemEnchantmentDTO enchantment) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new ItemEnchantmentResponseDTO.ItemEnchantmentErrorDTO(GENERIC_ERROR); } @@ -240,7 +202,7 @@ public ItemEnchantmentResponseDTO createEnchantmentById(UUID id, ItemEnchantment @Override public ItemEnchantmentResponseDTO deleteEnchantmentById(UUID id, UUID enchantment) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new ItemEnchantmentResponseDTO.ItemEnchantmentErrorDTO(GENERIC_ERROR); } @@ -259,7 +221,7 @@ public ItemEnchantmentResponseDTO deleteEnchantmentById(UUID id, UUID enchantmen @Override public List deleteAllEnchantmentsById(UUID id) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return List.of(); } @@ -273,7 +235,7 @@ public List deleteAllEnchantmentsById(UUID id) { @Override public ItemFlagResponseDTO updateFlagById(UUID id, ItemFlagDTO flag) { - var byId = this.itemRepository.findById(id); + var byId = this.repository.findById(id); if (byId.isEmpty()) { return new ItemFlagResponseDTO.ItemFlagErrorDTO(GENERIC_ERROR); } diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/NotificationServiceImpl.java b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/NotificationServiceImpl.java index 5bfd2d8..83293e2 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/NotificationServiceImpl.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/NotificationServiceImpl.java @@ -1,7 +1,5 @@ package net.onelitefeather.vulpes.backend.service.impl; -import io.micronaut.data.model.Page; -import io.micronaut.data.model.Pageable; import jakarta.inject.Inject; import jakarta.inject.Singleton; import net.onelitefeather.vulpes.api.model.NotificationEntity; @@ -10,64 +8,25 @@ import net.onelitefeather.vulpes.backend.domain.notification.NotificationModelResponseDTO; import net.onelitefeather.vulpes.backend.service.NotificationService; -import java.util.List; -import java.util.Optional; import java.util.UUID; /** - * Implementation of the NotificationService interface. + * Implementation of the {@link NotificationService} interface. */ @Singleton -public class NotificationServiceImpl implements NotificationService { - - private final NotificationRepository notificationRepository; +public class NotificationServiceImpl + extends AbstractCrudService + implements NotificationService { @Inject public NotificationServiceImpl(NotificationRepository notificationRepository) { - this.notificationRepository = notificationRepository; - } - - @Override - public NotificationModelResponseDTO.NotificationModelDTO createNotification(NotificationModelDTO notificationModelDTO) { - NotificationEntity notificationModel = notificationModelDTO.toNotificationModel(); - NotificationEntity savedNotificationModel = notificationRepository.save(notificationModel); - return NotificationModelResponseDTO.NotificationModelDTO.createDTO(savedNotificationModel); - } - - @Override - public NotificationModelResponseDTO updateNotification(NotificationModelDTO notificationModelDTO) { - Optional existingModel = notificationRepository.findById(notificationModelDTO.id()); - if (existingModel.isEmpty()) { - return new NotificationModelResponseDTO.NotificationModelErrorDTO("Notification not found"); - } - NotificationEntity notificationModel = notificationModelDTO.toNotificationModel(); - notificationModel = notificationRepository.update(notificationModel); - return NotificationModelResponseDTO.NotificationModelDTO.createDTO(notificationModel); - } - - @Override - public NotificationModelResponseDTO deleteNotification(UUID id) { - Optional model = notificationRepository.findById(id); - if (model.isPresent()) { - notificationRepository.deleteById(id); - return NotificationModelResponseDTO.NotificationModelDTO.createDTO(model.get()); - } - return new NotificationModelResponseDTO.NotificationModelErrorDTO("Notification not found"); - } - - @Override - public List deleteAllNotifications() { - notificationRepository.deleteAll(); - return List.of(); - } - - @Override - public Page getAllNotifications(Pageable pageable) { - return notificationRepository.findAll(pageable).map(NotificationModelResponseDTO.NotificationModelDTO::createDTO); - } - - @Override - public Optional findNotificationById(UUID id) { - return notificationRepository.findById(id); + super( + notificationRepository, + NotificationModelDTO::toNotificationModel, + NotificationModelResponseDTO.NotificationModelDTO::createDTO, + NotificationModelDTO::id, + NotificationModelResponseDTO.NotificationModelErrorDTO::new, + "Notification" + ); } } \ No newline at end of file diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/SoundServiceImpl.java b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/SoundServiceImpl.java index 1882203..9bb73e1 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/SoundServiceImpl.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/SoundServiceImpl.java @@ -13,80 +13,39 @@ import net.onelitefeather.vulpes.backend.domain.sound.SoundResponseDTO; import net.onelitefeather.vulpes.backend.service.SoundService; -import java.util.List; import java.util.Optional; import java.util.UUID; /** - * Implementation of the SoundService interface. + * Implementation of the {@link SoundService} interface. */ @Singleton -public class SoundServiceImpl implements SoundService { +public class SoundServiceImpl + extends AbstractCrudService + implements SoundService { private static final String GENERIC_ERROR = "Sound event not found"; - private final SoundRepository soundRepository; private final SoundFileSourceRepository soundFileSourceRepository; /** - * Constructs a new SoundServiceImpl with the specified SoundRepository. + * Constructs a new SoundServiceImpl with the specified SoundRepository and SoundFileSourceRepository. * - * @param soundRepository the repository to manage sound events + * @param soundRepository the repository to manage sound events * @param soundFileSourceRepository the repository to manage sound file sources */ @Inject public SoundServiceImpl(SoundRepository soundRepository, SoundFileSourceRepository soundFileSourceRepository) { - this.soundRepository = soundRepository; + super( + soundRepository, + SoundEventDTO::toEntity, + SoundResponseDTO.SoundModelDTO::createDTO, + SoundEventDTO::id, + SoundResponseDTO.SoundErrorDTO::new, + "Sound event" + ); this.soundFileSourceRepository = soundFileSourceRepository; } - @Override - public SoundResponseDTO createSoundEvent(SoundEventDTO soundEventDTO) { - SoundEventEntity event = soundEventDTO.toEntity(); - if (event.getId() != null) { - return new SoundResponseDTO.SoundErrorDTO("New sound event cannot have an id"); - } else { - event = soundRepository.save(event); - } - return SoundResponseDTO.SoundModelDTO.createDTO(event); - } - - @Override - public SoundResponseDTO updateSoundEvent(SoundEventDTO soundEventDTO) { - Optional existingModel = soundRepository.findById(soundEventDTO.id()); - if (existingModel.isEmpty()) { - return new SoundResponseDTO.SoundErrorDTO(GENERIC_ERROR); - } - SoundEventEntity soundModel = soundEventDTO.toEntity(); - soundModel = soundRepository.update(soundModel); - return SoundResponseDTO.SoundModelDTO.createDTO(soundModel); - } - - @Override - public SoundResponseDTO deleteSoundEvent(UUID id) { - Optional model = soundRepository.findById(id); - if (model.isPresent()) { - soundRepository.deleteById(id); - return SoundResponseDTO.SoundModelDTO.createDTO(model.get()); - } - return new SoundResponseDTO.SoundErrorDTO(GENERIC_ERROR); - } - - @Override - public List deleteAllSoundEvents() { - soundRepository.deleteAll(); - return List.of(); - } - - @Override - public Page getAllSoundEvents(Pageable pageable) { - return soundRepository.findAll(pageable).map(SoundResponseDTO.SoundModelDTO::createDTO); - } - - @Override - public Optional findSoundEventById(UUID id) { - return soundRepository.findById(id); - } - @Override public Page getSoundSourcesById(UUID id, Pageable pageable) { return this.soundFileSourceRepository.findSoundFileSourcesBySoundEvent(id, pageable).map(SoundResponseDTO.SoundFileSourceDTO::createDTO); @@ -98,7 +57,7 @@ public SoundResponseDTO.SoundFileSourceDTO createAndLinkSource(UUID soundEventId if (soundEventId == null || sourceDTO == null) { throw new IllegalArgumentException("SoundEventId and SourceDTO must not be null"); } - Optional soundEventOpt = soundRepository.findById(soundEventId); + Optional soundEventOpt = this.repository.findById(soundEventId); if (soundEventOpt.isEmpty()) { throw new IllegalArgumentException(GENERIC_ERROR); } @@ -114,7 +73,7 @@ public SoundResponseDTO.SoundFileSourceDTO updateLinkedSource(UUID soundEventId, if (soundEventId == null || sourceDTO == null || sourceDTO.id() == null) { throw new IllegalArgumentException("SoundEventId and SourceDTO and SourceDTO.Id must not be null"); } - Optional soundEventOpt = soundRepository.findById(soundEventId); + Optional soundEventOpt = this.repository.findById(soundEventId); if (soundEventOpt.isEmpty()) { throw new IllegalArgumentException(GENERIC_ERROR); } @@ -141,7 +100,7 @@ public SoundResponseDTO.SoundFileSourceDTO deleteLinkedSource(UUID soundEventId, throw new IllegalArgumentException("SoundEventId and SourceDTO and SourceDTO.Id must not be null"); } - Optional soundEventOpt = soundRepository.findById(soundEventId); + Optional soundEventOpt = this.repository.findById(soundEventId); if (soundEventOpt.isEmpty()) { throw new IllegalArgumentException(GENERIC_ERROR); } From f421a91e57f23058aa9523ab0aef941efecad297 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Fri, 21 Aug 2026 16:47:20 +0200 Subject: [PATCH 3/5] chore(controller): update method calls --- .../backend/controller/AttributeController.java | 10 +++++----- .../backend/controller/NotificationController.java | 12 ++++++------ .../backend/controller/font/FontController.java | 10 +++++----- .../backend/controller/item/ItemController.java | 12 ++++++------ .../backend/controller/sound/SoundController.java | 12 ++++++------ 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/net/onelitefeather/vulpes/backend/controller/AttributeController.java b/src/main/java/net/onelitefeather/vulpes/backend/controller/AttributeController.java index d997877..98fc28f 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/controller/AttributeController.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/controller/AttributeController.java @@ -61,7 +61,7 @@ public AttributeController(AttributeService attributeService) { @Post @Validated(groups = ValidationGroup.Create.class) public HttpResponse add(@Body AttributeModelDTO model) { - AttributeModelResponseDTO.AttributeModelDTO createdAttribute = attributeService.createAttribute(model); + AttributeModelResponseDTO.AttributeModelDTO createdAttribute = attributeService.create(model); return HttpResponse.ok(createdAttribute); } @@ -90,7 +90,7 @@ public HttpResponse add(@Body AttributeModelDTO model @Post("/update") @Validated(groups = ValidationGroup.Update.class) public HttpResponse update(@Body AttributeModelDTO model) { - AttributeModelResponseDTO result = attributeService.updateAttribute(model); + AttributeModelResponseDTO result = attributeService.update(model); if (result instanceof AttributeModelResponseDTO.AttributeModelErrorDTO) { return HttpResponse.notFound(result); } @@ -121,7 +121,7 @@ public HttpResponse update(@Body AttributeModelDTO mo ) @Delete("/delete/{id}") public HttpResponse delete(@PathVariable UUID id) { - AttributeModelResponseDTO result = attributeService.deleteAttribute(id); + AttributeModelResponseDTO result = attributeService.delete(id); if (result instanceof AttributeModelResponseDTO.AttributeModelErrorDTO) { return HttpResponse.notFound(result); } @@ -149,7 +149,7 @@ public HttpResponse delete(@PathVariable UUID id) { ) @Delete("/delete") public HttpResponse> deleteAll() { - List result = attributeService.deleteAllAttributes(); + List result = attributeService.deleteAll(); return HttpResponse.ok(result); } @@ -178,7 +178,7 @@ public HttpResponse> deleteAll() { @Produces(MediaType.APPLICATION_JSON) @Get(uris = {"/"}) public HttpResponse> getAll(Pageable pageable) { - Page models = attributeService.getAllAttributes(pageable); + Page models = attributeService.getAll(pageable); return HttpResponse.ok(models); } } diff --git a/src/main/java/net/onelitefeather/vulpes/backend/controller/NotificationController.java b/src/main/java/net/onelitefeather/vulpes/backend/controller/NotificationController.java index 48c3def..a509475 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/controller/NotificationController.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/controller/NotificationController.java @@ -74,7 +74,7 @@ public NotificationController(NotificationService notificationService) { public HttpResponse add( @Body NotificationModelDTO model ) { - NotificationModelResponseDTO.NotificationModelDTO result = notificationService.createNotification(model); + NotificationModelResponseDTO.NotificationModelDTO result = notificationService.create(model); return HttpResponse.ok(result); } @@ -109,7 +109,7 @@ public HttpResponse add( @Get("/{id}") @Produces(MediaType.APPLICATION_JSON) public HttpResponse getById(@PathVariable UUID id) { - Optional model = notificationService.findNotificationById(id); + Optional model = notificationService.findById(id); if (model.isPresent()) { return HttpResponse.ok(NotificationModelResponseDTO.NotificationModelDTO.createDTO(model.get())); } @@ -147,7 +147,7 @@ public HttpResponse getById(@PathVariable UUID id) @Delete("/delete/{id}") @Produces(MediaType.APPLICATION_JSON) public HttpResponse remove(@PathVariable UUID id) { - NotificationModelResponseDTO result = notificationService.deleteNotification(id); + NotificationModelResponseDTO result = notificationService.delete(id); if (result instanceof NotificationModelResponseDTO.NotificationModelErrorDTO) { return HttpResponse.notFound(result); } @@ -187,7 +187,7 @@ public HttpResponse remove(@PathVariable UUID id) @Get(uris = {"/"}) @Produces(MediaType.APPLICATION_JSON) public HttpResponse> getAll(Pageable pageable) { - Page list = notificationService.getAllNotifications(pageable); + Page list = notificationService.getAll(pageable); return HttpResponse.ok(list); } @@ -213,7 +213,7 @@ public HttpResponse> get @Delete("/delete/") @Produces(MediaType.APPLICATION_JSON) public HttpResponse> deleteAll() { - List result = notificationService.deleteAllNotifications(); + List result = notificationService.deleteAll(); return HttpResponse.ok(result); } @@ -249,7 +249,7 @@ public HttpResponse> deleteAll() { @Produces(MediaType.APPLICATION_JSON) @Validated(groups = ValidationGroup.Update.class) public HttpResponse update(@Body NotificationModelDTO model) { - NotificationModelResponseDTO result = notificationService.updateNotification(model); + NotificationModelResponseDTO result = notificationService.update(model); if (result instanceof NotificationModelResponseDTO.NotificationModelErrorDTO) { return HttpResponse.notFound(result); } diff --git a/src/main/java/net/onelitefeather/vulpes/backend/controller/font/FontController.java b/src/main/java/net/onelitefeather/vulpes/backend/controller/font/FontController.java index eb335d9..9f756cd 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/controller/font/FontController.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/controller/font/FontController.java @@ -68,7 +68,7 @@ public FontController(FontService fontService) { public HttpResponse add( @Body FontModelDTO item ) { - FontModelResponseDTO.FontModelDTO result = fontService.createFont(item); + FontModelResponseDTO.FontModelDTO result = fontService.create(item); return HttpResponse.ok(result); } @@ -97,7 +97,7 @@ public HttpResponse add( @Get("/{id}") @Produces(MediaType.APPLICATION_JSON) public HttpResponse getById(@PathVariable UUID id) { - Optional model = fontService.findFontById(id); + Optional model = fontService.findById(id); if (model.isPresent()) { FontEntity fontModel = model.get(); FontModelResponseDTO.FontModelDTO dto = FontModelResponseDTO.FontModelDTO.createDTO(fontModel); @@ -131,7 +131,7 @@ public HttpResponse getById(@PathVariable UUID id) { @Delete("/delete/{id}") @Produces(MediaType.APPLICATION_JSON) public HttpResponse remove(@PathVariable UUID id) { - FontModelResponseDTO result = fontService.deleteFont(id); + FontModelResponseDTO result = fontService.delete(id); if (result instanceof FontModelResponseDTO.FontModelErrorDTO) { return HttpResponse.notFound(result); } @@ -158,7 +158,7 @@ public HttpResponse remove(@PathVariable UUID id) { @Get(uris = {"/"}) @Produces(MediaType.APPLICATION_JSON) public HttpResponse> getAll(Pageable pageable) { - Page models = fontService.getAllFonts(pageable); + Page models = fontService.getAll(pageable); return HttpResponse.ok(models); } @@ -179,7 +179,7 @@ public HttpResponse> getAll(Pageable pag @Delete("delete") @Produces(MediaType.APPLICATION_JSON) public HttpResponse> deleteAll() { - List result = fontService.deleteAllFonts(); + List result = fontService.deleteAll(); return HttpResponse.ok(result); } } diff --git a/src/main/java/net/onelitefeather/vulpes/backend/controller/item/ItemController.java b/src/main/java/net/onelitefeather/vulpes/backend/controller/item/ItemController.java index 2b7932f..6ea3a35 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/controller/item/ItemController.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/controller/item/ItemController.java @@ -70,7 +70,7 @@ public ItemController(ItemService itemService) { public HttpResponse add( @Body ItemModelDTO itemModel ) { - ItemModelResponseDTO.ItemModelDTO createdItem = itemService.createItem(itemModel); + ItemModelResponseDTO.ItemModelDTO createdItem = itemService.create(itemModel); return HttpResponse.ok(createdItem); } @@ -101,7 +101,7 @@ public HttpResponse add( public HttpResponse getById( @PathVariable("itemId") UUID itemId ) { - Optional foundItemOpt = itemService.findItemById(itemId); + Optional foundItemOpt = itemService.findById(itemId); if (foundItemOpt.isPresent()) { var foundItem = foundItemOpt.get(); return HttpResponse.ok(ItemModelResponseDTO.ItemModelDTO.createDTO(foundItem)); @@ -129,7 +129,7 @@ public HttpResponse getById( @Get @Produces(MediaType.APPLICATION_JSON) public HttpResponse> getAll(Pageable pageable) { - Page itemsPage = itemService.getAllItems(pageable); + Page itemsPage = itemService.getAll(pageable); return HttpResponse.ok(itemsPage); } @@ -161,7 +161,7 @@ public HttpResponse> getAll(Pageable pag public HttpResponse update( @Body ItemModelDTO itemModel ) { - ItemModelResponseDTO updateResult = itemService.updateItem(itemModel); + ItemModelResponseDTO updateResult = itemService.update(itemModel); if (updateResult instanceof ItemModelResponseDTO.ItemModelErrorDTO) { return HttpResponse.notFound(updateResult); } @@ -193,7 +193,7 @@ public HttpResponse update( @Delete("/delete/{itemId}") @Produces(MediaType.APPLICATION_JSON) public HttpResponse delete(@PathVariable("itemId") UUID itemId) { - ItemModelResponseDTO deleteResult = itemService.deleteItem(itemId); + ItemModelResponseDTO deleteResult = itemService.delete(itemId); if (deleteResult instanceof ItemModelResponseDTO.ItemModelErrorDTO) { return HttpResponse.notFound(deleteResult); } @@ -218,7 +218,7 @@ public HttpResponse delete(@PathVariable("itemId") UUID it @Delete("/deleteAll") @Produces(MediaType.APPLICATION_JSON) public HttpResponse> deleteAll() { - List deleteResults = itemService.deleteAllItems(); + List deleteResults = itemService.deleteAll(); return HttpResponse.ok(deleteResults); } } diff --git a/src/main/java/net/onelitefeather/vulpes/backend/controller/sound/SoundController.java b/src/main/java/net/onelitefeather/vulpes/backend/controller/sound/SoundController.java index 5ddc533..c381a99 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/controller/sound/SoundController.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/controller/sound/SoundController.java @@ -77,7 +77,7 @@ public SoundController(SoundService soundService) { public HttpResponse add( @Body SoundEventDTO dtoModel ) { - SoundResponseDTO result = soundService.createSoundEvent(dtoModel); + SoundResponseDTO result = soundService.create(dtoModel); if (result instanceof SoundResponseDTO.SoundErrorDTO) { return HttpResponse.badRequest(result); } @@ -109,7 +109,7 @@ public HttpResponse add( @Get("/{id}") @Produces(MediaType.APPLICATION_JSON) public HttpResponse getById(@PathVariable UUID id) { - var soundEvent = soundService.findSoundEventById(id); + var soundEvent = soundService.findById(id); if (soundEvent.isPresent()) { return HttpResponse.ok(SoundResponseDTO.SoundModelDTO.createDTO(soundEvent.get())); } @@ -141,7 +141,7 @@ public HttpResponse getById(@PathVariable UUID id) { @Delete("/delete/{id}") @Produces(MediaType.APPLICATION_JSON) public HttpResponse remove(@PathVariable UUID id) { - SoundResponseDTO result = soundService.deleteSoundEvent(id); + SoundResponseDTO result = soundService.delete(id); if (result instanceof SoundResponseDTO.SoundErrorDTO) { return HttpResponse.notFound(result); } @@ -176,7 +176,7 @@ public HttpResponse remove(@PathVariable UUID id) { @Get("/") @Produces(MediaType.APPLICATION_JSON) public HttpResponse> getAll(Pageable pageable) { - Page returnValues = soundService.getAllSoundEvents(pageable); + Page returnValues = soundService.getAll(pageable); return HttpResponse.ok(returnValues); } @@ -197,7 +197,7 @@ public HttpResponse> getAll(Pageable pageab @Delete("/delete/") @Produces(MediaType.APPLICATION_JSON) public HttpResponse> deleteAll() { - List results = soundService.deleteAllSoundEvents(); + List results = soundService.deleteAll(); return HttpResponse.ok(results); } @@ -227,7 +227,7 @@ public HttpResponse> deleteAll() { @Produces(MediaType.APPLICATION_JSON) @Validated(groups = ValidationGroup.Update.class) public HttpResponse update(@Body SoundEventDTO model) { - SoundResponseDTO result = soundService.updateSoundEvent(model); + SoundResponseDTO result = soundService.update(model); if (result instanceof SoundResponseDTO.SoundErrorDTO) { return HttpResponse.notFound(result); } From 377f916b19c8a2afa031b32ea6ee2c2e5a7fb324 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Fri, 21 Aug 2026 16:47:36 +0200 Subject: [PATCH 4/5] test(sound): update method names --- .../backend/controller/SoundControllerTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/net/onelitefeather/vulpes/backend/controller/SoundControllerTest.java b/src/test/java/net/onelitefeather/vulpes/backend/controller/SoundControllerTest.java index 1147db0..1a55676 100644 --- a/src/test/java/net/onelitefeather/vulpes/backend/controller/SoundControllerTest.java +++ b/src/test/java/net/onelitefeather/vulpes/backend/controller/SoundControllerTest.java @@ -33,32 +33,32 @@ private static class StubSoundService implements SoundService { SoundResponseDTO.SoundFileSourceDTO sourceResponse; @Override - public SoundResponseDTO.SoundModelDTO createSoundEvent(SoundEventDTO soundEventDTO) { + public SoundResponseDTO.SoundModelDTO create(SoundEventDTO soundEventDTO) { return (SoundResponseDTO.SoundModelDTO) response; } @Override - public SoundResponseDTO updateSoundEvent(SoundEventDTO soundEventDTO) { + public SoundResponseDTO update(SoundEventDTO soundEventDTO) { return response; } @Override - public SoundResponseDTO deleteSoundEvent(UUID id) { + public SoundResponseDTO delete(UUID id) { return response; } @Override - public List deleteAllSoundEvents() { + public List deleteAll() { return List.of(); } @Override - public Page getAllSoundEvents(Pageable pageable) { + public Page getAll(Pageable pageable) { return modelDtoPage; } @Override - public Optional findSoundEventById(UUID id) { + public Optional findById(UUID id) { return findByIdResponse; } From 38a90148a1e5fe0eb8d27c4340b95feaa0678883 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Fri, 21 Aug 2026 16:52:22 +0200 Subject: [PATCH 5/5] chore(service): improve docs and naming --- .../service/impl/AbstractCrudService.java | 102 ++++++++++-------- 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AbstractCrudService.java b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AbstractCrudService.java index c414f95..6f9d5dd 100644 --- a/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AbstractCrudService.java +++ b/src/main/java/net/onelitefeather/vulpes/backend/service/impl/AbstractCrudService.java @@ -22,102 +22,120 @@ public abstract class AbstractCrudService implements CrudService { protected final PageableRepository repository; - protected final Function toEntityMapper; - protected final Function toSuccessDtoMapper; - protected final Function toListSuccessDtoMapper; - protected final Function idExtractor; - protected final Function errorDtoFactory; + protected final Function entityMapper; + protected final Function dtoMapper; + protected final Function dtoListMapper; + protected final Function idMapper; + protected final Function errorMapper; protected final String entityName; /** * Constructs a new AbstractCrudService with identical mapping for single and list representations. * - * @param repository the pageable repository - * @param toEntityMapper function to convert a request DTO to an entity - * @param toSuccessDtoMapper function to convert an entity to a success DTO - * @param idExtractor function to extract the ID from a request DTO - * @param errorDtoFactory function to create an error response DTO from an error message - * @param entityName the human-readable entity name for error messages + * @param repository the pageable repository + * @param entityMapper to convert a request DTO to an entity + * @param dtoMapper to convert an entity to a success DTO + * @param idMapper to extract the ID from a request DTO + * @param errorMapper to create an error response DTO from an error message + * @param entityName the human-readable entity name for error messages */ protected AbstractCrudService( PageableRepository repository, - Function toEntityMapper, - Function toSuccessDtoMapper, - Function idExtractor, - Function errorDtoFactory, + Function entityMapper, + Function dtoMapper, + Function idMapper, + Function errorMapper, String entityName ) { - this(repository, toEntityMapper, toSuccessDtoMapper, toSuccessDtoMapper, idExtractor, errorDtoFactory, entityName); + this(repository, entityMapper, dtoMapper, dtoMapper, idMapper, errorMapper, entityName); } /** * Constructs a new AbstractCrudService with custom mapping for single and list representations. * - * @param repository the pageable repository - * @param toEntityMapper function to convert a request DTO to an entity - * @param toSuccessDtoMapper function to convert an entity to a single success DTO - * @param toListSuccessDtoMapper function to convert an entity to a list success DTO - * @param idExtractor function to extract the ID from a request DTO - * @param errorDtoFactory function to create an error response DTO from an error message - * @param entityName the human-readable entity name for error messages + * @param repository the pageable repository + * @param entityMapper to convert a request DTO to an entity + * @param dtoMapper to convert an entity to a single success DTO + * @param dtoListMapper to convert an entity to a list success DTO + * @param idMapper to extract the ID from a request DTO + * @param errorMapper to create an error response DTO from an error message + * @param entityName the human-readable entity name for error messages */ protected AbstractCrudService( PageableRepository repository, - Function toEntityMapper, - Function toSuccessDtoMapper, - Function toListSuccessDtoMapper, - Function idExtractor, - Function errorDtoFactory, + Function entityMapper, + Function dtoMapper, + Function dtoListMapper, + Function idMapper, + Function errorMapper, String entityName ) { this.repository = repository; - this.toEntityMapper = toEntityMapper; - this.toSuccessDtoMapper = toSuccessDtoMapper; - this.toListSuccessDtoMapper = toListSuccessDtoMapper; - this.idExtractor = idExtractor; - this.errorDtoFactory = errorDtoFactory; + this.entityMapper = entityMapper; + this.dtoMapper = dtoMapper; + this.dtoListMapper = dtoListMapper; + this.idMapper = idMapper; + this.errorMapper = errorMapper; this.entityName = entityName; } + /** + * {@inheritDoc} + */ @Override public SUCCESS create(REQ dto) { - E entity = toEntityMapper.apply(dto); + E entity = entityMapper.apply(dto); E saved = repository.save(entity); - return toSuccessDtoMapper.apply(saved); + return dtoMapper.apply(saved); } + /** + * {@inheritDoc} + */ @Override public RES update(REQ dto) { - ID id = idExtractor.apply(dto); + ID id = idMapper.apply(dto); if (id == null || repository.findById(id).isEmpty()) { - return errorDtoFactory.apply(entityName + " not found"); + return errorMapper.apply(entityName + " not found"); } - E entity = toEntityMapper.apply(dto); + E entity = entityMapper.apply(dto); E updated = repository.update(entity); - return toSuccessDtoMapper.apply(updated); + return dtoMapper.apply(updated); } + /** + * {@inheritDoc} + */ @Override public RES delete(ID id) { Optional existing = repository.findById(id); if (existing.isPresent()) { repository.deleteById(id); - return toSuccessDtoMapper.apply(existing.get()); + return dtoMapper.apply(existing.get()); } - return errorDtoFactory.apply(entityName + " not found"); + return errorMapper.apply(entityName + " not found"); } + /** + * {@inheritDoc} + */ @Override public List deleteAll() { repository.deleteAll(); return List.of(); } + /** + * {@inheritDoc} + */ @Override public Page getAll(Pageable pageable) { - return repository.findAll(pageable).map(toListSuccessDtoMapper::apply); + return repository.findAll(pageable).map(dtoListMapper); } + /** + * {@inheritDoc} + */ @Override public Optional findById(ID id) { return repository.findById(id);