Implementation of category creation.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package org.codiki.exposition.category;
|
||||
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
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.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/categories")
|
||||
public class CategoryController {
|
||||
private final CategoryUseCases categoryUseCases;
|
||||
|
||||
public CategoryController(CategoryUseCases categoryUseCases) {
|
||||
this.categoryUseCases = categoryUseCases;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ResponseStatus(CREATED)
|
||||
public CategoryDto createCategory(@RequestBody CategoryEditionRequest request) {
|
||||
Category createdCategory = categoryUseCases.createCategory(request.name(), request.subCategoryIds());
|
||||
return new CategoryDto(createdCategory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.codiki.exposition.category.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record CategoryEditionRequest(
|
||||
String name,
|
||||
List<UUID> subCategoryIds
|
||||
) {}
|
||||
@@ -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.CategoryEditionException;
|
||||
import org.codiki.domain.category.exception.CategoryNotFoundException;
|
||||
import org.codiki.domain.exception.LoginFailureException;
|
||||
import org.codiki.domain.exception.RefreshTokenDoesNotExistException;
|
||||
@@ -66,4 +67,10 @@ public class GlobalControllerExceptionHandler {
|
||||
public void handlePublicationUpdateForbiddenException() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@ResponseStatus(BAD_REQUEST)
|
||||
@ExceptionHandler(CategoryEditionException.class)
|
||||
public void handleCategoryEditionException() {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ public class SecurityConfiguration {
|
||||
"/api/users/login",
|
||||
"/api/users/refresh-token"
|
||||
).permitAll()
|
||||
.requestMatchers(
|
||||
POST,
|
||||
"/api/categories"
|
||||
).hasRole("ADMIN")
|
||||
.requestMatchers(OPTIONS).permitAll()
|
||||
.anyRequest().authenticated()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user