diff --git a/src/main/java/com/maradona/backend/controllers/api/EmployeeController.java b/src/main/java/com/maradona/backend/controllers/api/EmployeeController.java index ade2817..1d1855c 100644 --- a/src/main/java/com/maradona/backend/controllers/api/EmployeeController.java +++ b/src/main/java/com/maradona/backend/controllers/api/EmployeeController.java @@ -14,7 +14,8 @@ import org.springframework.web.bind.annotation.RestController; import com.maradona.backend.dto.SkillPrototype; import com.maradona.backend.entities.Employee; -import com.maradona.backend.services.EmployeeService; +import com.maradona.backend.services.actions.EmployeeActions; +import com.maradona.backend.services.details.EmployeeDetails; /** * Controller for handling employee related requests. @@ -36,7 +37,10 @@ import com.maradona.backend.services.EmployeeService; public class EmployeeController { @Autowired - private EmployeeService employeeService; + private EmployeeDetails employeeDetails; + + @Autowired + private EmployeeActions employeeActions; Long user = Long.valueOf(1); @@ -48,7 +52,7 @@ public class EmployeeController { */ @GetMapping({ "/", "" }) public ResponseEntity get() { - var employee = employeeService.getEmployeeByEid(user); + var employee = employeeDetails.getEmployeeByEid(user); return employee .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); @@ -63,7 +67,7 @@ public class EmployeeController { */ @GetMapping("/{eid}") public ResponseEntity get(@RequestParam Long eid) { - var employee = employeeService.getEmployeeByEid(eid); + var employee = employeeDetails.getEmployeeByEid(eid); return employee .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); @@ -77,7 +81,7 @@ public class EmployeeController { */ @GetMapping("/all") public ResponseEntity> getAll() { - return ResponseEntity.ok(employeeService.getAllEmployees()); + return ResponseEntity.ok(employeeDetails.getAllEmployees()); } /** @@ -91,7 +95,7 @@ public class EmployeeController { */ @GetMapping("/from-skill") public ResponseEntity> getFromSkill(@RequestParam Long ssid, @RequestParam Integer level) { - return ResponseEntity.ok(employeeService.getEmployeesBySecondarySkill(ssid, level)); + return ResponseEntity.ok(employeeDetails.getEmployeesBySecondarySkill(ssid, level)); } /** @@ -105,7 +109,7 @@ public class EmployeeController { */ @PostMapping("/skill/protoype") public ResponseEntity postSkillProtoype(@RequestBody SkillPrototype skillPrototype) { - employeeService.addSecondarySkillToEmployee(user, skillPrototype); + employeeActions.addSecondarySkillToEmployee(user, skillPrototype); return ResponseEntity.status(HttpStatus.CREATED).build(); } @@ -121,7 +125,7 @@ public class EmployeeController { */ @PutMapping("/skill/level") public ResponseEntity putSkillLevel(@RequestParam Long ssid, @RequestParam Integer level) { - employeeService.updateSecondarySkillLevel(user, ssid, level); + employeeActions.updateSecondarySkillLevel(user, ssid, level); return ResponseEntity.ok().build(); } @@ -135,7 +139,7 @@ public class EmployeeController { */ @DeleteMapping("/skill") public ResponseEntity delete(@RequestParam Long ssid) { - employeeService.deleteSecondarySkillFromEmployee(user, ssid); + employeeActions.deleteSecondarySkillFromEmployee(user, ssid); return ResponseEntity.noContent().build(); } } \ No newline at end of file diff --git a/src/main/java/com/maradona/backend/controllers/api/FormOfAdressController.java b/src/main/java/com/maradona/backend/controllers/api/FormOfAdressController.java index feffeef..d23f04f 100644 --- a/src/main/java/com/maradona/backend/controllers/api/FormOfAdressController.java +++ b/src/main/java/com/maradona/backend/controllers/api/FormOfAdressController.java @@ -6,7 +6,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.maradona.backend.entities.FormOfAddress; -import com.maradona.backend.services.FormOfAddressService; +import com.maradona.backend.services.actions.FormOfAddressActions; +import com.maradona.backend.services.details.FormOfAddressDetails; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -30,9 +31,11 @@ import org.springframework.web.bind.annotation.PutMapping; @RestController @RequestMapping("/api/form-of-adress") class FormOfAdressController { + @Autowired + private FormOfAddressDetails formOfAdressDetails; @Autowired - private FormOfAddressService formOfAdressService; + private FormOfAddressActions formOfAdressActions; /** * Returns the form of address with the given ID. @@ -43,7 +46,7 @@ class FormOfAdressController { */ @GetMapping({ "/", "" }) public ResponseEntity getFormOfAdress(@RequestParam Long fid) { - return formOfAdressService.getFormOfAddressByFid(fid) + return formOfAdressDetails.getFormOfAddressByFid(fid) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } @@ -56,7 +59,7 @@ class FormOfAdressController { */ @GetMapping("/all") public ResponseEntity> getAllFormOfAdresses() { - Iterable formOfAddresses = formOfAdressService.getAllFormOfAddresses(); + Iterable formOfAddresses = formOfAdressDetails.getAllFormOfAddresses(); return ResponseEntity.ok(formOfAddresses); } @@ -71,7 +74,7 @@ class FormOfAdressController { public ResponseEntity createFormOfAdress(@RequestBody String description) { var formOfAddress = new FormOfAddress(); formOfAddress.setDescription(description); - formOfAdressService.saveFormOfAddress(formOfAddress); + formOfAdressActions.saveFormOfAddress(formOfAddress); return ResponseEntity.ok().build(); } @@ -85,12 +88,12 @@ class FormOfAdressController { */ @PutMapping({ "/", "" }) public ResponseEntity updateFormOfAdress(@RequestParam Long fid, @RequestBody String description) { - var formOfAddress = formOfAdressService.getFormOfAddressByFid(fid).orElse(null); + var formOfAddress = formOfAdressDetails.getFormOfAddressByFid(fid).orElse(null); if (formOfAddress == null) { return ResponseEntity.notFound().build(); } formOfAddress.setDescription(description); - formOfAdressService.saveFormOfAddress(formOfAddress); + formOfAdressActions.saveFormOfAddress(formOfAddress); return ResponseEntity.ok().build(); } @@ -103,11 +106,11 @@ class FormOfAdressController { */ @DeleteMapping({ "/", "" }) public ResponseEntity deleteFormOfAdress(@RequestParam Long fid) { - var formOfAddress = formOfAdressService.getFormOfAddressByFid(fid).orElse(null); + var formOfAddress = formOfAdressDetails.getFormOfAddressByFid(fid).orElse(null); if (formOfAddress == null) { return ResponseEntity.notFound().build(); } - formOfAdressService.deleteFormOfAddress(fid); + formOfAdressActions.deleteFormOfAddress(fid); return ResponseEntity.ok().build(); } } \ No newline at end of file diff --git a/src/main/java/com/maradona/backend/controllers/api/PrimarySkillController.java b/src/main/java/com/maradona/backend/controllers/api/PrimarySkillController.java index ba6739d..5ea134c 100644 --- a/src/main/java/com/maradona/backend/controllers/api/PrimarySkillController.java +++ b/src/main/java/com/maradona/backend/controllers/api/PrimarySkillController.java @@ -14,8 +14,10 @@ import org.springframework.web.bind.annotation.RestController; import com.maradona.backend.entities.PrimarySkill; import com.maradona.backend.entities.SecondarySkill; -import com.maradona.backend.services.PrimarySkillService; -import com.maradona.backend.services.SecondarySkillService; +import com.maradona.backend.services.actions.PrimarySkillActions; +import com.maradona.backend.services.actions.SecondarySkillActions; +import com.maradona.backend.services.details.PrimarySkillDetails; +import com.maradona.backend.services.details.SecondarySkillDetails; /** * Controller for handling primary skill data. @@ -34,10 +36,16 @@ import com.maradona.backend.services.SecondarySkillService; public class PrimarySkillController { @Autowired - private PrimarySkillService primarySkillService; + private PrimarySkillDetails primarySkillDetails; @Autowired - private SecondarySkillService secondarySkillService; + private PrimarySkillActions primarySkillActions; + + @Autowired + private SecondarySkillDetails secondarySkillDetails; + + @Autowired + private SecondarySkillActions secondarySkillActions; /** * Returns a specific primary skill from the database. @@ -48,7 +56,7 @@ public class PrimarySkillController { */ @GetMapping({ "/", "" }) public ResponseEntity get(@RequestParam Long pid) { - return primarySkillService.getPrimarySkillByPsid(pid) + return primarySkillDetails.getPrimarySkillByPsid(pid) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } @@ -61,7 +69,7 @@ public class PrimarySkillController { */ @GetMapping("/all") public ResponseEntity> getAll() { - return ResponseEntity.ok(primarySkillService.getAllPrimarySkills()); + return ResponseEntity.ok(primarySkillDetails.getAllPrimarySkills()); } /** @@ -73,7 +81,7 @@ public class PrimarySkillController { */ @PostMapping({ "/", "" }) public ResponseEntity post(@RequestBody PrimarySkill primarySkill) { - PrimarySkill savedPrimarySkill = primarySkillService.savePrimarySkill(primarySkill); + PrimarySkill savedPrimarySkill = primarySkillActions.savePrimarySkill(primarySkill); return ResponseEntity.status(HttpStatus.CREATED).body(savedPrimarySkill); } @@ -86,7 +94,7 @@ public class PrimarySkillController { */ @PutMapping({ "/", "" }) public ResponseEntity put(@RequestBody PrimarySkill primarySkill) { - PrimarySkill updatedPrimarySkill = primarySkillService.savePrimarySkill(primarySkill); + PrimarySkill updatedPrimarySkill = primarySkillActions.savePrimarySkill(primarySkill); return ResponseEntity.ok(updatedPrimarySkill); } @@ -99,15 +107,15 @@ public class PrimarySkillController { */ @DeleteMapping({ "/", "" }) public ResponseEntity delete(@RequestParam Long pid) { - var primarySkill = primarySkillService.getPrimarySkillByPsid(pid); + var primarySkill = primarySkillDetails.getPrimarySkillByPsid(pid); if (primarySkill.isPresent()) { - var secondarySkills = secondarySkillService.getAllSecondarySkills(); + var secondarySkills = secondarySkillDetails.getAllSecondarySkills(); for (SecondarySkill secondarySkill : secondarySkills) { if (secondarySkill.getPrimarySkill().getPsid().equals(pid)) { - secondarySkillService.deleteSecondarySkill(secondarySkill.getSsid()); + secondarySkillActions.deleteSecondarySkill(secondarySkill.getSsid()); } } - primarySkillService.deletePrimarySkill(pid); + primarySkillActions.deletePrimarySkill(pid); return ResponseEntity.noContent().build(); } else { return ResponseEntity.notFound().build(); diff --git a/src/main/java/com/maradona/backend/controllers/api/ProjectController.java b/src/main/java/com/maradona/backend/controllers/api/ProjectController.java index 4d6823d..61f38f5 100644 --- a/src/main/java/com/maradona/backend/controllers/api/ProjectController.java +++ b/src/main/java/com/maradona/backend/controllers/api/ProjectController.java @@ -15,7 +15,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.maradona.backend.entities.Project; -import com.maradona.backend.services.ProjectService; +import com.maradona.backend.services.actions.ProjectActions; +import com.maradona.backend.services.details.ProjectDetails; /** * Controller for handling project data. @@ -29,14 +30,16 @@ import com.maradona.backend.services.ProjectService; * - DELETE /api/project * * @see com.maradona.backend.entities.Project - * @see com.maradona.backend.services.ProjectService + * @see com.maradona.backend.services.actions.ProjectActions */ @RestController @RequestMapping("/api/project") public class ProjectController { + @Autowired + private ProjectDetails projectDetails; @Autowired - private ProjectService projectService; + private ProjectActions projectActions; /** * Returns a specific project from the database. @@ -47,7 +50,7 @@ public class ProjectController { */ @GetMapping({ "/", "" }) public ResponseEntity get(@RequestParam Long psid) { - Optional project = projectService.getProjectByPid(psid); + Optional project = projectDetails.getProjectByPid(psid); return project.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); } @@ -59,7 +62,7 @@ public class ProjectController { */ @GetMapping("/all") public ResponseEntity> getAll() { - return ResponseEntity.ok(projectService.getAllProjects()); + return ResponseEntity.ok(projectDetails.getAllProjects()); } /** @@ -71,7 +74,7 @@ public class ProjectController { */ @GetMapping("/from-employee") public ResponseEntity> getFromUser(@RequestParam Long eid) { - return ResponseEntity.ok(projectService.getProjectsByEid(eid)); + return ResponseEntity.ok(projectDetails.getProjectsByEid(eid)); } /** @@ -83,7 +86,7 @@ public class ProjectController { */ @PostMapping({ "/", "" }) public ResponseEntity post(@RequestBody Project project) { - Project savedProject = projectService.saveProject(project); + Project savedProject = projectActions.saveProject(project); return ResponseEntity.status(HttpStatus.CREATED).body(savedProject); } @@ -96,7 +99,7 @@ public class ProjectController { */ @PutMapping({ "/", "" }) public ResponseEntity put(@RequestBody Project project) { - Project updatedProject = projectService.saveProject(project); + Project updatedProject = projectActions.saveProject(project); return ResponseEntity.ok(updatedProject); } @@ -109,7 +112,7 @@ public class ProjectController { */ @DeleteMapping({ "/", "" }) public ResponseEntity delete(@RequestParam Long pid) { - projectService.deleteProject(pid); + projectActions.deleteProject(pid); return ResponseEntity.noContent().build(); } } \ No newline at end of file diff --git a/src/main/java/com/maradona/backend/controllers/api/SecondarySkillController.java b/src/main/java/com/maradona/backend/controllers/api/SecondarySkillController.java index 26985f6..bc7ab23 100644 --- a/src/main/java/com/maradona/backend/controllers/api/SecondarySkillController.java +++ b/src/main/java/com/maradona/backend/controllers/api/SecondarySkillController.java @@ -15,7 +15,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.maradona.backend.entities.SecondarySkill; -import com.maradona.backend.services.SecondarySkillService; +import com.maradona.backend.services.actions.SecondarySkillActions; +import com.maradona.backend.services.details.SecondarySkillDetails; /** * Controller for handling secondary skill data. @@ -35,7 +36,10 @@ import com.maradona.backend.services.SecondarySkillService; public class SecondarySkillController { @Autowired - private SecondarySkillService secondarySkillService; + private SecondarySkillDetails secondarySkillDetails; + + @Autowired + private SecondarySkillActions secondarySkillActions; /** * Returns a specific secondary skill from the database. @@ -46,7 +50,7 @@ public class SecondarySkillController { */ @GetMapping({ "/", "" }) public ResponseEntity get(@RequestParam Long ssid) { - Optional secondarySkill = secondarySkillService.getSecondarySkillBySsid(ssid); + Optional secondarySkill = secondarySkillDetails.getSecondarySkillBySsid(ssid); return secondarySkill.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); } @@ -58,7 +62,7 @@ public class SecondarySkillController { */ @GetMapping("/all") public ResponseEntity> getAll() { - return ResponseEntity.ok(secondarySkillService.getAllSecondarySkills()); + return ResponseEntity.ok(secondarySkillDetails.getAllSecondarySkills()); } /** @@ -71,7 +75,7 @@ public class SecondarySkillController { */ @GetMapping("/from-primary-skill") public ResponseEntity> getSecondarySkills(@RequestParam Long psid) { - return ResponseEntity.ok(secondarySkillService.getSecondarySkillsByPrimarySkillId(psid)); + return ResponseEntity.ok(secondarySkillDetails.getSecondarySkillsByPrimarySkillId(psid)); } /** @@ -83,7 +87,7 @@ public class SecondarySkillController { */ @PostMapping({ "/", "" }) public ResponseEntity post(@RequestBody SecondarySkill secondarySkill) { - SecondarySkill savedSecondarySkill = secondarySkillService.saveSecondarySkill(secondarySkill); + SecondarySkill savedSecondarySkill = secondarySkillActions.saveSecondarySkill(secondarySkill); return ResponseEntity.status(HttpStatus.CREATED).body(savedSecondarySkill); } @@ -96,7 +100,7 @@ public class SecondarySkillController { */ @PutMapping({ "/", "" }) public ResponseEntity put(@RequestBody SecondarySkill secondarySkill) { - SecondarySkill updatedSecondarySkill = secondarySkillService.saveSecondarySkill(secondarySkill); + SecondarySkill updatedSecondarySkill = secondarySkillActions.saveSecondarySkill(secondarySkill); return ResponseEntity.ok(updatedSecondarySkill); } @@ -109,7 +113,7 @@ public class SecondarySkillController { */ @DeleteMapping({ "/", "" }) public ResponseEntity delete(@RequestParam Long ssid) { - secondarySkillService.deleteSecondarySkill(ssid); + secondarySkillActions.deleteSecondarySkill(ssid); return ResponseEntity.noContent().build(); } } \ No newline at end of file diff --git a/src/main/java/com/maradona/backend/controllers/page/ProjectPage.java b/src/main/java/com/maradona/backend/controllers/page/ProjectPage.java index a4b66e6..3dbd0cc 100644 --- a/src/main/java/com/maradona/backend/controllers/page/ProjectPage.java +++ b/src/main/java/com/maradona/backend/controllers/page/ProjectPage.java @@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.beans.factory.annotation.Autowired; import com.maradona.backend.entities.Project; -import com.maradona.backend.services.ProjectService; +import com.maradona.backend.services.details.ProjectDetails; /** * Controller for routing to project related pages. @@ -21,7 +21,7 @@ import com.maradona.backend.services.ProjectService; @RequestMapping("/projects") public class ProjectPage { @Autowired - private ProjectService projectService; + private ProjectDetails projectDetails; /** * Returns the projects overview page. @@ -36,7 +36,7 @@ public class ProjectPage { */ @GetMapping({ "/", "" }) public String projects(Model model) { - var projects = projectService.getAllProjects(); + var projects = projectDetails.getAllProjects(); model.addAttribute("projects", projects); return "/pages/projects/overview"; } diff --git a/src/main/java/com/maradona/backend/controllers/page/SkillsPage.java b/src/main/java/com/maradona/backend/controllers/page/SkillsPage.java index c92c075..3b298d3 100644 --- a/src/main/java/com/maradona/backend/controllers/page/SkillsPage.java +++ b/src/main/java/com/maradona/backend/controllers/page/SkillsPage.java @@ -7,9 +7,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.stereotype.Controller; import com.maradona.backend.entities.SecondarySkill; -import com.maradona.backend.services.EmployeeService; -import com.maradona.backend.services.SkillService; -import com.maradona.backend.services.PrimarySkillService; +import com.maradona.backend.services.details.EmployeeDetails; +import com.maradona.backend.services.details.PrimarySkillDetails; +import com.maradona.backend.services.transfer.SkillService; import com.maradona.backend.dto.SkillPrototype; /** @@ -26,13 +26,13 @@ import com.maradona.backend.dto.SkillPrototype; @RequestMapping("/skills") public class SkillsPage { @Autowired - private EmployeeService employeeService; + private EmployeeDetails employeeDetails; @Autowired private SkillService skillService; @Autowired - private PrimarySkillService primarySkillService; + private PrimarySkillDetails primarySkillDetails; // Hardcoded placeholder user ID for now Long user = Long.valueOf(1); @@ -52,7 +52,7 @@ public class SkillsPage { */ @GetMapping({ "/", "" }) public String profile(Model model) { - model.addAttribute("employee", employeeService.getEmployeeByEid(user).orElse(null)); + model.addAttribute("employee", employeeDetails.getEmployeeByEid(user).orElse(null)); model.addAttribute("skills", skillService.getUserSkills(user)); return "/pages/skills/overview"; } @@ -93,7 +93,7 @@ public class SkillsPage { @GetMapping("/add") public String addSkill(Model model) { // TODO: Make sure it returns the correct initail data for secondary skills - model.addAttribute("primarySkills", primarySkillService.getAllPrimarySkills()); + model.addAttribute("primarySkills", primarySkillDetails.getAllPrimarySkills()); model.addAttribute("skillProtoype", new SkillPrototype()); return "/pages/skills/add"; } diff --git a/src/main/java/com/maradona/backend/services/EmployeeService.java b/src/main/java/com/maradona/backend/services/actions/EmployeeActions.java similarity index 63% rename from src/main/java/com/maradona/backend/services/EmployeeService.java rename to src/main/java/com/maradona/backend/services/actions/EmployeeActions.java index 6fcd32c..495d825 100644 --- a/src/main/java/com/maradona/backend/services/EmployeeService.java +++ b/src/main/java/com/maradona/backend/services/actions/EmployeeActions.java @@ -1,36 +1,29 @@ -package com.maradona.backend.services; +package com.maradona.backend.services.actions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.maradona.backend.entities.Employee; import com.maradona.backend.entities.EmployeeSecondarySkill; import com.maradona.backend.repositories.EmployeeRepository; +import com.maradona.backend.services.details.EmployeeDetails; +import com.maradona.backend.services.details.SecondarySkillDetails; import com.maradona.backend.dto.SkillPrototype; -import java.util.Optional; - @Service -public class EmployeeService { +public class EmployeeActions { @Autowired private EmployeeRepository employeeRepository; @Autowired - private SecondarySkillService secondarySkillService; + private EmployeeDetails employeeDetails; + + @Autowired + private SecondarySkillDetails secondarySkillDetails; public Employee saveEmployee(Employee employee) { return employeeRepository.save(employee); } - public Optional getEmployeeByEid(Long eid) { - var employees = employeeRepository.findAll(); - for (Employee employee : employees) { - if (employee.getEid().equals(eid)) { - return Optional.of(employee); - } - } - return Optional.empty(); - } - public void deleteEmployee(Long eid) { for (Employee employee : employeeRepository.findAll()) { if (employee.getEid().equals(eid)) { @@ -40,13 +33,9 @@ public class EmployeeService { } } - public Iterable getAllEmployees() { - return employeeRepository.findAll(); - } - public void addSecondarySkillToEmployee(Long eid, SkillPrototype skillPrototype) { - var employee = getEmployeeByEid(eid).orElseThrow(() -> new RuntimeException("Employee not found")); - var secondarySkill = secondarySkillService.getSecondarySkillBySsid(skillPrototype.getSsid()) + var employee = employeeDetails.getEmployeeByEid(eid).orElseThrow(() -> new RuntimeException("Employee not found")); + var secondarySkill = secondarySkillDetails.getSecondarySkillBySsid(skillPrototype.getSsid()) .orElseThrow(() -> new RuntimeException("Secondary Skill not found")); for (EmployeeSecondarySkill skill : employee.getSecondarySkills()) { @@ -64,8 +53,8 @@ public class EmployeeService { } public void updateSecondarySkillLevel(Long eid, Long ssid, Integer level) { - var employee = getEmployeeByEid(eid).orElseThrow(() -> new RuntimeException("Employee not found")); - secondarySkillService.getSecondarySkillBySsid( + var employee = employeeDetails.getEmployeeByEid(eid).orElseThrow(() -> new RuntimeException("Employee not found")); + secondarySkillDetails.getSecondarySkillBySsid( ssid) .orElseThrow(() -> new RuntimeException("Secondary Skill not found")); @@ -80,18 +69,12 @@ public class EmployeeService { } public void deleteSecondarySkillFromEmployee(Long eid, Long ssid) { - var employee = getEmployeeByEid(eid).orElseThrow(() -> new RuntimeException("Employee not found")); - secondarySkillService.getSecondarySkillBySsid( + var employee = employeeDetails.getEmployeeByEid(eid).orElseThrow(() -> new RuntimeException("Employee not found")); + secondarySkillDetails.getSecondarySkillBySsid( ssid) .orElseThrow(() -> new RuntimeException("Secondary Skill not found")); employee.getSecondarySkills().removeIf(skill -> skill.getSecondarySkill().getSsid().equals(ssid)); saveEmployee(employee); } - - public Iterable getEmployeesBySecondarySkill(Long ssid, Integer level) { - // Implement logic to fetch employees by secondary skill and level - // TODO: This is a placeholder implementation - return employeeRepository.findAll(); - } } \ No newline at end of file diff --git a/src/main/java/com/maradona/backend/services/FormOfAddressService.java b/src/main/java/com/maradona/backend/services/actions/FormOfAddressActions.java similarity index 56% rename from src/main/java/com/maradona/backend/services/FormOfAddressService.java rename to src/main/java/com/maradona/backend/services/actions/FormOfAddressActions.java index 7ac7f5a..007044e 100644 --- a/src/main/java/com/maradona/backend/services/FormOfAddressService.java +++ b/src/main/java/com/maradona/backend/services/actions/FormOfAddressActions.java @@ -1,32 +1,24 @@ -package com.maradona.backend.services; +package com.maradona.backend.services.actions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.maradona.backend.entities.FormOfAddress; import com.maradona.backend.repositories.FormOfAddressRepository; - -import java.util.Optional; +import com.maradona.backend.services.details.FormOfAddressDetails; @Service -public class FormOfAddressService { +public class FormOfAddressActions { @Autowired private FormOfAddressRepository formOfAddressRepository; + @Autowired + private FormOfAddressDetails formOfAddressDetails; + public FormOfAddress saveFormOfAddress(FormOfAddress formOfAddress) { return formOfAddressRepository.save(formOfAddress); } - public Optional getFormOfAddressByFid(Long fid) { - var formOfAddresses = formOfAddressRepository.findAll(); - for (FormOfAddress formOfAddress : formOfAddresses) { - if (formOfAddress.getFid().equals(fid)) { - return Optional.of(formOfAddress); - } - } - return Optional.empty(); - } - public void deleteFormOfAddress(Long fid) { for (FormOfAddress formOfAddress : formOfAddressRepository.findAll()) { if (formOfAddress.getFid().equals(fid)) { @@ -36,12 +28,9 @@ public class FormOfAddressService { } } - public Iterable getAllFormOfAddresses() { - return formOfAddressRepository.findAll(); - } - public void updateFormOfAddress(Long fid, String description) { - var formOfAddress = getFormOfAddressByFid(fid).orElseThrow(() -> new RuntimeException("Form of Address not found")); + var formOfAddress = formOfAddressDetails.getFormOfAddressByFid(fid) + .orElseThrow(() -> new RuntimeException("Form of Address not found")); formOfAddress.setDescription(description); saveFormOfAddress(formOfAddress); } diff --git a/src/main/java/com/maradona/backend/services/actions/PrimarySkillActions.java b/src/main/java/com/maradona/backend/services/actions/PrimarySkillActions.java new file mode 100644 index 0000000..0aa4abd --- /dev/null +++ b/src/main/java/com/maradona/backend/services/actions/PrimarySkillActions.java @@ -0,0 +1,42 @@ +package com.maradona.backend.services.actions; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.maradona.backend.entities.PrimarySkill; +import com.maradona.backend.entities.SecondarySkill; +import com.maradona.backend.repositories.PrimarySkillRepository; +import com.maradona.backend.repositories.SecondarySkillRepository; +import com.maradona.backend.services.details.SecondarySkillDetails; + +@Service +public class PrimarySkillActions { + + @Autowired + private PrimarySkillRepository primarySkillRepository; + + @Autowired + private SecondarySkillDetails secondarySkillDetails; + + @Autowired + private SecondarySkillRepository secondarySkillRepository; + + public PrimarySkill savePrimarySkill(PrimarySkill primarySkill) { + return primarySkillRepository.save(primarySkill); + } + + public void deletePrimarySkill(Long psid) { + var primarySkills = primarySkillRepository.findAll(); + var secondarySkills = secondarySkillDetails.getAllSecondarySkills(); + for (SecondarySkill secondarySkill : secondarySkills) { + if (secondarySkill.getPrimarySkill().getPsid().equals(psid)) { + var skillToDelete = secondarySkillDetails.getSecondarySkillBySsid(psid); + secondarySkillRepository.delete(skillToDelete.orElse(null)); + } + } + for (PrimarySkill primarySkill : primarySkills) { + if (primarySkill.getPsid().equals(psid)) { + primarySkillRepository.delete(primarySkill); + } + } + } +} diff --git a/src/main/java/com/maradona/backend/services/actions/ProjectActions.java b/src/main/java/com/maradona/backend/services/actions/ProjectActions.java new file mode 100644 index 0000000..c1d974b --- /dev/null +++ b/src/main/java/com/maradona/backend/services/actions/ProjectActions.java @@ -0,0 +1,26 @@ +package com.maradona.backend.services.actions; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.maradona.backend.entities.Project; +import com.maradona.backend.repositories.ProjectRepository; + +@Service +public class ProjectActions { + + @Autowired + private ProjectRepository projectRepository; + + public Project saveProject(Project project) { + return projectRepository.save(project); + } + + public void deleteProject(Long pid) { + var projects = projectRepository.findAll(); + for (Project project : projects) { + if (project.getPid().equals(pid)) { + projectRepository.delete(project); + } + } + } +} diff --git a/src/main/java/com/maradona/backend/services/actions/SecondarySkillActions.java b/src/main/java/com/maradona/backend/services/actions/SecondarySkillActions.java new file mode 100644 index 0000000..5dc033e --- /dev/null +++ b/src/main/java/com/maradona/backend/services/actions/SecondarySkillActions.java @@ -0,0 +1,42 @@ +package com.maradona.backend.services.actions; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.maradona.backend.entities.SecondarySkill; +import com.maradona.backend.repositories.PrimarySkillRepository; +import com.maradona.backend.repositories.SecondarySkillRepository; +import com.maradona.backend.services.details.PrimarySkillDetails; + +@Service +public class SecondarySkillActions { + @Autowired + private SecondarySkillRepository secondarySkillRepository; + + @Autowired + private PrimarySkillDetails primarySkillDetails; + + @Autowired + private PrimarySkillRepository primarySkillrRepository; + + public SecondarySkill saveSecondarySkill(SecondarySkill secondarySkill) { + var primarySkillDescription = secondarySkill.getPrimarySkill().getDescription(); + var existingPrimarySkill = primarySkillDetails.findByDescription(primarySkillDescription); + + if (existingPrimarySkill.isPresent()) { + secondarySkill.setPrimarySkill(existingPrimarySkill.get()); + } else { + primarySkillrRepository.save(secondarySkill.getPrimarySkill()); + } + + return secondarySkillRepository.save(secondarySkill); + } + + public void deleteSecondarySkill(Long ssid) { + var secondarySkills = secondarySkillRepository.findAll(); + for (SecondarySkill secondarySkill : secondarySkills) { + if (secondarySkill.getSsid().equals(ssid)) { + secondarySkillRepository.delete(secondarySkill); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/maradona/backend/services/details/EmployeeDetails.java b/src/main/java/com/maradona/backend/services/details/EmployeeDetails.java new file mode 100644 index 0000000..4997cb4 --- /dev/null +++ b/src/main/java/com/maradona/backend/services/details/EmployeeDetails.java @@ -0,0 +1,34 @@ +package com.maradona.backend.services.details; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.maradona.backend.entities.Employee; +import com.maradona.backend.repositories.EmployeeRepository; + +import java.util.Optional; + +@Service +public class EmployeeDetails { + @Autowired + private EmployeeRepository employeeRepository; + + public Optional getEmployeeByEid(Long eid) { + var employees = employeeRepository.findAll(); + for (Employee employee : employees) { + if (employee.getEid().equals(eid)) { + return Optional.of(employee); + } + } + return Optional.empty(); + } + + public Iterable getAllEmployees() { + return employeeRepository.findAll(); + } + + public Iterable getEmployeesBySecondarySkill(Long ssid, Integer level) { + // Implement logic to fetch employees by secondary skill and level + // TODO: This is a placeholder implementation + return employeeRepository.findAll(); + } +} \ No newline at end of file diff --git a/src/main/java/com/maradona/backend/services/details/FormOfAddressDetails.java b/src/main/java/com/maradona/backend/services/details/FormOfAddressDetails.java new file mode 100644 index 0000000..007f8ae --- /dev/null +++ b/src/main/java/com/maradona/backend/services/details/FormOfAddressDetails.java @@ -0,0 +1,29 @@ +package com.maradona.backend.services.details; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.maradona.backend.entities.FormOfAddress; +import com.maradona.backend.repositories.FormOfAddressRepository; + +import java.util.Optional; + +@Service +public class FormOfAddressDetails { + + @Autowired + private FormOfAddressRepository formOfAddressRepository; + + public Optional getFormOfAddressByFid(Long fid) { + var formOfAddresses = formOfAddressRepository.findAll(); + for (FormOfAddress formOfAddress : formOfAddresses) { + if (formOfAddress.getFid().equals(fid)) { + return Optional.of(formOfAddress); + } + } + return Optional.empty(); + } + + public Iterable getAllFormOfAddresses() { + return formOfAddressRepository.findAll(); + } +} diff --git a/src/main/java/com/maradona/backend/services/PrimarySkillService.java b/src/main/java/com/maradona/backend/services/details/PrimarySkillDetails.java similarity index 54% rename from src/main/java/com/maradona/backend/services/PrimarySkillService.java rename to src/main/java/com/maradona/backend/services/details/PrimarySkillDetails.java index 169ad7a..73667bd 100644 --- a/src/main/java/com/maradona/backend/services/PrimarySkillService.java +++ b/src/main/java/com/maradona/backend/services/details/PrimarySkillDetails.java @@ -1,26 +1,18 @@ -package com.maradona.backend.services; +package com.maradona.backend.services.details; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.maradona.backend.entities.PrimarySkill; -import com.maradona.backend.entities.SecondarySkill; import com.maradona.backend.repositories.PrimarySkillRepository; import java.util.Optional; @Service -public class PrimarySkillService { +public class PrimarySkillDetails { @Autowired private PrimarySkillRepository primarySkillRepository; - @Autowired - private SecondarySkillService secondarySkillRepository; - - public PrimarySkill savePrimarySkill(PrimarySkill primarySkill) { - return primarySkillRepository.save(primarySkill); - } - public Optional getPrimarySkillByPsid(Long psid) { var primarySkills = primarySkillRepository.findAll(); for (PrimarySkill primarySkill : primarySkills) { @@ -31,21 +23,6 @@ public class PrimarySkillService { return Optional.empty(); } - public void deletePrimarySkill(Long psid) { - var primarySkills = primarySkillRepository.findAll(); - var secondarySkills = secondarySkillRepository.getAllSecondarySkills(); - for (SecondarySkill secondarySkill : secondarySkills) { - if (secondarySkill.getPrimarySkill().getPsid().equals(psid)) { - secondarySkillRepository.deleteSecondarySkill(secondarySkill.getSsid()); - } - } - for (PrimarySkill primarySkill : primarySkills) { - if (primarySkill.getPsid().equals(psid)) { - primarySkillRepository.delete(primarySkill); - } - } - } - public Iterable getAllPrimarySkills() { return primarySkillRepository.findAll(); } diff --git a/src/main/java/com/maradona/backend/services/ProjectService.java b/src/main/java/com/maradona/backend/services/details/ProjectDetails.java similarity index 67% rename from src/main/java/com/maradona/backend/services/ProjectService.java rename to src/main/java/com/maradona/backend/services/details/ProjectDetails.java index 4e6280d..0af40a5 100644 --- a/src/main/java/com/maradona/backend/services/ProjectService.java +++ b/src/main/java/com/maradona/backend/services/details/ProjectDetails.java @@ -1,4 +1,4 @@ -package com.maradona.backend.services; +package com.maradona.backend.services.details; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -8,15 +8,11 @@ import com.maradona.backend.repositories.ProjectRepository; import java.util.Optional; @Service -public class ProjectService { +public class ProjectDetails { @Autowired private ProjectRepository projectRepository; - public Project saveProject(Project project) { - return projectRepository.save(project); - } - public Optional getProjectByPid(Long pid) { var projects = projectRepository.findAll(); for (Project project : projects) { @@ -27,15 +23,6 @@ public class ProjectService { return Optional.empty(); } - public void deleteProject(Long pid) { - var projects = projectRepository.findAll(); - for (Project project : projects) { - if (project.getPid().equals(pid)) { - projectRepository.delete(project); - } - } - } - public Iterable getAllProjects() { return projectRepository.findAll(); } diff --git a/src/main/java/com/maradona/backend/services/SecondarySkillService.java b/src/main/java/com/maradona/backend/services/details/SecondarySkillDetails.java similarity index 58% rename from src/main/java/com/maradona/backend/services/SecondarySkillService.java rename to src/main/java/com/maradona/backend/services/details/SecondarySkillDetails.java index 07df7eb..8d60851 100644 --- a/src/main/java/com/maradona/backend/services/SecondarySkillService.java +++ b/src/main/java/com/maradona/backend/services/details/SecondarySkillDetails.java @@ -1,4 +1,4 @@ -package com.maradona.backend.services; +package com.maradona.backend.services.details; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -8,26 +8,10 @@ import com.maradona.backend.repositories.SecondarySkillRepository; import java.util.Optional; @Service -public class SecondarySkillService { +public class SecondarySkillDetails { @Autowired private SecondarySkillRepository secondarySkillRepository; - @Autowired - private PrimarySkillService primarySkillService; - - public SecondarySkill saveSecondarySkill(SecondarySkill secondarySkill) { - var primarySkillDescription = secondarySkill.getPrimarySkill().getDescription(); - var existingPrimarySkill = primarySkillService.findByDescription(primarySkillDescription); - - if (existingPrimarySkill.isPresent()) { - secondarySkill.setPrimarySkill(existingPrimarySkill.get()); - } else { - primarySkillService.savePrimarySkill(secondarySkill.getPrimarySkill()); - } - - return secondarySkillRepository.save(secondarySkill); - } - public Optional getSecondarySkillBySsid(Long ssid) { var secondarySkills = secondarySkillRepository.findAll(); for (SecondarySkill secondarySkill : secondarySkills) { @@ -38,23 +22,19 @@ public class SecondarySkillService { return Optional.empty(); } - public void deleteSecondarySkill(Long ssid) { - secondarySkillRepository.deleteById(ssid); - } - - public Iterable getAllSecondarySkills() { - return secondarySkillRepository.findAll(); - } - public Iterable getSecondarySkillsByPrimarySkillId(Long psid) { var skills = secondarySkillRepository.findAll(); var result = new java.util.ArrayList(); for (SecondarySkill skill : skills) { if (skill.getPrimarySkill().getPsid().equals(psid)) { result.add(skill); - System.out.println(skill.getDescription()); } } return result; } + + public Iterable getAllSecondarySkills() { + return secondarySkillRepository.findAll(); + } + } \ No newline at end of file diff --git a/src/main/java/com/maradona/backend/services/SkillService.java b/src/main/java/com/maradona/backend/services/transfer/SkillService.java similarity index 76% rename from src/main/java/com/maradona/backend/services/SkillService.java rename to src/main/java/com/maradona/backend/services/transfer/SkillService.java index b3a6a4b..1516b6b 100644 --- a/src/main/java/com/maradona/backend/services/SkillService.java +++ b/src/main/java/com/maradona/backend/services/transfer/SkillService.java @@ -1,9 +1,13 @@ -package com.maradona.backend.services; +package com.maradona.backend.services.transfer; import com.maradona.backend.dto.SkillList; import com.maradona.backend.entities.Employee; import com.maradona.backend.entities.PrimarySkill; import com.maradona.backend.entities.SecondarySkill; +import com.maradona.backend.services.details.EmployeeDetails; +import com.maradona.backend.services.details.PrimarySkillDetails; +import com.maradona.backend.services.details.SecondarySkillDetails; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.data.util.Pair; @@ -16,17 +20,17 @@ import java.util.Map; public class SkillService { @Autowired - private PrimarySkillService primarySkillService; + private PrimarySkillDetails primarySkillDetails; @Autowired - private SecondarySkillService secondarySkillService; + private SecondarySkillDetails secondarySkillDetails; @Autowired - private EmployeeService employeeService; + private EmployeeDetails employeeDetails; public Iterable getAllSkills() { - Iterable primarySkills = primarySkillService.getAllPrimarySkills(); - Iterable secondarySkills = secondarySkillService.getAllSecondarySkills(); + Iterable primarySkills = primarySkillDetails.getAllPrimarySkills(); + Iterable secondarySkills = secondarySkillDetails.getAllSecondarySkills(); List skills = new ArrayList<>(); for (PrimarySkill primarySkill : primarySkills) { @@ -45,7 +49,7 @@ public class SkillService { if (eid == null) { return new ArrayList<>(); } - Employee employee = employeeService.getEmployeeByEid(eid).orElse(null); + Employee employee = employeeDetails.getEmployeeByEid(eid).orElse(null); if (employee == null) { return new ArrayList<>(); } @@ -53,7 +57,7 @@ public class SkillService { Map secondarySkillLevels = employee.getSecondarySkillLevels(); List skills = new ArrayList<>(); - for (PrimarySkill primarySkill : primarySkillService.getAllPrimarySkills()) { + for (PrimarySkill primarySkill : primarySkillDetails.getAllPrimarySkills()) { List> secondarySkillList = new ArrayList<>(); for (Map.Entry entry : secondarySkillLevels.entrySet()) { if (entry.getKey().getPrimarySkill().getPsid().equals(primarySkill.getPsid())) {