-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AB-xxx] adding server info controller
adding banner changing api endpoints
- Loading branch information
Showing
19 changed files
with
187 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...n/core/core-impl/src/main/java/dev/sheldan/abstracto/core/api/ExceptionHandlerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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; | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; | ||
|
||
@RestControllerAdvice | ||
@Slf4j | ||
public class ExceptionHandlerConfig extends ResponseEntityExceptionHandler { | ||
|
||
@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"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ication/core/core-impl/src/main/java/dev/sheldan/abstracto/core/api/ServerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ation/core/core-int/src/main/java/dev/sheldan/abstracto/core/models/api/GuildDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM alpine:3.19.0 | ||
ADD resources /python/resources | ||
ADD python /python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from __main__ import app | ||
|
||
import requests | ||
import logging | ||
import os | ||
|
||
backend_host = os.getenv('BACKEND_HOST') | ||
backend_port = os.getenv('BACKEND_PORT') | ||
|
||
server_url = f'http://{backend_host}:{backend_port}/servers/v1' | ||
|
||
@app.route('/servers/v1/<serverId>/info') | ||
def get_server_info(serverId): | ||
server = requests.get(f'{server_url}/{serverId}/info') | ||
logging.info(f'returning server info') | ||
return server.text, server.status_code |
File renamed without changes.
17 changes: 7 additions & 10 deletions
17
python/components/experience-tracking/python/endpoints/leaderboard.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
from __main__ import app | ||
|
||
from flask import request, render_template | ||
from flask_cors import cross_origin | ||
import requests | ||
import logging | ||
import os | ||
|
||
backend_host = os.getenv('BACKEND_HOST') | ||
backend_port = os.getenv('BACKEND_PORT') | ||
|
||
leaderboard_url = f'http://{backend_host}:{backend_port}/experience/leaderboard' | ||
leaderboard_url = f'http://{backend_host}:{backend_port}/experience/v1/leaderboards' | ||
|
||
@cross_origin() | ||
@app.route('/experience/api/leaderboard/<serverId>') | ||
@app.route('/experience/v1/leaderboards/<serverId>') | ||
def get_leaderboard(serverId): | ||
page = int(request.args.get('page', 0, type=int)) | ||
size = int(request.args.get('size', 25, type=int)) | ||
leaderboard = requests.get(f'{leaderboard_url}/{serverId}?page={page}&size={size}') | ||
logging.info(f'returning leaderboard for server') | ||
return leaderboard.text | ||
return leaderboard.text, leaderboard.status_code | ||
|
||
@cross_origin() | ||
@app.route('/experience/api/leaderboard/<serverId>/config') | ||
@app.route('/experience/v1/leaderboards/<serverId>/config') | ||
def get_experience_config(serverId): | ||
leaderboard = requests.get(f'{leaderboard_url}/{serverId}/config') | ||
logging.info(f'returning experience config for server') | ||
return leaderboard.text | ||
return leaderboard.text, leaderboard.status_code | ||
|
||
|
||
@app.route('/experience/leaderboard/<serverId>') | ||
@app.route('/experience/leaderboards/<serverId>') | ||
def render_index(serverId): | ||
return render_template('experience/leaderboard/index.html', serverId=serverId) | ||
return render_template('experience/leaderboards/index.html', serverId=serverId) |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.