1 | package edu.ucsb.cs156.happiercows.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.happiercows.entities.Course; | |
4 | import com.fasterxml.jackson.core.JsonProcessingException; | |
5 | import com.fasterxml.jackson.databind.ObjectMapper; | |
6 | import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException; | |
7 | import edu.ucsb.cs156.happiercows.models.HealthUpdateStrategyList; | |
8 | import edu.ucsb.cs156.happiercows.repositories.CourseRepository; | |
9 | import io.swagger.v3.oas.annotations.Operation; | |
10 | import io.swagger.v3.oas.annotations.Parameter; | |
11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
12 | import lombok.extern.slf4j.Slf4j; | |
13 | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | |
15 | import org.springframework.security.access.prepost.PreAuthorize; | |
16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
17 | import org.springframework.web.bind.annotation.GetMapping; | |
18 | import org.springframework.web.bind.annotation.PostMapping; | |
19 | import org.springframework.web.bind.annotation.RequestMapping; | |
20 | import org.springframework.web.bind.annotation.RequestParam; | |
21 | import org.springframework.format.annotation.DateTimeFormat; | |
22 | import org.springframework.web.bind.annotation.RestController; | |
23 | ||
24 | import java.time.LocalDateTime; | |
25 | ||
26 | @Tag(name = "courses") | |
27 | @RequestMapping("/api/courses") | |
28 | @RestController | |
29 | @Slf4j | |
30 | public class CourseController extends ApiController { | |
31 | ||
32 | @Autowired | |
33 | CourseRepository courseRepository; | |
34 | ||
35 | // Get all records in the table and return as a JSON array | |
36 | @Operation(summary= "List all courses") | |
37 | @PreAuthorize("hasRole('ROLE_USER')") | |
38 | @GetMapping("/all") | |
39 | public Iterable<Course> allCourses() { | |
40 | Iterable<Course> courses = courseRepository.findAll(); | |
41 |
1
1. allCourses : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/CourseController::allCourses → KILLED |
return courses; |
42 | } | |
43 | ||
44 | // Use the data in the input parameters to create a new row in the table and return the data as JSON | |
45 | @Operation(summary= "Create a new course") | |
46 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
47 | @PostMapping("/post") | |
48 | public Course postCourse( | |
49 | @Parameter(name = "name") @RequestParam String name, | |
50 | @Parameter(name = "school") @RequestParam String school, | |
51 | @Parameter(name = "term") @RequestParam String term, | |
52 | @Parameter(name = "startDate", description = "in iso format, i.e. YYYY-MM-DDTHH:MM:SS") | |
53 | @RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startDate, | |
54 | @Parameter(name = "endDate", description = "in iso format, i.e. YYYY-MM-DDTHH:MM:SS") | |
55 | @RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endDate) { | |
56 | | |
57 | Course course = Course.builder() | |
58 | .name(name) | |
59 | .school(school) | |
60 | .term(term) | |
61 | .startDate(startDate) | |
62 | .endDate(endDate) | |
63 | .build(); | |
64 | | |
65 |
1
1. postCourse : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/CourseController::postCourse → KILLED |
return courseRepository.save(course); |
66 | } | |
67 | ||
68 | @Operation(summary = "Delete a course") | |
69 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
70 | @DeleteMapping("") | |
71 | public Object deleteCourse( | |
72 | @Parameter(description = "ID of the Course to delete") @RequestParam Long id) { | |
73 | Course course = courseRepository.findById(id) | |
74 |
1
1. lambda$deleteCourse$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/CourseController::lambda$deleteCourse$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, id)); |
75 | ||
76 |
1
1. deleteCourse : removed call to edu/ucsb/cs156/happiercows/repositories/CourseRepository::delete → KILLED |
courseRepository.delete(course); |
77 |
1
1. deleteCourse : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/CourseController::deleteCourse → KILLED |
return genericMessage(String.format("Course with id %s deleted", id)); |
78 | } | |
79 | ||
80 | } | |
81 | ||
Mutations | ||
41 |
1.1 |
|
65 |
1.1 |
|
74 |
1.1 |
|
76 |
1.1 |
|
77 |
1.1 |