Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public AttributeController(AttributeService attributeService) {
@Post
@Validated(groups = ValidationGroup.Create.class)
public HttpResponse<AttributeModelResponseDTO> add(@Body AttributeModelDTO model) {
AttributeModelResponseDTO.AttributeModelDTO createdAttribute = attributeService.createAttribute(model);
AttributeModelResponseDTO.AttributeModelDTO createdAttribute = attributeService.create(model);
return HttpResponse.ok(createdAttribute);
}

Expand Down Expand Up @@ -90,7 +90,7 @@ public HttpResponse<AttributeModelResponseDTO> add(@Body AttributeModelDTO model
@Post("/update")
@Validated(groups = ValidationGroup.Update.class)
public HttpResponse<AttributeModelResponseDTO> update(@Body AttributeModelDTO model) {
AttributeModelResponseDTO result = attributeService.updateAttribute(model);
AttributeModelResponseDTO result = attributeService.update(model);
if (result instanceof AttributeModelResponseDTO.AttributeModelErrorDTO) {
return HttpResponse.notFound(result);
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public HttpResponse<AttributeModelResponseDTO> update(@Body AttributeModelDTO mo
)
@Delete("/delete/{id}")
public HttpResponse<AttributeModelResponseDTO> delete(@PathVariable UUID id) {
AttributeModelResponseDTO result = attributeService.deleteAttribute(id);
AttributeModelResponseDTO result = attributeService.delete(id);
if (result instanceof AttributeModelResponseDTO.AttributeModelErrorDTO) {
return HttpResponse.notFound(result);
}
Expand Down Expand Up @@ -149,7 +149,7 @@ public HttpResponse<AttributeModelResponseDTO> delete(@PathVariable UUID id) {
)
@Delete("/delete")
public HttpResponse<List<AttributeModelResponseDTO>> deleteAll() {
List<AttributeModelResponseDTO> result = attributeService.deleteAllAttributes();
List<AttributeModelResponseDTO> result = attributeService.deleteAll();
return HttpResponse.ok(result);
}

Expand Down Expand Up @@ -178,7 +178,7 @@ public HttpResponse<List<AttributeModelResponseDTO>> deleteAll() {
@Produces(MediaType.APPLICATION_JSON)
@Get(uris = {"/"})
public HttpResponse<Page<AttributeModelResponseDTO.AttributeModelDTO>> getAll(Pageable pageable) {
Page<AttributeModelResponseDTO.AttributeModelDTO> models = attributeService.getAllAttributes(pageable);
Page<AttributeModelResponseDTO.AttributeModelDTO> models = attributeService.getAll(pageable);
return HttpResponse.ok(models);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public NotificationController(NotificationService notificationService) {
public HttpResponse<NotificationModelResponseDTO> add(
@Body NotificationModelDTO model
) {
NotificationModelResponseDTO.NotificationModelDTO result = notificationService.createNotification(model);
NotificationModelResponseDTO.NotificationModelDTO result = notificationService.create(model);
return HttpResponse.ok(result);
}

Expand Down Expand Up @@ -109,7 +109,7 @@ public HttpResponse<NotificationModelResponseDTO> add(
@Get("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<NotificationModelResponseDTO> getById(@PathVariable UUID id) {
Optional<NotificationEntity> model = notificationService.findNotificationById(id);
Optional<NotificationEntity> model = notificationService.findById(id);
if (model.isPresent()) {
return HttpResponse.ok(NotificationModelResponseDTO.NotificationModelDTO.createDTO(model.get()));
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public HttpResponse<NotificationModelResponseDTO> getById(@PathVariable UUID id)
@Delete("/delete/{id}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<NotificationModelResponseDTO> remove(@PathVariable UUID id) {
NotificationModelResponseDTO result = notificationService.deleteNotification(id);
NotificationModelResponseDTO result = notificationService.delete(id);
if (result instanceof NotificationModelResponseDTO.NotificationModelErrorDTO) {
return HttpResponse.notFound(result);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public HttpResponse<NotificationModelResponseDTO> remove(@PathVariable UUID id)
@Get(uris = {"/"})
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<Page<NotificationModelResponseDTO.NotificationModelDTO>> getAll(Pageable pageable) {
Page<NotificationModelResponseDTO.NotificationModelDTO> list = notificationService.getAllNotifications(pageable);
Page<NotificationModelResponseDTO.NotificationModelDTO> list = notificationService.getAll(pageable);
return HttpResponse.ok(list);
}

Expand All @@ -213,7 +213,7 @@ public HttpResponse<Page<NotificationModelResponseDTO.NotificationModelDTO>> get
@Delete("/delete/")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<List<NotificationModelResponseDTO>> deleteAll() {
List<NotificationModelResponseDTO> result = notificationService.deleteAllNotifications();
List<NotificationModelResponseDTO> result = notificationService.deleteAll();
return HttpResponse.ok(result);
}

Expand Down Expand Up @@ -249,7 +249,7 @@ public HttpResponse<List<NotificationModelResponseDTO>> deleteAll() {
@Produces(MediaType.APPLICATION_JSON)
@Validated(groups = ValidationGroup.Update.class)
public HttpResponse<NotificationModelResponseDTO> update(@Body NotificationModelDTO model) {
NotificationModelResponseDTO result = notificationService.updateNotification(model);
NotificationModelResponseDTO result = notificationService.update(model);
if (result instanceof NotificationModelResponseDTO.NotificationModelErrorDTO) {
return HttpResponse.notFound(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public FontController(FontService fontService) {
public HttpResponse<FontModelResponseDTO> add(
@Body FontModelDTO item
) {
FontModelResponseDTO.FontModelDTO result = fontService.createFont(item);
FontModelResponseDTO.FontModelDTO result = fontService.create(item);
return HttpResponse.ok(result);
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public HttpResponse<FontModelResponseDTO> add(
@Get("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<FontModelResponseDTO> getById(@PathVariable UUID id) {
Optional<FontEntity> model = fontService.findFontById(id);
Optional<FontEntity> model = fontService.findById(id);
if (model.isPresent()) {
FontEntity fontModel = model.get();
FontModelResponseDTO.FontModelDTO dto = FontModelResponseDTO.FontModelDTO.createDTO(fontModel);
Expand Down Expand Up @@ -131,7 +131,7 @@ public HttpResponse<FontModelResponseDTO> getById(@PathVariable UUID id) {
@Delete("/delete/{id}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<FontModelResponseDTO> remove(@PathVariable UUID id) {
FontModelResponseDTO result = fontService.deleteFont(id);
FontModelResponseDTO result = fontService.delete(id);
if (result instanceof FontModelResponseDTO.FontModelErrorDTO) {
return HttpResponse.notFound(result);
}
Expand All @@ -158,7 +158,7 @@ public HttpResponse<FontModelResponseDTO> remove(@PathVariable UUID id) {
@Get(uris = {"/"})
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<Page<FontModelResponseDTO.FontModelDTO>> getAll(Pageable pageable) {
Page<FontModelResponseDTO.FontModelDTO> models = fontService.getAllFonts(pageable);
Page<FontModelResponseDTO.FontModelDTO> models = fontService.getAll(pageable);
return HttpResponse.ok(models);
}

Expand All @@ -179,7 +179,7 @@ public HttpResponse<Page<FontModelResponseDTO.FontModelDTO>> getAll(Pageable pag
@Delete("delete")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<List<FontModelResponseDTO>> deleteAll() {
List<FontModelResponseDTO> result = fontService.deleteAllFonts();
List<FontModelResponseDTO> result = fontService.deleteAll();
return HttpResponse.ok(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ItemController(ItemService itemService) {
public HttpResponse<ItemModelResponseDTO> add(
@Body ItemModelDTO itemModel
) {
ItemModelResponseDTO.ItemModelDTO createdItem = itemService.createItem(itemModel);
ItemModelResponseDTO.ItemModelDTO createdItem = itemService.create(itemModel);
return HttpResponse.ok(createdItem);
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public HttpResponse<ItemModelResponseDTO> add(
public HttpResponse<ItemModelResponseDTO> getById(
@PathVariable("itemId") UUID itemId
) {
Optional<ItemEntity> foundItemOpt = itemService.findItemById(itemId);
Optional<ItemEntity> foundItemOpt = itemService.findById(itemId);
if (foundItemOpt.isPresent()) {
var foundItem = foundItemOpt.get();
return HttpResponse.ok(ItemModelResponseDTO.ItemModelDTO.createDTO(foundItem));
Expand Down Expand Up @@ -129,7 +129,7 @@ public HttpResponse<ItemModelResponseDTO> getById(
@Get
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<Page<ItemModelResponseDTO.ItemModelDTO>> getAll(Pageable pageable) {
Page<ItemModelResponseDTO.ItemModelDTO> itemsPage = itemService.getAllItems(pageable);
Page<ItemModelResponseDTO.ItemModelDTO> itemsPage = itemService.getAll(pageable);
return HttpResponse.ok(itemsPage);
}

Expand Down Expand Up @@ -161,7 +161,7 @@ public HttpResponse<Page<ItemModelResponseDTO.ItemModelDTO>> getAll(Pageable pag
public HttpResponse<ItemModelResponseDTO> update(
@Body ItemModelDTO itemModel
) {
ItemModelResponseDTO updateResult = itemService.updateItem(itemModel);
ItemModelResponseDTO updateResult = itemService.update(itemModel);
if (updateResult instanceof ItemModelResponseDTO.ItemModelErrorDTO) {
return HttpResponse.notFound(updateResult);
}
Expand Down Expand Up @@ -193,7 +193,7 @@ public HttpResponse<ItemModelResponseDTO> update(
@Delete("/delete/{itemId}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<ItemModelResponseDTO> delete(@PathVariable("itemId") UUID itemId) {
ItemModelResponseDTO deleteResult = itemService.deleteItem(itemId);
ItemModelResponseDTO deleteResult = itemService.delete(itemId);
if (deleteResult instanceof ItemModelResponseDTO.ItemModelErrorDTO) {
return HttpResponse.notFound(deleteResult);
}
Expand All @@ -218,7 +218,7 @@ public HttpResponse<ItemModelResponseDTO> delete(@PathVariable("itemId") UUID it
@Delete("/deleteAll")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<List<ItemModelResponseDTO>> deleteAll() {
List<ItemModelResponseDTO> deleteResults = itemService.deleteAllItems();
List<ItemModelResponseDTO> deleteResults = itemService.deleteAll();
return HttpResponse.ok(deleteResults);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public SoundController(SoundService soundService) {
public HttpResponse<SoundResponseDTO> add(
@Body SoundEventDTO dtoModel
) {
SoundResponseDTO result = soundService.createSoundEvent(dtoModel);
SoundResponseDTO result = soundService.create(dtoModel);
if (result instanceof SoundResponseDTO.SoundErrorDTO) {
return HttpResponse.badRequest(result);
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public HttpResponse<SoundResponseDTO> add(
@Get("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<SoundResponseDTO> 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()));
}
Expand Down Expand Up @@ -141,7 +141,7 @@ public HttpResponse<SoundResponseDTO> getById(@PathVariable UUID id) {
@Delete("/delete/{id}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<SoundResponseDTO> remove(@PathVariable UUID id) {
SoundResponseDTO result = soundService.deleteSoundEvent(id);
SoundResponseDTO result = soundService.delete(id);
if (result instanceof SoundResponseDTO.SoundErrorDTO) {
return HttpResponse.notFound(result);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public HttpResponse<SoundResponseDTO> remove(@PathVariable UUID id) {
@Get("/")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<Page<SoundResponseDTO.SoundModelDTO>> getAll(Pageable pageable) {
Page<SoundResponseDTO.SoundModelDTO> returnValues = soundService.getAllSoundEvents(pageable);
Page<SoundResponseDTO.SoundModelDTO> returnValues = soundService.getAll(pageable);
return HttpResponse.ok(returnValues);
}

Expand All @@ -197,7 +197,7 @@ public HttpResponse<Page<SoundResponseDTO.SoundModelDTO>> getAll(Pageable pageab
@Delete("/delete/")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<List<SoundResponseDTO>> deleteAll() {
List<SoundResponseDTO> results = soundService.deleteAllSoundEvents();
List<SoundResponseDTO> results = soundService.deleteAll();
return HttpResponse.ok(results);
}

Expand Down Expand Up @@ -227,7 +227,7 @@ public HttpResponse<List<SoundResponseDTO>> deleteAll() {
@Produces(MediaType.APPLICATION_JSON)
@Validated(groups = ValidationGroup.Update.class)
public HttpResponse<SoundResponseDTO> update(@Body SoundEventDTO model) {
SoundResponseDTO result = soundService.updateSoundEvent(model);
SoundResponseDTO result = soundService.update(model);
if (result instanceof SoundResponseDTO.SoundErrorDTO) {
return HttpResponse.notFound(result);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AttributeModelResponseDTO> deleteAllAttributes();

/**
* Gets all attributes.
*
* @return a list of all attributes
*/
Page<AttributeModelResponseDTO.AttributeModelDTO> 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<AttributeEntity> findAttributeById(UUID id);
public interface AttributeService extends CrudService<AttributeEntity, UUID, AttributeModelDTO, AttributeModelResponseDTO, AttributeModelResponseDTO.AttributeModelDTO> {
}
Original file line number Diff line number Diff line change
@@ -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 <E> the entity type
* @param <ID> the entity identifier type
* @param <REQ> the request DTO type
* @param <RES> the response DTO interface type
* @param <SUCCESS> the concrete success response DTO type
*/
public interface CrudService<E, ID, REQ, RES, SUCCESS extends RES> {

/**
* 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<RES> deleteAll();

/**
* Retrieves all entities with pagination support.
*
* @param pageable pagination details
* @return a page of success DTOs
*/
Page<SUCCESS> 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<E> findById(ID id);
}
Loading
Loading