Fix and polish category CRUD.
This commit is contained in:
@@ -3,10 +3,12 @@ package org.codiki.exposition.category;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||
import org.codiki.application.category.CategoryUseCases;
|
||||
import org.codiki.domain.category.model.Category;
|
||||
import org.codiki.exposition.category.model.CategoryDto;
|
||||
import org.codiki.exposition.category.model.CategoryEditionRequest;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
@@ -43,4 +45,10 @@ public class CategoryController {
|
||||
);
|
||||
return new CategoryDto(createdCategory);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{categoryId}")
|
||||
@ResponseStatus(NO_CONTENT)
|
||||
public void deleteCategory(@PathVariable("categoryId") UUID categoryId) {
|
||||
categoryUseCases.deleteCategory(categoryId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
import static org.springframework.http.HttpStatus.UNAUTHORIZED;
|
||||
import org.codiki.domain.category.exception.CategoryDeletionException;
|
||||
import org.codiki.domain.category.exception.CategoryEditionException;
|
||||
import org.codiki.domain.category.exception.CategoryNotFoundException;
|
||||
import org.codiki.domain.exception.LoginFailureException;
|
||||
@@ -73,4 +74,10 @@ public class GlobalControllerExceptionHandler {
|
||||
public void handleCategoryEditionException() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@ResponseStatus(BAD_REQUEST)
|
||||
@ExceptionHandler(CategoryDeletionException.class)
|
||||
public void handleCategoryDeletionException() {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package org.codiki.exposition.configuration.security;
|
||||
|
||||
import static org.springframework.http.HttpMethod.DELETE;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.OPTIONS;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.HttpMethod.PUT;
|
||||
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -52,6 +54,14 @@ public class SecurityConfiguration {
|
||||
POST,
|
||||
"/api/categories"
|
||||
).hasRole("ADMIN")
|
||||
.requestMatchers(
|
||||
PUT,
|
||||
"/api/categories/{categoryId}"
|
||||
).hasRole("ADMIN")
|
||||
.requestMatchers(
|
||||
DELETE,
|
||||
"/api/categories/{categoryId}"
|
||||
).hasRole("ADMIN")
|
||||
.requestMatchers(OPTIONS).permitAll()
|
||||
.anyRequest().authenticated()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user