Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 13869c577b |
@@ -1,7 +1,9 @@
|
||||
package com.ddf.vodsystem.controllers;
|
||||
|
||||
import com.ddf.vodsystem.controllers.dto.StreamKey;
|
||||
import com.ddf.vodsystem.dto.APIResponse;
|
||||
import com.ddf.vodsystem.controllers.dto.Token;
|
||||
import com.ddf.vodsystem.entities.Stream;
|
||||
import com.ddf.vodsystem.entities.User;
|
||||
import com.ddf.vodsystem.exceptions.NotAuthenticated;
|
||||
import com.ddf.vodsystem.services.UserService;
|
||||
@@ -102,4 +104,12 @@ public class UserController {
|
||||
new APIResponse<>(SUCCESS, "Logged out successfully", null)
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping("/me/stream-key")
|
||||
public ResponseEntity<APIResponse<StreamKey>> regenerateStreamKey() {
|
||||
String streamKey = userService.regenerateStreamKey();
|
||||
return ResponseEntity.ok(
|
||||
new APIResponse<>(SUCCESS, "Stream key successfully", new StreamKey(streamKey))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.ddf.vodsystem.controllers.dto;
|
||||
|
||||
public record StreamKey (String streamKey) {
|
||||
}
|
||||
@@ -78,8 +78,8 @@ public class MarkerService {
|
||||
* @return the persisted {@link Marker}
|
||||
* @throws NotStreaming if the user has no active stream to mark
|
||||
*/
|
||||
public Marker create(String message) {
|
||||
Optional<Stream> stream = streamService.getActiveStream();
|
||||
public Marker create(User user, String message) {
|
||||
Optional<Stream> stream = streamService.getActiveStream(user);
|
||||
|
||||
if (stream.isEmpty()) {
|
||||
throw new NotStreaming("User must be streaming to mark");
|
||||
|
||||
@@ -90,19 +90,14 @@ public class StreamService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current user's active (not-yet-ended) stream, if any.
|
||||
* Returns the user's active (not-yet-ended) stream, if any.
|
||||
*
|
||||
* @param user the User object
|
||||
* @return the active {@link Stream}, or empty if the user is not currently streaming
|
||||
* @throws NotAuthenticated if no user session is present
|
||||
*/
|
||||
public Optional<Stream> getActiveStream() {
|
||||
Optional<User> user = userService.getLoggedInUser();
|
||||
|
||||
if (user.isEmpty()) {
|
||||
throw new NotAuthenticated("Log in to see user streams");
|
||||
}
|
||||
|
||||
return streamRepository.findByUserAndEndDateIsNull(user.get());
|
||||
public Optional<Stream> getActiveStream(User user) {
|
||||
return streamRepository.findByUserAndEndDateIsNull(user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -98,6 +98,12 @@ public class UserService {
|
||||
return userRepository.findByStreamKey(streamKey);
|
||||
}
|
||||
|
||||
public String regenerateStreamKey(User user) {
|
||||
user.setStreamKey(generateStreamKey());
|
||||
userRepository.saveAndFlush(user);
|
||||
return user.getStreamKey();
|
||||
}
|
||||
|
||||
private User createOrUpdateUser(User user) {
|
||||
Optional<User> existingUser = userRepository.findByGoogleId(user.getGoogleId());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user