refactor: Update projects
parent
572ec3ff51
commit
d56601f84c
|
@ -1,41 +0,0 @@
|
|||
package com.maradona.backend.controllers;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
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;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/projects")
|
||||
public class ProjectController {
|
||||
@Autowired
|
||||
private ProjectService projectService;
|
||||
|
||||
@GetMapping({ "/", "" })
|
||||
public String projects(Model model) {
|
||||
var projectData = projectService.getAllProjects();
|
||||
model.addAttribute("projectData", projectData);
|
||||
return "projects/projects";
|
||||
}
|
||||
|
||||
@GetMapping("/create")
|
||||
public String create(Model model) {
|
||||
model.addAttribute("project", new Project());
|
||||
return "projects/projects-create";
|
||||
}
|
||||
|
||||
@PostMapping("/save")
|
||||
public String save(@ModelAttribute Project project) {
|
||||
projectService.saveProject(project);
|
||||
return "redirect:/projects";
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public String delete(@RequestParam Long id) {
|
||||
projectService.deleteProject(id);
|
||||
return "redirect:/projects";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package com.maradona.backend.controllers.api;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import com.maradona.backend.entities.Project;
|
||||
import com.maradona.backend.services.ProjectService;
|
||||
|
||||
/**
|
||||
* Controller for handling project data.
|
||||
*
|
||||
* List of endpoints:
|
||||
* - GET /api/project
|
||||
* - GET /api/project/all
|
||||
* - GET /api/project/from-user
|
||||
* - POST /api/project
|
||||
* - PUT /api/project
|
||||
* - DELETE /api/project
|
||||
*
|
||||
* @warning The ProjectService is not accounting for the user yet.
|
||||
* @see Project
|
||||
* @see ProjectService
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/api/project")
|
||||
public class ProjectController {
|
||||
|
||||
/**
|
||||
* Service for handling project data.
|
||||
*/
|
||||
@Autowired
|
||||
private ProjectService projectService;
|
||||
|
||||
/**
|
||||
* Hardcoded user ID for testing purposes
|
||||
*/
|
||||
Long user = Long.valueOf(1);
|
||||
|
||||
/**
|
||||
* Returns a specific project from the database.
|
||||
*
|
||||
* @param id The ID of the requested project.
|
||||
* @param model The model with the requested data.
|
||||
* @see Project
|
||||
*/
|
||||
@GetMapping({ "/", "" })
|
||||
public void get(@RequestParam Long id, Model model) {
|
||||
var project = projectService.getProjectById(id).orElse(null);
|
||||
model.addAttribute("project", project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all projects from the database.
|
||||
*
|
||||
* @param model The model with the requested data.
|
||||
* @see Project
|
||||
*/
|
||||
@GetMapping("/all")
|
||||
public void getAll(Model model) {
|
||||
var projects = projectService.getAllProjects();
|
||||
model.addAttribute("projects", projects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all projects from the database that are associated with a specific
|
||||
* user.
|
||||
*
|
||||
* @param project
|
||||
* @param model
|
||||
* @see Project
|
||||
*/
|
||||
@GetMapping("/from-user")
|
||||
public void getFromUser(@ModelAttribute Project project, Model model) {
|
||||
var projects = projectService.getProjectsByUser(user);
|
||||
model.addAttribute("projects", projects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new project in the database.
|
||||
*
|
||||
* @param project The project to be created.
|
||||
* @see Project
|
||||
*/
|
||||
@PostMapping
|
||||
public void create(@ModelAttribute Project project) {
|
||||
projectService.saveProject(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing project in the database.
|
||||
*
|
||||
* @param project The project to be updated.
|
||||
* @see Project
|
||||
*/
|
||||
@PutMapping
|
||||
public void update(@ModelAttribute Project project) {
|
||||
projectService.saveProject(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a project from the database.
|
||||
*
|
||||
* @param id The ID of the project to be deleted.
|
||||
*/
|
||||
@DeleteMapping
|
||||
public void delete(@RequestParam Long id) {
|
||||
projectService.deleteProject(id);
|
||||
}
|
||||
}
|
|
@ -20,18 +20,18 @@ import com.maradona.backend.services.SecondarySkillService;
|
|||
* Controller for handling secondary skill data.
|
||||
*
|
||||
* List of endpoints:
|
||||
* - GET /api/secondary-skills
|
||||
* - GET /api/secondary-skills/all
|
||||
* - GET /api/secondary-skills/from-primary-skill
|
||||
* - POST /api/secondary-skills
|
||||
* - PUT /api/secondary-skills
|
||||
* - DELETE /api/secondary-skills
|
||||
* - GET /api/secondary-skill
|
||||
* - GET /api/secondary-skill/all
|
||||
* - GET /api/secondary-skill/from-primary-skill
|
||||
* - POST /api/secondary-skill
|
||||
* - PUT /api/secondary-skill
|
||||
* - DELETE /api/secondary-skill
|
||||
*
|
||||
* @see SecondarySkill
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/api/secondary-skills")
|
||||
public class SecondarySkillsController {
|
||||
@RequestMapping("/api/secondary-skill")
|
||||
public class SecondarySkillController {
|
||||
|
||||
/**
|
||||
* Service for handling secondary skill data.
|
|
@ -0,0 +1,56 @@
|
|||
package com.maradona.backend.controllers.page;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Controller for routing to project related pages.
|
||||
*
|
||||
* List of endpoints:
|
||||
* - GET /projects
|
||||
* - GET /projects/create
|
||||
*
|
||||
* @see Project
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/projects")
|
||||
public class ProjectPage {
|
||||
@Autowired
|
||||
private ProjectService projectService;
|
||||
|
||||
/**
|
||||
* Returns the projects overview page.
|
||||
* Collects the project list and adds it to the model for the frontend.
|
||||
*
|
||||
* Attributes that can be used by the frontend are a List of Project objects
|
||||
* "projects".
|
||||
*
|
||||
* @param model The model with the data to be displayed.
|
||||
* @return The projects overview page template
|
||||
* @see Project
|
||||
*/
|
||||
@GetMapping({ "/", "" })
|
||||
public String projects(Model model) {
|
||||
var projects = projectService.getAllProjects();
|
||||
model.addAttribute("projects", projects);
|
||||
return "projects/projects";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the project creation page.
|
||||
*
|
||||
* @param model The model with the data to be displayed.
|
||||
* @return The project creation page template
|
||||
* @see Project
|
||||
*/
|
||||
@GetMapping("/create")
|
||||
public String create(Model model) {
|
||||
model.addAttribute("project", new Project());
|
||||
return "projects/projects-create";
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.maradona.backend.controllers;
|
||||
package com.maradona.backend.controllers.page;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.Model;
|
||||
|
@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
|||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import com.maradona.backend.entities.SecondarySkill;
|
||||
|
@ -23,7 +22,7 @@ import java.util.List;
|
|||
|
||||
@Controller
|
||||
@RequestMapping("/skills")
|
||||
public class SkillsController {
|
||||
public class SkillsPage {
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
|
|
@ -28,4 +28,9 @@ public class ProjectService {
|
|||
public Iterable<Project> getAllProjects() {
|
||||
return projectRepository.findAll();
|
||||
}
|
||||
|
||||
public Iterable<Project> getProjectsByUser(Long userId) {
|
||||
// TODO: Actually filter by user
|
||||
return projectRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue