api: Implement delete project

pull/1/head
Lunix-420 2024-11-01 02:53:43 +01:00
parent 269371f5c8
commit 3326d48450
4 changed files with 18 additions and 11 deletions

Binary file not shown.

View File

@ -7,6 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.maradona.backend.entities.Project;
import com.maradona.backend.services.ProjectService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@Controller
@RequestMapping("/projects")
@ -31,6 +33,13 @@ public class ProjectController {
@PostMapping("/save")
public String save(@ModelAttribute Project project) {
projectService.saveProject(project);
return "redirect:/";
return "redirect:/projects";
}
@PostMapping("/delete")
public String delete(@RequestParam Long id) {
projectService.deleteProject(id);
return "redirect:/projects";
}
}

View File

@ -14,12 +14,14 @@
<span th:text="${project.name}">Project Name</span> -
<span th:text="${project.startDate}">Start Date</span> to
<span th:text="${project.endDate}">End Date</span>
<button
th:href="@{/projects/delete/{id}(id=${project.id})}"
type="submit"
<form
th:action="@{/projects/delete}"
method="post"
style="display: inline"
>
Delete
</button>
<input type="hidden" name="id" th:value="${project.id}" />
<button type="submit" class="button">Delete</button>
</form>
</li>
</ul>
</div>

View File

@ -8,11 +8,7 @@
<div th:replace="~{_header :: header(activePage=${home})}"></div>
<div>
<h2>Create Project</h2>
<form
th:action="@{/projects/create}"
th:object="${project}"
method="post"
>
<form th:action="@{/projects/save}" th:object="${project}" method="post">
<div>
<label for="name">Project Name:</label>
<input type="text" id="name" th:field="*{name}" required />