Add endpoint to list reaction types

This commit is contained in:
Tim
2025-07-01 16:00:52 +08:00
parent de463e0884
commit 43a8c75f88
2 changed files with 16 additions and 0 deletions

View File

@@ -15,6 +15,14 @@ import org.springframework.web.bind.annotation.*;
public class ReactionController {
private final ReactionService reactionService;
/**
* Get all available reaction types.
*/
@GetMapping("/reaction-types")
public ReactionType[] listReactionTypes() {
return ReactionType.values();
}
@PostMapping("/posts/{postId}/reactions")
public ResponseEntity<ReactionDto> reactToPost(@PathVariable Long postId,
@RequestBody ReactionRequest req,

View File

@@ -17,6 +17,7 @@ import org.springframework.test.web.servlet.MockMvc;
import static org.mockito.ArgumentMatchers.eq;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -70,4 +71,11 @@ class ReactionControllerTest {
.andExpect(status().isOk())
.andExpect(jsonPath("$.commentId").value(2));
}
@Test
void listReactionTypes() throws Exception {
mockMvc.perform(get("/api/reaction-types"))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0]").value("LIKE"));
}
}