-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassAPI.java
More file actions
57 lines (54 loc) · 1.71 KB
/
ClassAPI.java
File metadata and controls
57 lines (54 loc) · 1.71 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
package com.hcmutap.elearning.controller.api;
import com.hcmutap.elearning.controller.admin.HomeController;
import com.hcmutap.elearning.exception.NotFoundException;
import com.hcmutap.elearning.model.ClassModel;
import com.hcmutap.elearning.service.IClassService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api")
public class ClassAPI {
private static final Logger logger = LoggerFactory.getLogger(ClassAPI.class);
@Resource
private IClassService classService;
@GetMapping("/class/findAll")
public List<ClassModel> findAll() {
return classService.findAll();
}
@GetMapping("/class/findById")
public ClassModel findById(@RequestParam String id) {
try {
return classService.findById(id);
} catch (NotFoundException e) {
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
return null;
}
}
@PostMapping("/class")
public String save(@RequestBody ClassModel classModel) { return classService.save(classModel);}
@PutMapping("/class")
public void update(@RequestBody ClassModel classModel) {
// need to handler not found exception in dao -> service -> controller
try {
classService.update(classModel);
} catch (NotFoundException e) {
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
// return null;
}
}
@DeleteMapping("/class")
public void delete(@RequestBody List<String> ids) {
try {
classService.delete(ids);
} catch (NotFoundException e) {
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
// return null;
}
}
}