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
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencyResolutionManagement {
versionCatalogs {
create("libs") {
version("micronaut", "5.0.2")
version("vulpes.model", "1.8.3")
version("vulpes.model", "2.0.0")
version("uuid.creator", "6.1.1")
version("datafaker", "2.7.0")
version("jetbrains.annotation", "26.1.0")
Expand All @@ -48,7 +48,7 @@ dependencyResolutionManagement {
library("vulpes.api", "net.onelitefeather", "vulpes-model").versionRef("vulpes.model")
library("jetbrains.annotation", "org.jetbrains", "annotations").versionRef("jetbrains.annotation")
library("datafaker", "net.datafaker", "datafaker").versionRef("datafaker")
library("testcontainers.junit", "org.testcontainers", "junit-jupiter").withoutVersion()
library("testcontainers.junit", "org.testcontainers", "testcontainers-junit-jupiter").withoutVersion()

library("hibernate.validator", "org.hibernate.validator", "hibernate-validator").versionRef("hibernate.validator")
library("jakarta.validation", "jakarta.validation", "jakarta.validation-api").versionRef("jakarta.validation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.List;
import java.util.UUID;

@Controller("/attribute")
@Controller("/project/{projectId}/attribute")
public class AttributeController {

private final AttributeService attributeService;
Expand All @@ -39,7 +39,7 @@ public AttributeController(AttributeService attributeService) {
@Operation(
summary = "Add a new attribute",
operationId = "addAttribute",
description = "Adds a new attribute to the database. The attribute is created with the given properties.",
description = "Adds a new attribute to the given project.",
tags = {"Attribute"}
)
@ApiResponse(
Expand All @@ -51,24 +51,27 @@ public AttributeController(AttributeService attributeService) {
)
)
@ApiResponse(
responseCode = "500",
description = "The attribute could not be added to the database.",
responseCode = "404",
description = "The project was not found.",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = AttributeModelResponseDTO.AttributeModelErrorDTO.class)
)
)
@Post
@Validated(groups = ValidationGroup.Create.class)
public HttpResponse<AttributeModelResponseDTO> add(@Body AttributeModelDTO model) {
AttributeModelResponseDTO.AttributeModelDTO createdAttribute = attributeService.create(model);
return HttpResponse.ok(createdAttribute);
public HttpResponse<AttributeModelResponseDTO> add(@PathVariable UUID projectId, @Body AttributeModelDTO model) {
AttributeModelResponseDTO result = attributeService.create(projectId, model);
if (result instanceof AttributeModelResponseDTO.AttributeModelErrorDTO) {
return HttpResponse.notFound(result);
}
return HttpResponse.ok(result);
}

@Operation(
summary = "Update an attribute",
operationId = "updateAttribute",
description = "Returns the attribute with the given ID.",
description = "Updates an attribute owned by the given project.",
tags = {"Attribute"}
)
@ApiResponse(
Expand All @@ -81,16 +84,16 @@ public HttpResponse<AttributeModelResponseDTO> add(@Body AttributeModelDTO model
)
@ApiResponse(
responseCode = "404",
description = "The attribute was not found.",
description = "The attribute was not found, or does not belong to the given project.",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = AttributeModelResponseDTO.AttributeModelErrorDTO.class)
)
)
@Post("/update")
@Validated(groups = ValidationGroup.Update.class)
public HttpResponse<AttributeModelResponseDTO> update(@Body AttributeModelDTO model) {
AttributeModelResponseDTO result = attributeService.update(model);
public HttpResponse<AttributeModelResponseDTO> update(@PathVariable UUID projectId, @Body AttributeModelDTO model) {
AttributeModelResponseDTO result = attributeService.update(projectId, model);
if (result instanceof AttributeModelResponseDTO.AttributeModelErrorDTO) {
return HttpResponse.notFound(result);
}
Expand All @@ -100,7 +103,7 @@ public HttpResponse<AttributeModelResponseDTO> update(@Body AttributeModelDTO mo
@Operation(
summary = "Delete an attribute by ID",
operationId = "deleteAttributeById",
description = "Deletes the attribute with the given ID.",
description = "Deletes an attribute owned by the given project.",
tags = {"Attribute"}
)
@ApiResponse(
Expand All @@ -113,30 +116,30 @@ public HttpResponse<AttributeModelResponseDTO> update(@Body AttributeModelDTO mo
)
@ApiResponse(
responseCode = "404",
description = "The attribute was not found.",
description = "The attribute was not found, or does not belong to the given project.",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = AttributeModelResponseDTO.AttributeModelErrorDTO.class)
)
)
@Delete("/delete/{id}")
public HttpResponse<AttributeModelResponseDTO> delete(@PathVariable UUID id) {
AttributeModelResponseDTO result = attributeService.delete(id);
public HttpResponse<AttributeModelResponseDTO> delete(@PathVariable UUID projectId, @PathVariable UUID id) {
AttributeModelResponseDTO result = attributeService.delete(projectId, id);
if (result instanceof AttributeModelResponseDTO.AttributeModelErrorDTO) {
return HttpResponse.notFound(result);
}
return HttpResponse.ok(result);
}

/**
* Deletes all [AttributeModel] from the database.
* Deletes all [AttributeModel] belonging to the given project.
*
* @return a list with all [AttributeModel] mapped in a [HttpResponse]
* @return a list with all deleted [AttributeModel] mapped in a [HttpResponse]
*/
@Operation(
summary = "Delete all attributes",
operationId = "deleteAllAttributes",
description = "Deletes all attributes from the database.",
description = "Deletes all attributes belonging to the given project.",
tags = {"Attribute"}
)
@ApiResponse(
Expand All @@ -148,20 +151,20 @@ public HttpResponse<AttributeModelResponseDTO> delete(@PathVariable UUID id) {
)
)
@Delete("/delete")
public HttpResponse<List<AttributeModelResponseDTO>> deleteAll() {
List<AttributeModelResponseDTO> result = attributeService.deleteAll();
public HttpResponse<List<AttributeModelResponseDTO>> deleteAll(@PathVariable UUID projectId) {
List<AttributeModelResponseDTO> result = attributeService.deleteAll(projectId);
return HttpResponse.ok(result);
}

/**
* Returns all [AttributeModel] which are currently persists in the database.
* Returns all [AttributeModel] belonging to the given project.
*
* @return a list with all [AttributeModel] mapped in a [HttpResponse]
*/
@Operation(
summary = "Get all attributes",
operationId = "getAllAttributes",
description = "Gets all attributes from the database.",
description = "Gets all attributes belonging to the given project.",
tags = {"Attribute"}
)
@ApiResponse(
Expand All @@ -177,8 +180,8 @@ public HttpResponse<List<AttributeModelResponseDTO>> deleteAll() {
)
@Produces(MediaType.APPLICATION_JSON)
@Get(uris = {"/"})
public HttpResponse<Page<AttributeModelResponseDTO.AttributeModelDTO>> getAll(Pageable pageable) {
Page<AttributeModelResponseDTO.AttributeModelDTO> models = attributeService.getAll(pageable);
public HttpResponse<Page<AttributeModelResponseDTO.AttributeModelDTO>> getAll(@PathVariable UUID projectId, Pageable pageable) {
Page<AttributeModelResponseDTO.AttributeModelDTO> models = attributeService.getAll(projectId, pageable);
return HttpResponse.ok(models);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @version 1.0.0
* @since 1.0.0
*/
@Controller("/notification")
@Controller("/project/{projectId}/notification")
public class NotificationController {

private final NotificationService notificationService;
Expand All @@ -40,16 +40,10 @@ public NotificationController(NotificationService notificationService) {
this.notificationService = notificationService;
}

/**
* Adds a new notification.
*
* @param model the notification model to be added
* @return HttpResponse containing the added notification
*/
@Operation(
summary = "Add a new notification",
operationId = "addNotification",
description = "Adds a new notification to the database.",
description = "Adds a new notification to the given project.",
tags = {"Notification"}
)
@ApiResponse(
Expand All @@ -61,8 +55,8 @@ public NotificationController(NotificationService notificationService) {
)
)
@ApiResponse(
responseCode = "500",
description = "The notification could not be added to the database.",
responseCode = "404",
description = "The project was not found.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = NotificationModelResponseDTO.NotificationModelErrorDTO.class)
Expand All @@ -71,23 +65,18 @@ public NotificationController(NotificationService notificationService) {
@Post
@Produces(MediaType.APPLICATION_JSON)
@Validated(groups = ValidationGroup.Create.class)
public HttpResponse<NotificationModelResponseDTO> add(
@Body NotificationModelDTO model
) {
NotificationModelResponseDTO.NotificationModelDTO result = notificationService.create(model);
public HttpResponse<NotificationModelResponseDTO> add(@PathVariable UUID projectId, @Body NotificationModelDTO model) {
NotificationModelResponseDTO result = notificationService.create(projectId, model);
if (result instanceof NotificationModelResponseDTO.NotificationModelErrorDTO) {
return HttpResponse.notFound(result);
}
return HttpResponse.ok(result);
}

/**
* Retrieves a notification by its ID.
*
* @param id the ID of the notification to retrieve
* @return HttpResponse containing the notification if found, or not found response
*/
@Operation(
summary = "Get a notification by ID",
operationId = "getNotificationById",
description = "Retrieves a notification from the database by its ID.",
description = "Retrieves a notification owned by the given project by its ID.",
tags = {"Notification"}
)
@ApiResponse(
Expand All @@ -100,32 +89,26 @@ public HttpResponse<NotificationModelResponseDTO> add(
)
@ApiResponse(
responseCode = "404",
description = "The notification was not found in the database.",
description = "The notification was not found, or does not belong to the given project.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = NotificationModelResponseDTO.NotificationModelErrorDTO.class)
)
)
@Get("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<NotificationModelResponseDTO> getById(@PathVariable UUID id) {
Optional<NotificationEntity> model = notificationService.findById(id);
public HttpResponse<NotificationModelResponseDTO> getById(@PathVariable UUID projectId, @PathVariable UUID id) {
Optional<NotificationEntity> model = notificationService.findById(projectId, id);
if (model.isPresent()) {
return HttpResponse.ok(NotificationModelResponseDTO.NotificationModelDTO.createDTO(model.get()));
}
return HttpResponse.notFound(new NotificationModelResponseDTO.NotificationModelErrorDTO("Notification not found"));
}

/**
* Removes a notification by its ID.
*
* @param id the ID of the notification to remove
* @return HttpResponse containing the removed notification if found, or not found response
*/
@Operation(
summary = "Remove a notification by ID",
operationId = "removeNotificationById",
description = "Removes a notification from the database by its ID.",
description = "Removes a notification owned by the given project by its ID.",
tags = {"Notification"}
)
@ApiResponse(
Expand All @@ -138,31 +121,26 @@ public HttpResponse<NotificationModelResponseDTO> getById(@PathVariable UUID id)
)
@ApiResponse(
responseCode = "404",
description = "The notification was not found in the database.",
description = "The notification was not found, or does not belong to the given project.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = NotificationModelResponseDTO.NotificationModelErrorDTO.class)
)
)
@Delete("/delete/{id}")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<NotificationModelResponseDTO> remove(@PathVariable UUID id) {
NotificationModelResponseDTO result = notificationService.delete(id);
public HttpResponse<NotificationModelResponseDTO> remove(@PathVariable UUID projectId, @PathVariable UUID id) {
NotificationModelResponseDTO result = notificationService.delete(projectId, id);
if (result instanceof NotificationModelResponseDTO.NotificationModelErrorDTO) {
return HttpResponse.notFound(result);
}
return HttpResponse.ok(result);
}

/**
* Retrieves all notifications.
*
* @return HttpResponse containing a list of all notifications
*/
@Operation(
summary = "Get all notifications",
operationId = "getAllNotifications",
description = "Retrieves all notifications from the database.",
description = "Retrieves all notifications belonging to the given project.",
tags = {"Notification"}
)
@ApiResponse(
Expand All @@ -176,30 +154,17 @@ public HttpResponse<NotificationModelResponseDTO> remove(@PathVariable UUID id)
)
)
)
@ApiResponse(
responseCode = "404",
description = "No notifications were found in the database.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = NotificationModelResponseDTO.NotificationModelErrorDTO.class)
)
)
@Get(uris = {"/"})
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<Page<NotificationModelResponseDTO.NotificationModelDTO>> getAll(Pageable pageable) {
Page<NotificationModelResponseDTO.NotificationModelDTO> list = notificationService.getAll(pageable);
public HttpResponse<Page<NotificationModelResponseDTO.NotificationModelDTO>> getAll(@PathVariable UUID projectId, Pageable pageable) {
Page<NotificationModelResponseDTO.NotificationModelDTO> list = notificationService.getAll(projectId, pageable);
return HttpResponse.ok(list);
}

/**
* Deletes all notifications.
*
* @return HttpResponse containing an empty list
*/
@Operation(
summary = "Delete all notifications",
operationId = "deleteAllNotifications",
description = "Deletes all notifications from the database.",
description = "Deletes all notifications belonging to the given project.",
tags = {"Notification"}
)
@ApiResponse(
Expand All @@ -212,21 +177,15 @@ public HttpResponse<Page<NotificationModelResponseDTO.NotificationModelDTO>> get
)
@Delete("/delete/")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<List<NotificationModelResponseDTO>> deleteAll() {
List<NotificationModelResponseDTO> result = notificationService.deleteAll();
public HttpResponse<List<NotificationModelResponseDTO>> deleteAll(@PathVariable UUID projectId) {
List<NotificationModelResponseDTO> result = notificationService.deleteAll(projectId);
return HttpResponse.ok(result);
}

/**
* Updates an existing notification.
*
* @param model the notification model to update
* @return HttpResponse containing the updated notification
*/
@Operation(
summary = "Update a notification",
operationId = "updateNotification",
description = "Updates an existing notification in the database.",
description = "Updates a notification owned by the given project.",
tags = {"Notification"}
)
@ApiResponse(
Expand All @@ -239,7 +198,7 @@ public HttpResponse<List<NotificationModelResponseDTO>> deleteAll() {
)
@ApiResponse(
responseCode = "404",
description = "The notification was not found in the database.",
description = "The notification was not found, or does not belong to the given project.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = NotificationModelResponseDTO.NotificationModelErrorDTO.class)
Expand All @@ -248,8 +207,8 @@ public HttpResponse<List<NotificationModelResponseDTO>> deleteAll() {
@Post("/update")
@Produces(MediaType.APPLICATION_JSON)
@Validated(groups = ValidationGroup.Update.class)
public HttpResponse<NotificationModelResponseDTO> update(@Body NotificationModelDTO model) {
NotificationModelResponseDTO result = notificationService.update(model);
public HttpResponse<NotificationModelResponseDTO> update(@PathVariable UUID projectId, @Body NotificationModelDTO model) {
NotificationModelResponseDTO result = notificationService.update(projectId, model);
if (result instanceof NotificationModelResponseDTO.NotificationModelErrorDTO) {
return HttpResponse.notFound(result);
}
Expand Down
Loading
Loading