mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-24 13:44:33 +00:00
[AB-xxx] initial experience leaderboard version
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package dev.sheldan.abstracto.core.api;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.GuildNotFoundException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class ExceptionHandlerConfig {
|
||||
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
@ExceptionHandler(GuildNotFoundException.class)
|
||||
protected ResponseEntity<String> handleResourceNotFound(GuildNotFoundException ex){
|
||||
log.warn("Server not found.", ex);
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.NOT_FOUND)
|
||||
.body("Server not found");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package dev.sheldan.abstracto.core.api;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.api.GuildDisplay;
|
||||
import dev.sheldan.abstracto.core.service.GuildService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/servers/v1/")
|
||||
public class ServerController {
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Autowired
|
||||
private GuildService guildService;
|
||||
|
||||
@GetMapping(value = "/{serverId}/info", produces = "application/json")
|
||||
public GuildDisplay getLeaderboard(@PathVariable("serverId") Long serverId) {
|
||||
serverManagementService.loadServer(serverId); // only used for verification if it exists in the db
|
||||
Guild guild = guildService.getGuildById(serverId);
|
||||
return GuildDisplay
|
||||
.builder()
|
||||
.name(guild.getName())
|
||||
.id(guild.getIdLong())
|
||||
.bannerUrl(guild.getBannerUrl())
|
||||
.iconUrl(guild.getIconUrl())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user