Compare commits
No commits in common. "b8be4113d38757efab3b4a99aaf21011f67b4ab7" and "59a95fd4bb439ac8b60e5f223ea6836cc85d1d52" have entirely different histories.
b8be4113d3
...
59a95fd4bb
@ -2,5 +2,3 @@ POST https://keycloak.szut.dev/auth/realms/szut/protocol/openid-connect/token
|
|||||||
Content-Type: application/x-www-form-urlencoded
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
|
||||||
grant_type=password&client_id=employee-management-service&username=user&password=test
|
grant_type=password&client_id=employee-management-service&username=user&password=test
|
||||||
|
|
||||||
> {% client.global.set("auth_token", response.body.access_token); %}
|
|
@ -44,7 +44,6 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
|
||||||
compileOnly("org.projectlombok:lombok")
|
compileOnly("org.projectlombok:lombok")
|
||||||
annotationProcessor("org.projectlombok:lombok")
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
### GET request to example server
|
|
||||||
POST http://localhost:8080/projects
|
|
||||||
Authorization: Bearer {{auth_token}}
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"name": "name",
|
|
||||||
"leading_employee": 1,
|
|
||||||
"employees": [2, 3],
|
|
||||||
"contractor": 4,
|
|
||||||
"contractorName": "Peter File",
|
|
||||||
"comment": "goal of project",
|
|
||||||
"startDate": "01.01.2000",
|
|
||||||
"plannedEndDate": "01.01.2001"
|
|
||||||
}
|
|
@ -3,10 +3,8 @@ package de.szut.lf8_starter.exceptionHandling;
|
|||||||
import io.swagger.v3.oas.annotations.media.Content;
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||||
import jakarta.validation.ConstraintViolationException;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
import org.springframework.web.context.request.WebRequest;
|
||||||
@ -26,26 +24,5 @@ public class GlobalExceptionHandler {
|
|||||||
return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
|
||||||
public ResponseEntity<ErrorDetails> handleAllOtherExceptions(Exception ex, WebRequest request) {
|
|
||||||
ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getClass() + " " + ex.getMessage(), request.getDescription(false));
|
|
||||||
|
|
||||||
return new ResponseEntity<>(errorDetails, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
||||||
public ResponseEntity<ErrorDetails> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex, WebRequest request) {
|
|
||||||
ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
|
|
||||||
|
|
||||||
return new ResponseEntity<>(errorDetails, HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(ConstraintViolationException.class)
|
|
||||||
public ResponseEntity<ErrorDetails> handleConstraintViolationException(ConstraintViolationException ex, WebRequest request) {
|
|
||||||
String errorMessage = ex.getConstraintViolations().stream().findFirst().get().getMessage();
|
|
||||||
|
|
||||||
ErrorDetails errorDetails = new ErrorDetails(new Date(), errorMessage, request.getDescription(false));
|
|
||||||
|
|
||||||
return new ResponseEntity<>(errorDetails, HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
package de.szut.lf8_starter.project;
|
|
||||||
|
|
||||||
import de.szut.lf8_starter.project.dto.CreateProjectDto;
|
|
||||||
import de.szut.lf8_starter.project.dto.GetProjectDto;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Content;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
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.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(value = "/projects")
|
|
||||||
public class CreateProjectAction {
|
|
||||||
private final ProjectService projectService;
|
|
||||||
private final ProjectMapper projectMapper;
|
|
||||||
|
|
||||||
public CreateProjectAction(ProjectService projectService, ProjectMapper mappingService) {
|
|
||||||
this.projectService = projectService;
|
|
||||||
this.projectMapper = mappingService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "Creates a new Project")
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(responseCode = "201", description = "created project", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = GetProjectDto.class))}),
|
|
||||||
@ApiResponse(responseCode = "400", description = "invalid JSON posted", content = @Content),
|
|
||||||
@ApiResponse(responseCode = "401", description = "not authorized", content = @Content)})
|
|
||||||
@PostMapping
|
|
||||||
public GetProjectDto create(@RequestBody @Valid CreateProjectDto createProjectDto) {
|
|
||||||
ProjectEntity projectEntity = this.projectMapper.mapCreateDtoToEntity(createProjectDto);
|
|
||||||
|
|
||||||
projectEntity = this.projectService.create(projectEntity);
|
|
||||||
|
|
||||||
return this.projectMapper.mapToGetDto(projectEntity);
|
|
||||||
}
|
|
||||||
}
|
|
@ -37,7 +37,5 @@ public class ProjectEntity {
|
|||||||
@CreatedDate
|
@CreatedDate
|
||||||
private LocalDate startDate;
|
private LocalDate startDate;
|
||||||
|
|
||||||
private LocalDate plannedEndDate;
|
|
||||||
|
|
||||||
private LocalDate endDate;
|
private LocalDate endDate;
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
package de.szut.lf8_starter.project;
|
|
||||||
|
|
||||||
import de.szut.lf8_starter.project.dto.CreateProjectDto;
|
|
||||||
import de.szut.lf8_starter.project.dto.GetProjectDto;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ProjectMapper {
|
|
||||||
public ProjectEntity mapCreateDtoToEntity(CreateProjectDto createProjectDto) {
|
|
||||||
ProjectEntity projectEntity = new ProjectEntity();
|
|
||||||
|
|
||||||
projectEntity.setName(createProjectDto.getName());
|
|
||||||
projectEntity.setComment(createProjectDto.getComment());
|
|
||||||
projectEntity.setLeadingEmployee(createProjectDto.getLeadingEmployee());
|
|
||||||
projectEntity.setEmployees(createProjectDto.getEmployees());
|
|
||||||
projectEntity.setContractor(createProjectDto.getContractor());
|
|
||||||
projectEntity.setContractorName(createProjectDto.getContractorName());
|
|
||||||
projectEntity.setStartDate(createProjectDto.getStartDate());
|
|
||||||
projectEntity.setPlannedEndDate(createProjectDto.getPlannedEndDate());
|
|
||||||
projectEntity.setEndDate(createProjectDto.getEndDate());
|
|
||||||
|
|
||||||
return projectEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GetProjectDto mapToGetDto(ProjectEntity projectEntity) {
|
|
||||||
GetProjectDto getProjectDto = new GetProjectDto();
|
|
||||||
|
|
||||||
getProjectDto.setName(projectEntity.getName());
|
|
||||||
getProjectDto.setComment(projectEntity.getComment());
|
|
||||||
getProjectDto.setLeadingEmployee(projectEntity.getLeadingEmployee());
|
|
||||||
getProjectDto.setEmployees(projectEntity.getEmployees());
|
|
||||||
getProjectDto.setContractor(projectEntity.getContractor());
|
|
||||||
getProjectDto.setContractorName(projectEntity.getContractorName());
|
|
||||||
getProjectDto.setStartDate(projectEntity.getStartDate());
|
|
||||||
getProjectDto.setPlannedEndDate(projectEntity.getPlannedEndDate());
|
|
||||||
getProjectDto.setEndDate(projectEntity.getEndDate());
|
|
||||||
|
|
||||||
return getProjectDto;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package de.szut.lf8_starter.project;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ProjectService {
|
|
||||||
private final ProjectRepository projectRepository;
|
|
||||||
|
|
||||||
public ProjectService(ProjectRepository projectRepository) {
|
|
||||||
this.projectRepository = projectRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProjectEntity create(ProjectEntity projectEntity) {
|
|
||||||
return this.projectRepository.save(projectEntity);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package de.szut.lf8_starter.project.dto;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class CreateProjectDto {
|
|
||||||
@NotBlank
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private long leadingEmployee;
|
|
||||||
|
|
||||||
private List<Long> employees;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private long contractor;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String contractorName;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String comment;
|
|
||||||
|
|
||||||
@JsonFormat(pattern = "dd.MM.yyyy")
|
|
||||||
@NotNull
|
|
||||||
private LocalDate startDate;
|
|
||||||
|
|
||||||
@JsonFormat(pattern = "dd.MM.yyyy")
|
|
||||||
@NotNull
|
|
||||||
private LocalDate plannedEndDate;
|
|
||||||
|
|
||||||
@JsonFormat(pattern = "dd.MM.yyyy")
|
|
||||||
private LocalDate endDate;
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
package de.szut.lf8_starter.project.dto;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class GetProjectDto {
|
|
||||||
@NotBlank
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private long leadingEmployee;
|
|
||||||
|
|
||||||
private List<Long> employees;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private long contractor;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String contractorName;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String comment;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@JsonFormat(pattern = "dd.MM.yyyy")
|
|
||||||
private LocalDate startDate;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@JsonFormat(pattern = "dd.MM.yyyy")
|
|
||||||
private LocalDate plannedEndDate;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@JsonFormat(pattern = "dd.MM.yyyy")
|
|
||||||
private LocalDate endDate;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user