--- /dev/null
+package eu.svjatoslav.alyverkko.controller;
+
+import eu.svjatoslav.alyverkko.models.User;
+import eu.svjatoslav.alyverkko.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/users")
+public class UserController {
+
+ private final UserService userService;
+
+ @Autowired
+ public UserController(UserService userService) {
+ this.userService = userService;
+ }
+
+ @GetMapping
+ public List<User> getAllUsers() {
+ return userService.findAll();
+ }
+
+ @PostMapping
+ public User createUser(@RequestBody User user) {
+ return userService.save(user);
+ }
+
+ @DeleteMapping("/{id}")
+ public void deleteUser(@PathVariable Long id) {
+ userService.deleteById(id);
+ }
+
+
+ @GetMapping
+ public String listEntities(Model model) {
+ model.addAttribute("users", userService.findAll());
+ return "user/list";
+ }
+
+ @GetMapping("/{id}")
+ public String showEntity(@PathVariable Long id, Model model) {
+ User entity = userService.findById(id);
+ if (entity != null) {
+ model.addAttribute("user", entity);
+ return "user/show";
+ }
+ return "redirect:/user";
+ }
+
+ @GetMapping("/new")
+ public String createEntityForm(Model model) {
+ model.addAttribute("entity", new User());
+ return "user/edit";
+ }
+
+ @PostMapping
+ public String saveEntity(@ModelAttribute("entity") User user) {
+ userService.save(user);
+ return "redirect:/user";
+ }
+
+ @GetMapping("/{id}/edit")
+ public String editEntityForm(@PathVariable Long id, Model model) {
+ User entity = userService.findById(id);
+ if (entity != null) {
+ model.addAttribute("user", entity);
+ return "user/edit";
+ }
+ return "redirect:/user";
+ }
+
+ @DeleteMapping("/{id}")
+ public String deleteEntity(@PathVariable Long id) {
+ userService.deleteById(id);
+ return "redirect:/user";
+ }
+}
\ No newline at end of file
--- /dev/null
+package eu.svjatoslav.alyverkko.service;
+
+import eu.svjatoslav.alyverkko.models.User;
+import eu.svjatoslav.alyverkko.repository.UserRepository;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class UserService {
+
+ UserRepository userRepository;
+
+ public UserService(UserRepository userRepository) {
+ this.userRepository = userRepository;
+ }
+
+ public List<User> findAll() {
+ return userRepository.findAll();
+ }
+
+ public User save(User user) {
+ return userRepository.save(user);
+ }
+
+ public void deleteById(Long id) {
+ userRepository.deleteById(id);
+ }
+
+ public User findById(Long id) {
+ return userRepository.findById(id).get();
+ }
+}
--- /dev/null
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head>
+ <meta charset="UTF-8">
+ <title>Your Entities List</title>
+</head>
+<body>
+<h1>Entities List</h1>
+<a class="btn btn-primary mb-3" href="users/new">Create New User</a>
+<table class="table">
+ <thead>
+ <tr>
+ <th>ID</th>
+ <th>Name</th>
+ <th>Actions</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr th:each="user : ${users}">
+ <td th:text="${user.id}"></td>
+ <td th:text="${user.username}"></td>
+ <td>
+ <a class="btn btn-info" th:href="@{/user/{id}(id=${user.id})}">View</a>
+ <a class="btn btn-primary" th:href="@{/your/{id}/edit}(id=${user.id})">Edit</a>
+ </td>
+ </tr>
+ </tbody>
+</table>
+</body>
+</html>