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 @@ -12,6 +12,8 @@
import io.micronaut.http.annotation.Post;
import io.micronaut.http.annotation.Produces;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -268,30 +270,30 @@ public HttpResponse<Page<SoundResponseDTO>> get(@PathVariable UUID id, Pageable
* Creates a new SoundFileSource and links it to a SoundEventEntity by ID.
*
* @param soundEventId the ID of the SoundEventEntity
* @param sourceDTO the DTO containing source data
* @param sourceDTO the DTO containing source data
* @return the created SoundFileSourceDTO
*/
@Operation(
summary = "Create and link a SoundFileSource",
operationId = "createAndLinkSoundFileSource",
description = "Creates a new SoundFileSource and links it to a SoundEventEntity by its ID.",
tags = {"Sound"}
summary = "Create and link a SoundFileSource",
operationId = "createAndLinkSoundFileSource",
description = "Creates a new SoundFileSource and links it to a SoundEventEntity by its ID.",
tags = {"Sound"}
)
@ApiResponse(
responseCode = "200",
description = "The SoundFileSource was successfully created and linked.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = SoundResponseDTO.SoundFileSourceDTO.class)
)
responseCode = "200",
description = "The SoundFileSource was successfully created and linked.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = SoundResponseDTO.SoundFileSourceDTO.class)
)
)
@ApiResponse(
responseCode = "404",
description = "The SoundEventEntity was not found.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = SoundResponseDTO.SoundFileSourceDTO.class)
)
responseCode = "404",
description = "The SoundEventEntity was not found.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = SoundResponseDTO.SoundFileSourceDTO.class)
)
)
@Post("{id}/sources")
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -307,7 +309,7 @@ public HttpResponse<SoundResponseDTO> createSource(
* Updates an existing SoundFileSource linked to a SoundEventEntity by ID.
*
* @param soundEventId the ID of the SoundEventEntity
* @param sourceDTO the DTO containing updated source data
* @param sourceDTO the DTO containing updated source data
* @return the updated SoundFileSourceDTO
*/
@Operation(
Expand Down Expand Up @@ -347,7 +349,7 @@ public HttpResponse<SoundResponseDTO> updateSource(
* Deletes an existing SoundFileSource linked to a SoundEventEntity by ID.
*
* @param soundEventId the ID of the SoundEventEntity
* @param sourceDTO the DTO containing source data to delete
* @param soundId the DTO containing source data to delete
* @return the deleted SoundFileSourceDTO
*/
@Operation(
Expand All @@ -372,19 +374,17 @@ public HttpResponse<SoundResponseDTO> updateSource(
schema = @Schema(implementation = SoundResponseDTO.SoundFileSourceDTO.class)
)
)
@Delete("{id}/sources/delete")
@Delete("{id}/sources/delete/{soundId}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<SoundResponseDTO> deleteSource(
@Parameter(name = "id", description = "The id of the sound event", in = ParameterIn.PATH, required = true)
@PathVariable("id") UUID soundEventId,
@Body SoundFileSourceDTO sourceDTO
@Parameter(name = "soundID", description = "The id of the sound file", in = ParameterIn.PATH, required = true)
@PathVariable("soundId") UUID soundId
) {
SoundResponseDTO result = soundService.deleteLinkedSource(soundEventId, sourceDTO);
SoundResponseDTO result = soundService.deleteLinkedSource(soundEventId, soundId);
return HttpResponse.ok(result);
}






}
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,28 @@ public interface SoundService {

/**
* Creates a new sound file source and links it to a sound event.
*
* @param soundEventId the ID of the sound event to link the source to
* @param sourceDTO the source data to create
* @param sourceDTO the source data to create
* @return the created source response
*/
SoundResponseDTO createAndLinkSource(UUID soundEventId, SoundFileSourceDTO sourceDTO);

/**
* Updates an existing sound file source linked to a sound event by ID.
*
* @param soundEventId the ID of the sound event
* @param sourceDTO the source data to update
* @param sourceDTO the source data to update
* @return the updated source response
*/
SoundResponseDTO updateLinkedSource(UUID soundEventId, SoundFileSourceDTO sourceDTO);

/**
* Deletes an existing sound file source linked to a sound event by ID.
*
* @param soundEventId the ID of the sound event
* @param sourceDTO the source data to delete
* @param sourceId the ID of the source to delete
* @return the deleted source response
*/
SoundResponseDTO deleteLinkedSource(UUID soundEventId, SoundFileSourceDTO sourceDTO);
SoundResponseDTO deleteLinkedSource(UUID soundEventId, UUID sourceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public SoundResponseDTO.SoundFileSourceDTO updateLinkedSource(UUID soundEventId,

@Override
@Transactional
public SoundResponseDTO.SoundFileSourceDTO deleteLinkedSource(UUID soundEventId, SoundFileSourceDTO sourceDTO) {
if (soundEventId == null || sourceDTO == null || sourceDTO.id() == null) {
public SoundResponseDTO.SoundFileSourceDTO deleteLinkedSource(UUID soundEventId, UUID sourceID) {
if (soundEventId == null || sourceID == null) {
throw new IllegalArgumentException("SoundEventId and SourceDTO and SourceDTO.Id must not be null");
}

Expand All @@ -154,12 +154,12 @@ public SoundResponseDTO.SoundFileSourceDTO deleteLinkedSource(UUID soundEventId,
.stream()
.filter(SoundResponseDTO.SoundFileSourceDTO.class::isInstance)
.map(SoundResponseDTO.SoundFileSourceDTO.class::cast)
.filter(s -> s.id().equals(sourceDTO.id()))
.filter(s -> s.id().equals(sourceID))
.findFirst();
if (existingSourceOpt.isEmpty()) {
throw new IllegalArgumentException("Sound source not found for the given sound event");
}
soundFileSourceRepository.deleteById(sourceDTO.id());
soundFileSourceRepository.deleteById(sourceID);
return existingSourceOpt.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public SoundResponseDTO.SoundFileSourceDTO updateLinkedSource(UUID soundEventId,
}

@Override
public SoundResponseDTO.SoundFileSourceDTO deleteLinkedSource(UUID soundEventId, SoundFileSourceDTO sourceDTO) {
public SoundResponseDTO.SoundFileSourceDTO deleteLinkedSource(UUID soundEventId, UUID sourceDTO) {
return sourceResponse;
}
}
Expand Down
Loading