commit cf25eed32682b4be144e5a020a95f61257a9ada1
Author: Hrabikv <75799502+Hrabikv@users.noreply.github.com>
Date:   Tue Nov 14 20:25:44 2023 +0100

    https://kivprogrammers.atlassian.net/browse/TSP2-50 přijímání dat z frontendu a příprava endpointů

diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/IterationAndPhasesController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/IterationAndPhasesController.java
index b4fd80b..234ecad 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/IterationAndPhasesController.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/IterationAndPhasesController.java
@@ -1,29 +1,15 @@
 package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller.management;
 
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import cz.zcu.fav.kiv.antipatterndetectionapp.Constants;
 import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
-import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Iteration;
-import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Person;
-import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Phase;
 import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService;
-import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.PersonService;
-import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.*;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationAndPhasesToDto;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationToDto;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PersonToDto;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PhaseToDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.managment.IterationsAndPhasesService;
 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.ui.Model;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
-import javax.servlet.http.HttpSession;
 import java.util.*;
 
 /**
@@ -33,13 +19,15 @@ import java.util.*;
 @RequestMapping("v2/management")
 public class IterationAndPhasesController {
 
+    @Autowired
+    private IterationsAndPhasesService iterationsAndPhasesService;
+
     @Autowired
     private ProjectService projectService;
 
     @GetMapping("/segment-iteration-phase")
     public ResponseEntity<String> getIterationAndPhasesFromProject(@RequestParam Map<String, String> requestData) {
         long ProjectId = Long.parseLong(requestData.get("projectId").toString());
-        ObjectMapper objectMapper = new ObjectMapper();
 
         Project project = projectService.getProjectById(ProjectId);
 
@@ -47,25 +35,25 @@ public class IterationAndPhasesController {
             return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Project not found");
         }
 
-        List<Iteration> iterations = project.getIterations();
-        List<Phase> phases = project.getPhases();
-
-        List<IterationDto> iterationDtos = new IterationToDto().convert(iterations);
-        List<PhaseDto> phasesDtos = new PhaseToDto().convert(phases);
-
+        return iterationsAndPhasesService.getIterationAndPhases(project);
+    }
 
-        Collections.sort(iterationDtos, Comparator.comparing(IterationDto::getName, String.CASE_INSENSITIVE_ORDER));
-        Collections.sort(phasesDtos, Comparator.comparing(PhaseDto::getName, String.CASE_INSENSITIVE_ORDER));
+    @PostMapping("/changeIteration")
+    public ResponseEntity<String> changeIteration(@RequestBody Map<String, String[]> requestData) {
+        if (requestData.get("Ids").length == 0) {
+            return ResponseEntity.status(HttpStatus.NO_CONTENT).body("No Iterations send");
+        }
 
-        IterationAndPhasesDto iterationAndPhasesDto = new IterationAndPhasesToDto().convert(iterationDtos, phasesDtos);
+        return iterationsAndPhasesService.changeToPhase(requestData.get("Ids"));
+    }
 
-        try {
-            String json = objectMapper.writeValueAsString(iterationAndPhasesDto);
-            return ResponseEntity.status((iterations != null && phases != 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");
+    @PostMapping("/changePhase")
+    public ResponseEntity<String> changePhase(@RequestBody Map<String, String[]> requestData) {
+        if (requestData.get("Ids").length == 0) {
+            return ResponseEntity.status(HttpStatus.NO_CONTENT).body("No Phases send");
         }
+
+        return iterationsAndPhasesService.changeToIteration(requestData.get("Ids"));
     }
 
 }
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/managment/IterationsAndPhasesService.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/managment/IterationsAndPhasesService.java
new file mode 100644
index 0000000..eea7b9c
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/managment/IterationsAndPhasesService.java
@@ -0,0 +1,13 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.managment;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
+import org.springframework.http.ResponseEntity;
+
+public interface IterationsAndPhasesService {
+
+    public ResponseEntity<String> getIterationAndPhases(Project project);
+
+    public ResponseEntity<String> changeToPhase(String[] iterationsIds);
+
+    public ResponseEntity<String> changeToIteration(String[] phasesIds);
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/managment/IterationsAndPhasesServiceImpl.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/managment/IterationsAndPhasesServiceImpl.java
new file mode 100644
index 0000000..5451d80
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/managment/IterationsAndPhasesServiceImpl.java
@@ -0,0 +1,59 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.managment;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Iteration;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Phase;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationAndPhasesDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.IterationDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.PhaseDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationAndPhasesToDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.IterationToDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.PhaseToDto;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+@Service
+public class IterationsAndPhasesServiceImpl implements IterationsAndPhasesService {
+
+    @Override
+    public ResponseEntity<String> getIterationAndPhases(Project project) {
+        ObjectMapper objectMapper = new ObjectMapper();
+
+        List<Iteration> iterations = project.getIterations();
+        List<Phase> phases = project.getPhases();
+
+        List<IterationDto> iterationDtos = new IterationToDto().convert(iterations);
+        List<PhaseDto> phasesDtos = new PhaseToDto().convert(phases);
+
+
+        Collections.sort(iterationDtos, Comparator.comparing(IterationDto::getName, String.CASE_INSENSITIVE_ORDER));
+        Collections.sort(phasesDtos, Comparator.comparing(PhaseDto::getName, String.CASE_INSENSITIVE_ORDER));
+
+        IterationAndPhasesDto iterationAndPhasesDto = new IterationAndPhasesToDto().convert(iterationDtos, phasesDtos);
+
+        try {
+            String json = objectMapper.writeValueAsString(iterationAndPhasesDto);
+            return ResponseEntity.status((iterations != null && phases != 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");
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> changeToPhase(String[] iterationsIds) {
+        return null;
+    }
+
+    @Override
+    public ResponseEntity<String> changeToIteration(String[] phasesIds) {
+        return null;
+    }
+
+}
