content: package io.reflectoring.coderadar.rest.module;
  
  import io.reflectoring.coderadar.projectadministration.ModulePathInvalidException;
  import io.reflectoring.coderadar.projectadministration.port.driver.module.create.CreateModuleCommand;
  import io.reflectoring.coderadar.projectadministration.port.driver.module.create.CreateModuleUseCase;
  import io.reflectoring.coderadar.rest.AbstractBaseController;
  import io.reflectoring.coderadar.rest.domain.ErrorMessageResponse;
  import io.reflectoring.coderadar.rest.domain.IdResponse;
  import io.reflectoring.coderadar.useradministration.service.security.AuthenticationService;
  import lombok.RequiredArgsConstructor;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.MediaType;
  import org.springframework.http.ResponseEntity;
  import org.springframework.validation.annotation.Validated;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RestController;
  
  @RestController
  @RequiredArgsConstructor
  public class CreateModuleController implements AbstractBaseController {
    private final CreateModuleUseCase createModuleUseCase;
    private final AuthenticationService authenticationService;
  
    @PostMapping(
        path = "/projects/{projectId}/modules",
        consumes = MediaType.APPLICATION_JSON_VALUE,
        produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Object> createModule(
        @RequestBody @Validated CreateModuleCommand command,
        @PathVariable(name = "projectId") long projectId) {
      authenticationService.authenticateAdmin(projectId);
      try {
        return new ResponseEntity<>(
            new IdResponse(createModuleUseCase.createModule(command, projectId)), HttpStatus.CREATED);
      } catch (ModulePathInvalidException e) {
        return new ResponseEntity<>(new ErrorMessageResponse(e.getMessage()), HttpStatus.BAD_REQUEST);
      }
    }
  }
  