Last change
on this file 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 | |
---|
1 | package com.example.task.service;
|
---|
2 |
|
---|
3 | import com.example.task.entity.TaskEntity;
|
---|
4 | import com.example.task.repository.TaskRepository;
|
---|
5 | import lombok.AllArgsConstructor;
|
---|
6 | import org.springframework.stereotype.Service;
|
---|
7 |
|
---|
8 | import java.time.LocalDate;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | @Service
|
---|
12 | @AllArgsConstructor
|
---|
13 | public 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.