-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentController.java
More file actions
73 lines (63 loc) · 3.2 KB
/
AssignmentController.java
File metadata and controls
73 lines (63 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.grade.manage.controller;
import com.grade.manage.dto.create.TempAssignCreateDTO;
import com.grade.manage.dto.detail.TempAssignDetailDTO;
import com.grade.manage.dto.simple.TempAssignDTO;
import com.grade.manage.dto.update.AssignmentUpdateDTO;
import com.grade.manage.response.ApiResponse;
import com.grade.manage.service.AssignmentService;
import jakarta.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
*
* @author Studios TKOH!
*/
@RestController
@RequestMapping("/api/assignments")
@RequiredArgsConstructor
public class AssignmentController {
private final AssignmentService assignmentService;
@GetMapping
public ResponseEntity<ApiResponse<List<TempAssignDTO>>> listAll() {
return ResponseEntity.ok(ApiResponse.ok("Assignments fetched successfully", assignmentService.listAll()));
}
@GetMapping("/users/{userId}")
public ResponseEntity<ApiResponse<List<TempAssignDTO>>> listByUser(@PathVariable Long userId) {
return ResponseEntity.ok(ApiResponse.ok("Assignments fetched successfully", assignmentService.listByUser(userId)));
}
@GetMapping("/range")
public ResponseEntity<ApiResponse<List<TempAssignDTO>>> listByRange(
@RequestParam("start") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime start,
@RequestParam("end") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime end) {
return ResponseEntity.ok(ApiResponse.ok("Assignments fetched successfully", assignmentService.listByDateRange(start, end)));
}
@GetMapping("/{id}")
public ResponseEntity<ApiResponse<TempAssignDetailDTO>> getDetail(@PathVariable Long id) {
return ResponseEntity.ok(ApiResponse.ok("Assignment fetched successfully", assignmentService.getDetail(id)));
}
@PostMapping
public ResponseEntity<ApiResponse<TempAssignDetailDTO>> create(@Valid @RequestBody TempAssignCreateDTO create) {
return ResponseEntity.ok(ApiResponse.ok("Assignment created successfully", assignmentService.create(create)));
}
@PutMapping
public ResponseEntity<ApiResponse<TempAssignDetailDTO>> update(@Valid @RequestBody AssignmentUpdateDTO update) {
return ResponseEntity.ok(ApiResponse.ok("Assignment updated successfully", assignmentService.update(update)));
}
@DeleteMapping("/{id}")
public ResponseEntity<ApiResponse<Void>> delete(@PathVariable Long id) {
assignmentService.delete(id);
return ResponseEntity.ok(ApiResponse.ok("Assignment deleted successfully"));
}
}