[AB-xxx] initial experience leaderboard version

This commit is contained in:
Sheldan
2024-03-25 20:39:21 +01:00
parent 8f9b7eba16
commit bc0c3a18d7
46 changed files with 17561 additions and 1 deletions

View File

@@ -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");
}
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,13 @@
package dev.sheldan.abstracto.core.models.api;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
public class GuildDisplay {
private Long id;
private String name;
private String iconUrl;
private String bannerUrl;
}

View File

@@ -0,0 +1,35 @@
package dev.sheldan.abstracto.core.models.frontend;
import dev.sheldan.abstracto.core.models.database.ARole;
import lombok.Builder;
import lombok.Getter;
import net.dv8tion.jda.api.entities.Role;
import java.awt.*;
@Getter
@Builder
public class RoleDisplay {
private Long id;
private String name;
private Integer r;
private Integer g;
private Integer b;
public static RoleDisplay fromRole(Role role) {
RoleDisplayBuilder builder = builder()
.name(role.getName());
Color roleColor = role.getColor();
if(roleColor != null) {
builder.r(roleColor.getRed()).
b(roleColor.getBlue())
.g(roleColor.getGreen());
}
return builder.build();
}
public static RoleDisplay fromARole(ARole role) {
return builder()
.id(role.getId())
.build();
}
}

View File

@@ -0,0 +1,21 @@
package dev.sheldan.abstracto.core.models.frontend;
import lombok.Builder;
import lombok.Getter;
import net.dv8tion.jda.api.entities.Member;
@Getter
@Builder
public class UserDisplay {
private String avatarUrl;
private String name;
private Long id;
public static UserDisplay fromMember(Member member) {
return builder()
.avatarUrl(member.getEffectiveAvatarUrl())
.name(member.getEffectiveName())
.id(member.getIdLong())
.build();
}
}