| 1 | package edu.ucsb.cs.scaffold.controller; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.annotation.JsonProperty; | |
| 4 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 5 | import com.fasterxml.jackson.databind.JsonNode; | |
| 6 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 7 | import edu.ucsb.cs.scaffold.model.LegacyUserActivity; | |
| 8 | import edu.ucsb.cs.scaffold.repository.LegacyUserActivityRepository; | |
| 9 | import io.swagger.v3.oas.annotations.Operation; | |
| 10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | import lombok.RequiredArgsConstructor; | |
| 12 | import org.springframework.http.ResponseEntity; | |
| 13 | import org.springframework.web.bind.annotation.*; | |
| 14 | ||
| 15 | // Serves only LegacyHomePage.tsx (via legacyClient.ts). Events here have no course | |
| 16 | // scoping; the course-scoped counterpart is UserActivityController at /api/user-activity. | |
| 17 | @Tag(name = "Legacy User Activity") | |
| 18 | @RestController | |
| 19 | @RequiredArgsConstructor | |
| 20 | public class LegacyUserActivityController { | |
| 21 | ||
| 22 | private final LegacyUserActivityRepository legacyUserActivityRepository; | |
| 23 | private final ObjectMapper objectMapper; | |
| 24 | ||
| 25 | @Operation(summary = "Insert a legacy user activity event") | |
| 26 | @PostMapping("/api/legacy/user-activity") | |
| 27 | public ResponseEntity<Void> insertUserActivity(@RequestBody LegacyUserActivityRequest body) { | |
| 28 |
3
1. insertUserActivity : negated conditional → KILLED 2. insertUserActivity : negated conditional → KILLED 3. insertUserActivity : negated conditional → KILLED |
if (body.userid() == null || body.eventType() == null || body.eventType().isBlank()) { |
| 29 |
1
1. insertUserActivity : replaced return value with null for edu/ucsb/cs/scaffold/controller/LegacyUserActivityController::insertUserActivity → KILLED |
return ResponseEntity.badRequest().build(); |
| 30 | } | |
| 31 | ||
| 32 | LegacyUserActivity activity = new LegacyUserActivity(); | |
| 33 |
1
1. insertUserActivity : removed call to edu/ucsb/cs/scaffold/model/LegacyUserActivity::setUserid → KILLED |
activity.setUserid(body.userid()); |
| 34 |
1
1. insertUserActivity : removed call to edu/ucsb/cs/scaffold/model/LegacyUserActivity::setEventType → KILLED |
activity.setEventType(body.eventType()); |
| 35 |
1
1. insertUserActivity : removed call to edu/ucsb/cs/scaffold/model/LegacyUserActivity::setPayload → KILLED |
activity.setPayload( |
| 36 |
1
1. insertUserActivity : negated conditional → KILLED |
writeJson(body.payload() == null ? objectMapper.createObjectNode() : body.payload())); |
| 37 | legacyUserActivityRepository.save(activity); | |
| 38 |
1
1. insertUserActivity : replaced return value with null for edu/ucsb/cs/scaffold/controller/LegacyUserActivityController::insertUserActivity → KILLED |
return ResponseEntity.noContent().build(); |
| 39 | } | |
| 40 | ||
| 41 | private String writeJson(Object value) { | |
| 42 | try { | |
| 43 |
1
1. writeJson : replaced return value with "" for edu/ucsb/cs/scaffold/controller/LegacyUserActivityController::writeJson → KILLED |
return objectMapper.writeValueAsString(value); |
| 44 | } catch (JsonProcessingException e) { | |
| 45 | throw new IllegalArgumentException("Unable to serialize JSON payload", e); | |
| 46 | } | |
| 47 | } | |
| 48 | ||
| 49 | public record LegacyUserActivityRequest( | |
| 50 | Long userid, @JsonProperty("event_type") String eventType, JsonNode payload) {} | |
| 51 | } | |
Mutations | ||
| 28 |
1.1 2.2 3.3 |
|
| 29 |
1.1 |
|
| 33 |
1.1 |
|
| 34 |
1.1 |
|
| 35 |
1.1 |
|
| 36 |
1.1 |
|
| 38 |
1.1 |
|
| 43 |
1.1 |