Compare commits

..

3 Commits

Author SHA1 Message Date
86cc38d3cb Merge branch 'main' into feature/releases
All checks were successful
Quality Check / Tests (pull_request) Successful in 53s
Quality Check / Checkstyle Main (pull_request) Successful in 48s
2024-09-25 11:53:01 +00:00
25d7d30a7d feat(project): Get all projects (SCRUM-15) (!10)
SCRUM-15 #close

Reviewed-on: #10
Reviewed-by: Phan Huy Tran <ptran@noreply.localhost>
2024-09-25 11:38:31 +00:00
1a98d4f8d2 chore(deps): update actions/checkout action to v4 (!12)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/checkout](https://github.com/actions/checkout) | action | major | `v3` -> `v4` |

---

### Release Notes

<details>
<summary>actions/checkout (actions/checkout)</summary>

### [`v4`](https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v417)

[Compare Source](https://github.com/actions/checkout/compare/v3...v4)

-   Bump the minor-npm-dependencies group across 1 directory with 4 updates by [@&#8203;dependabot](https://github.com/dependabot) in https://github.com/actions/checkout/pull/1739
-   Bump actions/checkout from 3 to 4 by [@&#8203;dependabot](https://github.com/dependabot) in https://github.com/actions/checkout/pull/1697
-   Check out other refs/\* by commit by [@&#8203;orhantoy](https://github.com/orhantoy) in https://github.com/actions/checkout/pull/1774
-   Pin actions/checkout's own workflows to a known, good, stable version. by [@&#8203;jww3](https://github.com/jww3) in https://github.com/actions/checkout/pull/1776

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC45NC4zIiwidXBkYXRlZEluVmVyIjoiMzguOTQuMyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: Jan Gleytenhoover <krisellp9@gmail.com>
Reviewed-on: #12
Reviewed-by: Jan Gleytenhoover <krisellp9@gmail.com>
Co-authored-by: Renovate <renovate@kjan.de>
Co-committed-by: Renovate <renovate@kjan.de>
2024-09-25 11:36:28 +00:00
9 changed files with 151 additions and 4 deletions

@ -11,7 +11,7 @@ jobs:
image: "cimg/openjdk:21.0.2-node" image: "cimg/openjdk:21.0.2-node"
steps: steps:
- name: "Checkout" - name: "Checkout"
uses: actions/checkout@v3 uses: actions/checkout@v4
- uses: actions/cache@v4 - uses: actions/cache@v4
with: with:
path: | path: |
@ -23,7 +23,7 @@ jobs:
- name: "Prepare Gradle" - name: "Prepare Gradle"
run: gradle clean run: gradle clean
- name: "Check" - name: "Check"
run: gradle testClasses run: gradle test
- name: "Stop Gradle" - name: "Stop Gradle"
run: gradle --stop run: gradle --stop
checkstyle: checkstyle:
@ -33,7 +33,7 @@ jobs:
image: "cimg/openjdk:21.0.2-node" image: "cimg/openjdk:21.0.2-node"
steps: steps:
- name: "Checkout" - name: "Checkout"
uses: actions/checkout@v3 uses: actions/checkout@v4
- uses: actions/cache@v4 - uses: actions/cache@v4
with: with:
path: | path: |
@ -45,6 +45,6 @@ jobs:
- name: "Prepare Gradle" - name: "Prepare Gradle"
run: gradle clean run: gradle clean
- name: "Check" - name: "Check"
run: gradle check run: gradle checkstyleMain --scan
- name: "Stop Gradle" - name: "Stop Gradle"
run: gradle --stop run: gradle --stop

@ -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) { public GetProjectDto mapToGetDto(ProjectEntity projectEntity) {
GetProjectDto getProjectDto = new GetProjectDto(); GetProjectDto getProjectDto = new GetProjectDto();
getProjectDto.setId(projectEntity.getId());
getProjectDto.setName(projectEntity.getName()); getProjectDto.setName(projectEntity.getName());
getProjectDto.setComment(projectEntity.getComment()); getProjectDto.setComment(projectEntity.getComment());
getProjectDto.setLeadingEmployee(projectEntity.getLeadingEmployee()); getProjectDto.setLeadingEmployee(projectEntity.getLeadingEmployee());

@ -1,6 +1,8 @@
package de.szut.lf8_starter.project; package de.szut.lf8_starter.project;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ProjectRepository extends JpaRepository<ProjectEntity, Long> { public interface ProjectRepository extends JpaRepository<ProjectEntity, Long> {
} }

@ -2,6 +2,8 @@ package de.szut.lf8_starter.project;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public class ProjectService { public class ProjectService {
private final ProjectRepository projectRepository; private final ProjectRepository projectRepository;
@ -13,4 +15,8 @@ public class ProjectService {
public ProjectEntity create(ProjectEntity projectEntity) { public ProjectEntity create(ProjectEntity projectEntity) {
return this.projectRepository.save(projectEntity); return this.projectRepository.save(projectEntity);
} }
public List<ProjectEntity> readAll() {
return this.projectRepository.findAll();
}
} }

@ -12,6 +12,8 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
public class GetProjectDto { public class GetProjectDto {
private long id;
@NotBlank @NotBlank
private String name; private String name;

@ -5,6 +5,7 @@ import java.util.stream.Collectors;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer; import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;

@ -0,0 +1,37 @@
package de.szut.lf8_starter.integration.project;
import de.szut.lf8_starter.project.ProjectEntity;
import de.szut.lf8_starter.project.ProjectRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.web.servlet.MockMvc;
import java.time.LocalDate;
import java.util.List;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc(addFilters = true)
public class ProjectFindAllNotAuthenticated {
@Autowired
private ProjectRepository projectRepository;
@Autowired
private MockMvc mockMvc;
@Autowired
private TestRestTemplate restTemplate;
@Test
void findAllProjects() throws Exception {
this.mockMvc.perform(get("/projects"))
.andExpect(status().isUnauthorized());
}
}

@ -0,0 +1,60 @@
package de.szut.lf8_starter.integration.project;
import de.szut.lf8_starter.project.ProjectEntity;
import de.szut.lf8_starter.project.ProjectRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.web.servlet.MockMvc;
import java.time.LocalDate;
import java.util.List;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc(addFilters = false)
public class ProjectFindAllSuccess {
@Autowired
private ProjectRepository projectRepository;
@Autowired
private MockMvc mockMvc;
@Autowired
private TestRestTemplate restTemplate;
@Test
void findAllProjects() throws Exception {
var project = new ProjectEntity();
project.setId(1);
project.setComment("comment");
project.setContractor(1);
project.setContractorName("contractorName");
project.setEndDate(LocalDate.of(2024, 1, 1));
project.setLeadingEmployee(1);
project.setName("name");
project.setStartDate(LocalDate.of(2021, 1, 1));
project.setEmployees(List.of(1L,2L,3L));
this.projectRepository.save(project);
this.mockMvc.perform(get("/projects"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(1)))
.andExpect(jsonPath("$[0].id").value(1))
.andExpect(jsonPath("$[0].comment").value("comment"))
.andExpect(jsonPath("$[0].contractor").value(1))
.andExpect(jsonPath("$[0].contractorName").value("contractorName"))
.andExpect(jsonPath("$[0].endDate").value("01.01.2024"))
.andExpect(jsonPath("$[0].leadingEmployee").value(1))
.andExpect(jsonPath("$[0].name").value("name"))
.andExpect(jsonPath("$[0].startDate").value("01.01.2021"))
.andExpect(jsonPath("$[0].employees").isArray())
.andExpect(jsonPath("$[0].employees", hasSize(3)));
}
}