feat(markers): get by id

This commit is contained in:
2026-07-02 18:35:22 +01:00
parent 62dc0b0491
commit dc33d1df33
7 changed files with 57 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
meta {
name: Create Marker
type: http
seq: 2
seq: 3
}
post {

View File

@@ -0,0 +1,16 @@
meta {
name: Get Marker
type: http
seq: 1
}
get {
url: {{base_url}}/markers/5
body: none
auth: inherit
}
settings {
encodeUrl: true
timeout: 0
}

View File

@@ -1,7 +1,7 @@
meta {
name: Get all markers
type: http
seq: 1
seq: 2
}
get {

View File

@@ -115,4 +115,11 @@ public class GlobalExceptionHandler {
APIResponse<Void> response = new APIResponse<>(ERROR, ex.getMessage(), null);
return ResponseEntity.status(HttpStatus.CONFLICT).body(response);
}
@ExceptionHandler(MarkerNotFound.class)
public ResponseEntity<APIResponse<Void>> handleMarkerNotFound(MarkerNotFound ex) {
logger.error("MarkerNotFound: {}", ex.getMessage());
APIResponse<Void> response = new APIResponse<>(ERROR, ex.getMessage(), null);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}

View File

@@ -33,6 +33,15 @@ public class MarkerController {
);
}
@GetMapping("/{id}")
public ResponseEntity<APIResponse<MarkerResponse>> getMarkerById(@PathVariable Long id) {
Marker marker = markerService.getMarkerById(id);
return ResponseEntity.ok(
new APIResponse<>(SUCCESS, "Marker retrieved successfully", convertToDTO(marker))
);
}
@PostMapping("")
public ResponseEntity<APIResponse<MarkerResponse>> createMarker(@Valid @RequestBody MarkerCreateRequest request) {
Marker marker = markerService.create(request.message());

View File

@@ -0,0 +1,7 @@
package com.ddf.vodsystem.exceptions;
public class MarkerNotFound extends RuntimeException {
public MarkerNotFound(String message) {
super(message);
}
}

View File

@@ -3,6 +3,7 @@ package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.Marker;
import com.ddf.vodsystem.entities.Stream;
import com.ddf.vodsystem.entities.User;
import com.ddf.vodsystem.exceptions.MarkerNotFound;
import com.ddf.vodsystem.exceptions.NotAuthenticated;
import com.ddf.vodsystem.exceptions.NotStreaming;
import com.ddf.vodsystem.repositories.MarkerRepository;
@@ -25,6 +26,21 @@ public class MarkerService {
this.markerRepository = markerRepository;
}
public Marker getMarkerById(Long id) {
Optional<Marker> marker = markerRepository.findById(id);
if (marker.isEmpty()) {
throw new MarkerNotFound("Marker does not exist");
}
Optional<User> user = userService.getLoggedInUser();
if (user.isEmpty() || !user.get().equals(marker.get().getUser())) {
throw new NotAuthenticated("User not authenticated for this marker");
}
return marker.get();
}
public List<Marker> getUserMarkers() {
Optional<User> user = userService.getLoggedInUser();