commit 0dda356710fd7c40c85e1cd3bf3f827296ee8694
Author: stepanekp <1stepanekpetr@gmail.com>
Date:   Sat Nov 4 21:24:33 2023 +0100

    https://kivprogrammers.atlassian.net/browse/TSP2-48 Načítání seznamu projektů z api, načítání osob a identit z api, vykreslení

diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/PersonController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/PersonController.java
index ec3c904..4d20038 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/PersonController.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/PersonController.java
@@ -25,7 +25,7 @@ import java.util.Objects;
 /**
  * This class contains all endpoints of person.html
  */
-@Controller
+//@Controller
 public class PersonController {
 
     private final Logger LOGGER = LoggerFactory.getLogger(PersonController.class);
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/PersonController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/PersonController.java
new file mode 100644
index 0000000..b5e5e90
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/PersonController.java
@@ -0,0 +1,54 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller.management;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Person;
+import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PersonDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PersonToDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class contains all endpoints of management/persons
+ */
+@Controller
+@RequestMapping("v2/management")
+public class PersonController {
+
+    @Autowired
+    private ProjectService projectService;
+
+    @PostMapping("/personsFromProject")
+    public ResponseEntity<String> getPersonsFromProject(@RequestBody Map<String, String> requestData) {
+        long ProjectId = Long.parseLong(requestData.get("projectId").toString());
+        ObjectMapper objectMapper = new ObjectMapper();
+
+        Project project = projectService.getProjectById(ProjectId);
+
+        if (project == null) {
+            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Project not found");
+        }
+        List<Person> persons = project.getPeople();
+        List<PersonDto> personDtos = new PersonToDto().convert(persons);
+        Collections.sort(personDtos, Comparator.comparing(PersonDto::getName, String.CASE_INSENSITIVE_ORDER));
+
+        try {
+            String json = objectMapper.writeValueAsString(personDtos);
+            return ResponseEntity.status(persons != null ? HttpStatus.OK : HttpStatus.NO_CONTENT).body(json);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to serialize data to JSON");
+        }
+    }
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ProjectController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ProjectController.java
index 61759c5..f848c70 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ProjectController.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ProjectController.java
@@ -21,7 +21,7 @@ import java.util.*;
 
 
 /**
- * This class contains all endpoints of projects.html
+ * This class contains all endpoints connected to Projects
  */
 @Controller
 @RequestMapping("v2/management")
@@ -30,8 +30,15 @@ public class ProjectController {
     @Autowired
     private ProjectService projectService;
 
-    @GetMapping("/projects")
-    public ResponseEntity<String> getProjectsData() {
+    @GetMapping("/projectsList")
+    public ResponseEntity<String> getProjectsList() {
+        ProjectToDto projectToDto = new ProjectToDto();
+        List<ProjectDto> projects = projectToDto.convert(projectService.getAllProjects());
+        return ResponseEntity.status(projects.size() > 0 ? HttpStatus.OK : HttpStatus.NO_CONTENT).body(new Gson().toJson(projects));
+    }
+
+    @GetMapping("/projectsHierarchy")
+    public ResponseEntity<String> getProjectsHierarchy() {
         ProjectToDto projectToDto = new ProjectToDto();
         List<Node> parents = new ArrayList<>();
         List<ProjectDto> parentProjects = projectToDto.convert(projectService.getParentProjects());
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/IdentityDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/IdentityDto.java
new file mode 100644
index 0000000..2f904eb
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/IdentityDto.java
@@ -0,0 +1,23 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class IdentityDto {
+
+    private Long id;
+    private String name;
+
+    private String description;
+
+    private String email;
+
+
+    public static IdentityDtoBuilder builder() {return new IdentityDtoBuilder();}
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/PersonDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/PersonDto.java
new file mode 100644
index 0000000..b76c877
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/PersonDto.java
@@ -0,0 +1,22 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class PersonDto {
+
+    private Long id;
+    private String name;
+
+    private List<IdentityDto> identities;
+
+    public static PersonDtoBuilder builder() {return new PersonDtoBuilder();}
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/IdentityToDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/IdentityToDto.java
new file mode 100644
index 0000000..c5ede9b
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/IdentityToDto.java
@@ -0,0 +1,36 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters;
+
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Identity;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IdentityDto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class IdentityToDto implements ClassToDto<Identity, IdentityDto> {
+
+    @Override
+    public IdentityDto convert(Identity source) {
+        if (source == null) {
+            return null;
+        }
+
+        return IdentityDto.builder()
+                .id(source.getId())
+                .name(source.getName())
+                .description(source.getDescription())
+                .email(source.getEmail())
+                .build();
+    }
+
+    @Override
+    public List<IdentityDto> convert(List<Identity> source) {
+        List<IdentityDto> convertedList = new ArrayList<>();
+
+        if(source == null){
+            return convertedList;
+        }
+        source.stream().forEach(sourceItem->convertedList.add(this.convert(sourceItem)));
+        return convertedList;
+    }
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/PersonToDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/PersonToDto.java
new file mode 100644
index 0000000..72a9569
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/PersonToDto.java
@@ -0,0 +1,37 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Person;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IdentityDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PersonDto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PersonToDto implements ClassToDto<Person, PersonDto> {
+    @Override
+    public PersonDto convert(Person source) {
+        if (source == null) {
+            return null;
+        }
+
+        IdentityToDto identityToDto = new IdentityToDto();
+        List<IdentityDto> identityDtos = identityToDto.convert(source.getIdentities());
+
+        return PersonDto.builder()
+                .id(source.getId())
+                .name(source.getName())
+                .identities(identityDtos)
+                .build();
+    }
+
+    @Override
+    public List<PersonDto> convert(List<Person> source) {
+        List<PersonDto> convertedList = new ArrayList<>();
+
+        if(source == null){
+            return convertedList;
+        }
+        source.stream().forEach(sourceItem->convertedList.add(this.convert(sourceItem)));
+        return convertedList;
+    }
+}
