SCRUM-15 #close Reviewed-on: #10 Reviewed-by: Phan Huy Tran <ptran@noreply.localhost>
This commit is contained in:
		
					parent
					
						
							
								1a98d4f8d2
							
						
					
				
			
			
				commit
				
					
						25d7d30a7d
					
				
			
		
					 9 changed files with 149 additions and 2 deletions
				
			
		|  | @ -0,0 +1,38 @@ | |||
| package de.szut.lf8_starter.project; | ||||
| 
 | ||||
| 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 org.springframework.web.bind.annotation.*; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| @RestController | ||||
| @RequestMapping(value = "projects") | ||||
| public class ProjectController { | ||||
|     private final ProjectService service; | ||||
|     private final ProjectMapper projectMapper; | ||||
|     public ProjectController(ProjectService service, ProjectMapper projectMapper) { | ||||
|         this.service = service; | ||||
|         this.projectMapper = projectMapper; | ||||
|     } | ||||
| 
 | ||||
|     @Operation(summary = "returns all projects") | ||||
|     @ApiResponses(value = { | ||||
|             @ApiResponse(responseCode = "200", description = "all projects", | ||||
|                     content = {@Content(mediaType = "application/json", | ||||
|                             schema = @Schema(implementation = GetProjectDto.class))}), | ||||
|             @ApiResponse(responseCode = "401", description = "not authorized", | ||||
|                     content = @Content)}) | ||||
|     @GetMapping | ||||
|     public List<GetProjectDto> findAll() { | ||||
|         return this.service | ||||
|                 .readAll() | ||||
|                 .stream() | ||||
|                 .map(this.projectMapper::mapToGetDto) | ||||
|                 .toList(); | ||||
|     } | ||||
| } | ||||
|  | @ -25,6 +25,7 @@ public class ProjectMapper { | |||
|     public GetProjectDto mapToGetDto(ProjectEntity projectEntity) { | ||||
|         GetProjectDto getProjectDto = new GetProjectDto(); | ||||
| 
 | ||||
|         getProjectDto.setId(projectEntity.getId()); | ||||
|         getProjectDto.setName(projectEntity.getName()); | ||||
|         getProjectDto.setComment(projectEntity.getComment()); | ||||
|         getProjectDto.setLeadingEmployee(projectEntity.getLeadingEmployee()); | ||||
|  |  | |||
|  | @ -1,6 +1,8 @@ | |||
| package de.szut.lf8_starter.project; | ||||
| 
 | ||||
| import org.springframework.data.jpa.repository.JpaRepository; | ||||
| import org.springframework.stereotype.Repository; | ||||
| 
 | ||||
| @Repository | ||||
| public interface ProjectRepository extends JpaRepository<ProjectEntity, Long> { | ||||
| } | ||||
|  |  | |||
|  | @ -2,6 +2,8 @@ package de.szut.lf8_starter.project; | |||
| 
 | ||||
| import org.springframework.stereotype.Service; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| @Service | ||||
| public class ProjectService { | ||||
|     private final ProjectRepository projectRepository; | ||||
|  | @ -13,4 +15,8 @@ public class ProjectService { | |||
|     public ProjectEntity create(ProjectEntity projectEntity) { | ||||
|         return this.projectRepository.save(projectEntity); | ||||
|     } | ||||
| 
 | ||||
|     public List<ProjectEntity> readAll() { | ||||
|         return this.projectRepository.findAll(); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -12,6 +12,8 @@ import java.util.List; | |||
| @Getter | ||||
| @Setter | ||||
| public class GetProjectDto { | ||||
|     private long id; | ||||
| 
 | ||||
|     @NotBlank | ||||
|     private String name; | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ import java.util.stream.Collectors; | |||
| 
 | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.context.annotation.Profile; | ||||
| import org.springframework.http.HttpMethod; | ||||
| import org.springframework.security.config.Customizer; | ||||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||||
|  |  | |||
		Reference in a new issue