feat: message broadcast endpoint mapping

This commit is contained in:
Zhongheng Liu 2025-11-27 14:58:56 +01:00
commit fcc7cfd9ac
Signed by: steven
GPG key ID: F69B980899C1C09D

View file

@ -0,0 +1,30 @@
package server.api;
import commons.Recipe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
@Controller
public class UpdateMessagingController {
private final RecipeController recipeController;
@Autowired
public UpdateMessagingController(
RecipeController recipeController) {
this.recipeController = recipeController;
}
/**
* Mapping for STOMP: <code>SEND /updates/recipe</code>
* @param recipe The request body as a new {@link Recipe} object to update the original into
* @return The updated {@link Recipe} object wrapped in a {@link org.springframework.http.ResponseEntity}.
*/
@MessageMapping("/updates/recipe")
@SendTo("/subscribe/recipe")
public ResponseEntity<Recipe> broadcastRecipeUpdate(Recipe recipe) {
return recipeController.updateRecipe(recipe.getId(), recipe);
}
}