From a93d569783324a07bd85b3831c632ab335f77442 Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 25 Sep 2024 12:52:05 +0200
Subject: [PATCH] Rebase
---
.gitea/workflows/qs.yml | 100 ++++++++---------
GetBearerToken.http | 10 +-
requests/createProject.http | 28 ++---
.../GlobalExceptionHandler.java | 102 +++++++++---------
.../lf8_starter/project/GetProjectDto.java | 86 +++++++--------
.../lf8_starter/project/ProjectEntity.java | 86 +++++++--------
.../lf8_starter/project/ProjectMapper.java | 76 ++++++-------
.../lf8_starter/project/ProjectService.java | 32 +++---
.../project/dto/CreateProjectAction.java | 84 +++++++--------
.../project/dto/CreateProjectDto.java | 84 +++++++--------
10 files changed, 344 insertions(+), 344 deletions(-)
diff --git a/.gitea/workflows/qs.yml b/.gitea/workflows/qs.yml
index d962ad2..d41bf56 100644
--- a/.gitea/workflows/qs.yml
+++ b/.gitea/workflows/qs.yml
@@ -1,50 +1,50 @@
-name: "Quality Check"
-
-on:
- - pull_request
-
-jobs:
- test:
- name: "Tests"
- runs-on: "ubuntu-latest"
- container:
- image: "cimg/openjdk:21.0.2-node"
- steps:
- - name: "Checkout"
- uses: actions/checkout@v3
- - uses: actions/cache@v4
- with:
- path: |
- ~/.gradle/caches
- ~/.gradle/wrapper
- key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
- restore-keys: |
- ${{ runner.os }}-gradle-
- - name: "Prepare Gradle"
- run: gradle clean
- - name: "Check"
- run: gradle testClasses
- - name: "Stop Gradle"
- run: gradle --stop
- checkstyle:
- name: "Checkstyle Main"
- runs-on: "ubuntu-latest"
- container:
- image: "cimg/openjdk:21.0.2-node"
- steps:
- - name: "Checkout"
- uses: actions/checkout@v3
- - uses: actions/cache@v4
- with:
- path: |
- ~/.gradle/caches
- ~/.gradle/wrapper
- key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
- restore-keys: |
- ${{ runner.os }}-gradle-
- - name: "Prepare Gradle"
- run: gradle clean
- - name: "Check"
- run: gradle check
- - name: "Stop Gradle"
- run: gradle --stop
+name: "Quality Check"
+
+on:
+ - pull_request
+
+jobs:
+ test:
+ name: "Tests"
+ runs-on: "ubuntu-latest"
+ container:
+ image: "cimg/openjdk:21.0.2-node"
+ steps:
+ - name: "Checkout"
+ uses: actions/checkout@v3
+ - uses: actions/cache@v4
+ with:
+ path: |
+ ~/.gradle/caches
+ ~/.gradle/wrapper
+ key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
+ restore-keys: |
+ ${{ runner.os }}-gradle-
+ - name: "Prepare Gradle"
+ run: gradle clean
+ - name: "Check"
+ run: gradle testClasses
+ - name: "Stop Gradle"
+ run: gradle --stop
+ checkstyle:
+ name: "Checkstyle Main"
+ runs-on: "ubuntu-latest"
+ container:
+ image: "cimg/openjdk:21.0.2-node"
+ steps:
+ - name: "Checkout"
+ uses: actions/checkout@v3
+ - uses: actions/cache@v4
+ with:
+ path: |
+ ~/.gradle/caches
+ ~/.gradle/wrapper
+ key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
+ restore-keys: |
+ ${{ runner.os }}-gradle-
+ - name: "Prepare Gradle"
+ run: gradle clean
+ - name: "Check"
+ run: gradle check
+ - name: "Stop Gradle"
+ run: gradle --stop
diff --git a/GetBearerToken.http b/GetBearerToken.http
index f5209ca..abf7e94 100644
--- a/GetBearerToken.http
+++ b/GetBearerToken.http
@@ -1,6 +1,6 @@
-POST https://keycloak.szut.dev/auth/realms/szut/protocol/openid-connect/token
-Content-Type: application/x-www-form-urlencoded
-
-grant_type=password&client_id=employee-management-service&username=user&password=test
-
+POST https://keycloak.szut.dev/auth/realms/szut/protocol/openid-connect/token
+Content-Type: application/x-www-form-urlencoded
+
+grant_type=password&client_id=employee-management-service&username=user&password=test
+
> {% client.global.set("auth_token", response.body.access_token); %}
\ No newline at end of file
diff --git a/requests/createProject.http b/requests/createProject.http
index add2394..6854828 100644
--- a/requests/createProject.http
+++ b/requests/createProject.http
@@ -1,15 +1,15 @@
-### 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"
+### 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"
}
\ No newline at end of file
diff --git a/src/main/java/de/szut/lf8_starter/exceptionHandling/GlobalExceptionHandler.java b/src/main/java/de/szut/lf8_starter/exceptionHandling/GlobalExceptionHandler.java
index 68a15a7..92ba734 100644
--- a/src/main/java/de/szut/lf8_starter/exceptionHandling/GlobalExceptionHandler.java
+++ b/src/main/java/de/szut/lf8_starter/exceptionHandling/GlobalExceptionHandler.java
@@ -1,51 +1,51 @@
-package de.szut.lf8_starter.exceptionHandling;
-
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-import jakarta.validation.ConstraintViolationException;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.MethodArgumentNotValidException;
-import org.springframework.web.bind.annotation.ControllerAdvice;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.context.request.WebRequest;
-
-import java.util.Date;
-
-@ControllerAdvice
-@ApiResponses(value = {
- @ApiResponse(responseCode = "500", description = "invalid JSON posted",
- content = @Content)
-})
-public class GlobalExceptionHandler {
-
- @ExceptionHandler(ResourceNotFoundException.class)
- public ResponseEntity> handleHelloEntityNotFoundException(ResourceNotFoundException ex, WebRequest request) {
- ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
- return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND);
- }
-
- @ExceptionHandler(Exception.class)
- public ResponseEntity 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 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 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);
- }
-}
+package de.szut.lf8_starter.exceptionHandling;
+
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import jakarta.validation.ConstraintViolationException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.context.request.WebRequest;
+
+import java.util.Date;
+
+@ControllerAdvice
+@ApiResponses(value = {
+ @ApiResponse(responseCode = "500", description = "invalid JSON posted",
+ content = @Content)
+})
+public class GlobalExceptionHandler {
+
+ @ExceptionHandler(ResourceNotFoundException.class)
+ public ResponseEntity> handleHelloEntityNotFoundException(ResourceNotFoundException ex, WebRequest request) {
+ ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
+ return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND);
+ }
+
+ @ExceptionHandler(Exception.class)
+ public ResponseEntity 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 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 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);
+ }
+}
diff --git a/src/main/java/de/szut/lf8_starter/project/GetProjectDto.java b/src/main/java/de/szut/lf8_starter/project/GetProjectDto.java
index 86ce087..75b8c60 100644
--- a/src/main/java/de/szut/lf8_starter/project/GetProjectDto.java
+++ b/src/main/java/de/szut/lf8_starter/project/GetProjectDto.java
@@ -1,43 +1,43 @@
-package de.szut.lf8_starter.project;
-
-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 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;
-}
+package de.szut.lf8_starter.project;
+
+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 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;
+}
diff --git a/src/main/java/de/szut/lf8_starter/project/ProjectEntity.java b/src/main/java/de/szut/lf8_starter/project/ProjectEntity.java
index d9c35a1..82563fe 100644
--- a/src/main/java/de/szut/lf8_starter/project/ProjectEntity.java
+++ b/src/main/java/de/szut/lf8_starter/project/ProjectEntity.java
@@ -1,43 +1,43 @@
-package de.szut.lf8_starter.project;
-
-import jakarta.persistence.*;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import org.springframework.data.annotation.CreatedDate;
-
-import java.time.LocalDate;
-import java.util.List;
-
-@NoArgsConstructor
-@AllArgsConstructor
-@Getter
-@Setter
-@Entity
-@Table(name = "projects")
-public class ProjectEntity {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private long id;
-
- private String name;
-
- private long leadingEmployee;
-
- @ElementCollection
- private List employees;
-
- private long contractor;
-
- private String contractorName;
-
- private String comment;
-
- @CreatedDate
- private LocalDate startDate;
-
- private LocalDate plannedEndDate;
-
- private LocalDate endDate;
-}
+package de.szut.lf8_starter.project;
+
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.springframework.data.annotation.CreatedDate;
+
+import java.time.LocalDate;
+import java.util.List;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Getter
+@Setter
+@Entity
+@Table(name = "projects")
+public class ProjectEntity {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private long id;
+
+ private String name;
+
+ private long leadingEmployee;
+
+ @ElementCollection
+ private List employees;
+
+ private long contractor;
+
+ private String contractorName;
+
+ private String comment;
+
+ @CreatedDate
+ private LocalDate startDate;
+
+ private LocalDate plannedEndDate;
+
+ private LocalDate endDate;
+}
diff --git a/src/main/java/de/szut/lf8_starter/project/ProjectMapper.java b/src/main/java/de/szut/lf8_starter/project/ProjectMapper.java
index 363ea64..c70276d 100644
--- a/src/main/java/de/szut/lf8_starter/project/ProjectMapper.java
+++ b/src/main/java/de/szut/lf8_starter/project/ProjectMapper.java
@@ -1,39 +1,39 @@
-package de.szut.lf8_starter.project;
-
-import de.szut.lf8_starter.project.dto.CreateProjectDto;
-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;
- }
+package de.szut.lf8_starter.project;
+
+import de.szut.lf8_starter.project.dto.CreateProjectDto;
+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;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/de/szut/lf8_starter/project/ProjectService.java b/src/main/java/de/szut/lf8_starter/project/ProjectService.java
index a12228f..2f30d54 100644
--- a/src/main/java/de/szut/lf8_starter/project/ProjectService.java
+++ b/src/main/java/de/szut/lf8_starter/project/ProjectService.java
@@ -1,16 +1,16 @@
-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);
- }
-}
+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);
+ }
+}
diff --git a/src/main/java/de/szut/lf8_starter/project/dto/CreateProjectAction.java b/src/main/java/de/szut/lf8_starter/project/dto/CreateProjectAction.java
index f1c6cdc..511c5ee 100644
--- a/src/main/java/de/szut/lf8_starter/project/dto/CreateProjectAction.java
+++ b/src/main/java/de/szut/lf8_starter/project/dto/CreateProjectAction.java
@@ -1,42 +1,42 @@
-package de.szut.lf8_starter.project.dto;
-
-import de.szut.lf8_starter.project.GetProjectDto;
-import de.szut.lf8_starter.project.ProjectEntity;
-import de.szut.lf8_starter.project.ProjectMapper;
-import de.szut.lf8_starter.project.ProjectService;
-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);
- }
-}
+package de.szut.lf8_starter.project.dto;
+
+import de.szut.lf8_starter.project.GetProjectDto;
+import de.szut.lf8_starter.project.ProjectEntity;
+import de.szut.lf8_starter.project.ProjectMapper;
+import de.szut.lf8_starter.project.ProjectService;
+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);
+ }
+}
diff --git a/src/main/java/de/szut/lf8_starter/project/dto/CreateProjectDto.java b/src/main/java/de/szut/lf8_starter/project/dto/CreateProjectDto.java
index 4c6ab0d..f27e7f4 100644
--- a/src/main/java/de/szut/lf8_starter/project/dto/CreateProjectDto.java
+++ b/src/main/java/de/szut/lf8_starter/project/dto/CreateProjectDto.java
@@ -1,42 +1,42 @@
-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 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;
-}
+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 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;
+}