content: package com.taskmanager.taskmanager.web;
  
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RestController;
  import com.taskmanager.taskmanager.entity.Task;
  import com.taskmanager.taskmanager.service.TaskService;
  import jakarta.validation.Valid;
  import lombok.AllArgsConstructor;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.HttpStatusCode;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.CrossOrigin;
  import org.springframework.web.bind.annotation.DeleteMapping;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.PutMapping;
  
  
  @CrossOrigin(origins = "http://localhost:5173")
  @AllArgsConstructor
  @RestController
  @RequestMapping("/task")
  public class TaskController {
      @Autowired
      private TaskService taskService;
      
      @GetMapping("/all")
      public ResponseEntity<List<Task>> getAllTasks() {
          return new ResponseEntity<>(taskService.getAllTasks(), HttpStatus.OK);
      }
      
      @GetMapping("/{taskId}")
      public ResponseEntity<Task> getTask(@PathVariable Long taskId) {
          return new ResponseEntity<>(taskService.getTask(taskId), HttpStatus.OK);
      }
  
      @GetMapping("user/{userId}")
      public ResponseEntity<List<Task>> getUserTasks(@PathVariable Long userId) {
          return new ResponseEntity<>(taskService.getUserTasks(userId), HttpStatus.OK);
      }
  
      @PostMapping("/user/{userId}")
      public ResponseEntity<Task> addTask(@Valid @RequestBody Task task, @PathVariable Long userId) {
          return new ResponseEntity<>(taskService.saveTask(userId, task), HttpStatus.OK);
      }
  
      @PutMapping("/{taskId}")
      public ResponseEntity<Task> updateTask(@PathVariable Long taskId, @RequestBody @Valid Task task) {
          return new ResponseEntity<>(taskService.updateTask(taskId, task), HttpStatus.OK);
      }
  
      @PutMapping("{taskId}/session")
      public ResponseEntity<Task> addSession(@PathVariable Long taskId) {
          return new ResponseEntity<>(taskService.addSession(taskId), HttpStatus.OK);
      }
  
      @DeleteMapping("/{taskId}")
      public ResponseEntity<HttpStatus> deleteTask(@PathVariable Long taskId) {
          taskService.deleteTask(taskId);
          return new ResponseEntity<>(HttpStatus.NO_CONTENT);
      }
  
  }
  