source: src/main/java/com/example/task/service/TaskService.java@ fdfbdde

Last change on this file since fdfbdde was fdfbdde, checked in by Stojilkova Sara <sara.stojilkova.students.finki.ukim.mk>, 9 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1package com.example.task.service;
2
3import com.example.task.entity.TaskEntity;
4import com.example.task.repository.TaskRepository;
5import lombok.AllArgsConstructor;
6import org.springframework.stereotype.Service;
7
8import java.time.LocalDate;
9import java.util.List;
10
11@Service
12@AllArgsConstructor
13public class TaskService {
14
15 private final TaskRepository taskRepository;
16 private final UserAuthenticationService userAuthenticationService;
17
18 public void addTask(String name, String description, int priority, LocalDate dueDate) {
19 taskRepository.save(new TaskEntity(dueDate, name, description, priority, false, userAuthenticationService.getLoggedInUser()));
20 }
21
22 public List<TaskEntity> getUserTasks() {
23 return userAuthenticationService.getLoggedInUser().getTasks();
24 }
25
26 public void deleteTask(Integer id) {
27 taskRepository.deleteById(id);
28 }
29
30 public void finishTask(Integer id) throws Exception {
31 TaskEntity task = taskRepository.findById(id).orElseThrow(Exception::new);
32 task.setDone(true);
33 taskRepository.save(task);
34 }
35}
Note: See TracBrowser for help on using the repository browser.