【发布时间】:2021-12-14 18:53:39
【问题描述】:
我有一个 Spring MVC 控制器,但我不确定它的设计是好是坏。据我所知,缺少 api 版本控制,但除此之外,我为文档实现了 Swagger 并添加了 SpringSecurity 并尝试遵循 YARAS(Yet Another RESTful API Standard) 来构建它,但我需要另一个眼睛来评论它。
@Slf4j
@Controller
@RequestMapping
@RequiredArgsConstructor
public class XGameController implements GameController {
private final GameService gameService;
private final ObjectMapper mapper;
@RequestMapping(value = "/", method= RequestMethod.GET)
public String index() {
return "game";
}
@RequestMapping(value = "/login", method= RequestMethod.GET)
public String login() {
return "login";
}
@Secured("ROLE_USER")
@RequestMapping(value = "/games", method= RequestMethod.POST)
public String initializeGame(Model model) {
log.info("New XGame is initializing...");
Game game = new Game();
game = gameService.initializeGame(game.getId());
try {
model.addAttribute("game", mapper.writeValueAsString(game));
} catch (JsonProcessingException e) {
log.error(e.getMessage());
}
log.info("New XGame is initialized successfully!");
return "game";
}
@Secured("ROLE_USER")
@RequestMapping(value = "/games/{gameId}", method= RequestMethod.PUT)
public @ResponseBody Game play(@PathVariable("gameId") String gameId,
@RequestParam Integer pitNumber,
@RequestParam String action) {
log.info("Sowing stone is triggered...");
return gameService.executeGameRules(UUID.fromString(gameId), pitNumber);
}
@RequestMapping(value = "/403", method= RequestMethod.GET)
public String error403() {
return "/error/403";
}
}
我的大摇大摆的快照;
【问题讨论】:
-
您应该将此问题发送给codereview.stackexchange.com以获得更好的答案
-
如果您在 Code Review 上发帖,请阅读帮助中心页面,例如 How do I ask a good question? - 那里的期望略有不同。
标签: java spring spring-boot api spring-mvc