mirror of
https://github.com/arcan1s/ffxivbis.git
synced 2025-07-07 02:45:52 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
88617eccdf | |||
ccbf581332 | |||
0ab9162cb5 | |||
d3018998cd | |||
d4553b2e50 | |||
8496d105c0 | |||
ec2cfaea38 | |||
963e84f792 | |||
feea01a47e | |||
fcacd9f15c | |||
b2256784dd | |||
fee87ddbc8 | |||
dc882b74bf | |||
7a6cd84ce3 | |||
33b750123d |
@ -7,4 +7,3 @@ scalaVersion := "2.13.6"
|
||||
scalacOptions ++= Seq("-deprecation", "-feature")
|
||||
|
||||
enablePlugins(JavaAppPackaging)
|
||||
coverageEnabled := true
|
||||
|
@ -12,6 +12,7 @@ libraryDependencies += "com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion
|
||||
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % AkkaVersion
|
||||
libraryDependencies += "com.github.swagger-akka-http" %% "swagger-akka-http" % "2.6.0"
|
||||
libraryDependencies += "jakarta.platform" % "jakarta.jakartaee-web-api" % "9.1.0"
|
||||
libraryDependencies += "ch.megard" %% "akka-http-cors" % "1.1.2"
|
||||
|
||||
libraryDependencies += "io.spray" %% "spray-json" % "1.3.6"
|
||||
|
||||
|
23
src/main/resources/html/api.html
Normal file
23
src/main/resources/html/api.html
Normal file
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>FFXIV loot helper API</title>
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<!-- Embed elements Elements via Web Component -->
|
||||
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
|
||||
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css" type="text/css">
|
||||
|
||||
<link rel="shortcut icon" href="/static/favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<elements-api
|
||||
apiDescriptionUrl="/api-docs/swagger.json"
|
||||
router="hash"
|
||||
layout="sidebar"
|
||||
/>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -6,17 +6,17 @@
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link href="/static/favicon.ico" rel="shortcut icon">
|
||||
<link rel="shortcut icon" href="/static/favicon.ico">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" type="text/css">
|
||||
|
||||
<link href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" type="text/css">
|
||||
|
||||
|
||||
<link href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" type="text/css">
|
||||
|
||||
<link href="/static/styles.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="/static/styles.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -86,23 +86,24 @@
|
||||
|
||||
<div id="update-bis-dialog" tabindex="-1" role="dialog" class="modal fade">
|
||||
<div class="modal-dialog" role="document">
|
||||
<form class="modal-content">
|
||||
<div class="modal-header">
|
||||
<form class="modal-content" action="javascript:" onsubmit="updateBis()">
|
||||
<div class="modal-header form-group row">
|
||||
<div class="btn-group" role="group" aria-label="Update bis">
|
||||
<input id="add-piece-btn" name="update-bis" type="radio" class="btn-check" autocomplete="off" checked>
|
||||
<label class="btn btn-outline-primary" for="add-piece-btn">add piece</label>
|
||||
|
||||
<input id="update-bis-btn" name="update-bis" type="radio" class="btn-check" autocomplete="off">
|
||||
<label class="btn btn-outline-primary" for="update-bis-btn">update bis</label>
|
||||
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
|
||||
</div>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="player">player</label>
|
||||
<div class="col-sm-8">
|
||||
<select id="player" name="player" class="form-control" title="player"></select>
|
||||
<select id="player" name="player" class="form-control" title="player" required></select>
|
||||
</div>
|
||||
</div>
|
||||
<div id="piece-row" class="form-group row">
|
||||
@ -120,14 +121,14 @@
|
||||
<div id="bis-link-row" class="form-group row" style="display: none">
|
||||
<label class="col-sm-4 col-form-label" for="bis-link">link</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="bis-link" name="link" class="form-control" placeholder="link to bis" onkeyup="disableSubmitBisButton()">
|
||||
<input id="bis-link" name="link" class="form-control" placeholder="link to bis">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">close</button>
|
||||
<button id="submit-add-bis-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="addPiece()" disabled>add</button>
|
||||
<button id="submit-update-bis-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="setBis()" style="display: none" disabled>set</button>
|
||||
<button id="submit-add-bis-btn" type="submit" class="btn btn-primary">add</button>
|
||||
<button id="submit-set-bis-btn" type="submit" class="btn btn-primary" style="display: none">set</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@ -138,6 +139,7 @@
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
|
||||
<ul class="nav">
|
||||
<li><a class="nav-link" href="/" title="home">home</a></li>
|
||||
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
|
||||
</ul>
|
||||
|
||||
<ul class="nav">
|
||||
@ -171,7 +173,7 @@
|
||||
const updateButton = $("#update-btn");
|
||||
|
||||
const submitAddBisButton = $("#submit-add-bis-btn");
|
||||
const submitUpdateBisButton = $("#submit-update-bis-btn");
|
||||
const submitSetBisButton = $("#submit-set-bis-btn");
|
||||
const updateBisDialog = $("#update-bis-dialog");
|
||||
|
||||
const addPieceButton = $("#add-piece-btn");
|
||||
@ -208,12 +210,8 @@
|
||||
success: function (_) { reload(); },
|
||||
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
|
||||
});
|
||||
}
|
||||
|
||||
function disableSubmitBisButton() {
|
||||
const nonEmpty = (playerInput.val() !== null); // well lol
|
||||
submitUpdateBisButton.attr("disabled", !(nonEmpty && linkInput.val()));
|
||||
submitAddBisButton.attr("disabled", !(nonEmpty));
|
||||
updateBisDialog.modal("hide");
|
||||
return true; // action expects boolean result
|
||||
}
|
||||
|
||||
function hideControls() {
|
||||
@ -222,20 +220,24 @@
|
||||
}
|
||||
|
||||
function hideLinkPart() {
|
||||
disableSubmitBisButton();
|
||||
bisLinkRow.hide();
|
||||
submitUpdateBisButton.hide();
|
||||
linkInput.prop("required", false);
|
||||
submitSetBisButton.hide();
|
||||
pieceRow.show();
|
||||
pieceTypeRow.show();
|
||||
pieceInput.prop("required", true);
|
||||
pieceTypeInput.prop("required", true);
|
||||
submitAddBisButton.show();
|
||||
}
|
||||
|
||||
function hidePiecePart() {
|
||||
disableSubmitBisButton();
|
||||
bisLinkRow.show();
|
||||
submitUpdateBisButton.show();
|
||||
linkInput.prop("required", true);
|
||||
submitSetBisButton.show();
|
||||
pieceRow.hide();
|
||||
pieceTypeRow.hide();
|
||||
pieceInput.prop("required", false);
|
||||
pieceTypeInput.prop("required", false);
|
||||
submitAddBisButton.hide();
|
||||
}
|
||||
|
||||
@ -269,7 +271,6 @@
|
||||
return option;
|
||||
});
|
||||
playerInput.empty().append(options);
|
||||
disableSubmitBisButton();
|
||||
},
|
||||
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
|
||||
});
|
||||
@ -327,6 +328,18 @@
|
||||
success: function (_) { reload(); },
|
||||
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
|
||||
});
|
||||
updateBisDialog.modal("hide");
|
||||
return true; // action expects boolean result
|
||||
}
|
||||
|
||||
function updateBis() {
|
||||
if (updateBisButton.is(":checked")) {
|
||||
return setBis();
|
||||
}
|
||||
if (addPieceButton.is(":checked")) {
|
||||
return addPiece();
|
||||
}
|
||||
return false; // should not happen
|
||||
}
|
||||
|
||||
$(function () {
|
||||
@ -344,6 +357,7 @@
|
||||
|
||||
table.bootstrapTable({});
|
||||
reload();
|
||||
reset();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -6,11 +6,11 @@
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link href="/static/favicon.ico" rel="shortcut icon">
|
||||
<link rel="shortcut icon" href="/static/favicon.ico">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
|
||||
<link href="/static/styles.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="/static/styles.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -71,7 +71,9 @@
|
||||
|
||||
<div class="container">
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
|
||||
<ul class="nav"></ul>
|
||||
<ul class="nav">
|
||||
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
|
||||
</ul>
|
||||
|
||||
<ul class="nav">
|
||||
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
|
||||
@ -122,7 +124,7 @@
|
||||
password: passwordInput.val(),
|
||||
permission: "admin",
|
||||
}),
|
||||
type: "PUT",
|
||||
type: "POST",
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
|
@ -6,17 +6,17 @@
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link href="/static/favicon.ico" rel="shortcut icon">
|
||||
<link rel="shortcut icon" href="/static/favicon.ico">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" type="text/css">
|
||||
|
||||
<link href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" type="text/css">
|
||||
|
||||
|
||||
<link href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" type="text/css">
|
||||
|
||||
<link href="/static/styles.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="/static/styles.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -88,35 +88,35 @@
|
||||
|
||||
<div id="add-loot-dialog" tabindex="-1" role="dialog" class="modal fade">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<form class="modal-content" action="javascript:" onsubmit="addLoot()">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">add looted piece</h4>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
|
||||
</div>
|
||||
|
||||
<form class="modal-body">
|
||||
<div class="modal-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="player">player</label>
|
||||
<div class="col-sm-8">
|
||||
<select id="player" name="player" class="form-control" title="player"></select>
|
||||
<select id="player" name="player" class="form-control" title="player" required></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="piece">piece</label>
|
||||
<div class="col-sm-8">
|
||||
<select id="piece" name="piece" class="form-control" title="piece"></select>
|
||||
<select id="piece" name="piece" class="form-control" title="piece" required></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="piece-type">piece type</label>
|
||||
<div class="col-sm-8">
|
||||
<select id="piece-type" name="pieceType" class="form-control" title="pieceType"></select>
|
||||
<select id="piece-type" name="pieceType" class="form-control" title="pieceType" required></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="job">job</label>
|
||||
<div class="col-sm-8">
|
||||
<select id="job" name="job" class="form-control" title="job"></select>
|
||||
<select id="job" name="job" class="form-control" title="job" required></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
@ -141,14 +141,14 @@
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">close</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="suggestLoot()">suggest</button>
|
||||
<button id="submit-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="addLoot()" disabled>add</button>
|
||||
<button type="submit" class="btn btn-primary">add</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -156,6 +156,7 @@
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
|
||||
<ul class="nav">
|
||||
<li><a class="nav-link" href="/" title="home">home</a></li>
|
||||
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
|
||||
</ul>
|
||||
|
||||
<ul class="nav">
|
||||
@ -189,7 +190,6 @@
|
||||
const addButton = $("#add-btn");
|
||||
const removeButton = $("#remove-btn");
|
||||
|
||||
const submitLootButton = $("#submit-btn");
|
||||
const addLootDialog = $("#add-loot-dialog");
|
||||
|
||||
const freeLootInput = $("#free-loot");
|
||||
@ -221,6 +221,8 @@
|
||||
success: function (_) { reload(); },
|
||||
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
|
||||
});
|
||||
addLootDialog.modal("hide");
|
||||
return true; // action expects boolean result
|
||||
}
|
||||
|
||||
function hideControls() {
|
||||
@ -260,7 +262,6 @@
|
||||
return option;
|
||||
});
|
||||
playerInput.empty().append(options);
|
||||
submitLootButton.attr("disabled", options.length === 0);
|
||||
},
|
||||
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
|
||||
});
|
||||
@ -310,7 +311,7 @@
|
||||
return {
|
||||
nick: stat.nick,
|
||||
job: stat.job,
|
||||
isRequired: stat.isRequired,
|
||||
isRequired: stat.isRequired ? "yes" : "no",
|
||||
lootCount: stat.lootCount,
|
||||
lootCountBiS: stat.lootCountBiS,
|
||||
lootCountTotal: stat.lootCountTotal,
|
||||
|
@ -6,17 +6,17 @@
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link href="/static/favicon.ico" rel="shortcut icon">
|
||||
<link rel="shortcut icon" href="/static/favicon.ico">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" type="text/css">
|
||||
|
||||
<link href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" type="text/css">
|
||||
|
||||
|
||||
<link href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" type="text/css">
|
||||
|
||||
<link href="/static/styles.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="/static/styles.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -84,23 +84,23 @@
|
||||
|
||||
<div id="add-player-dialog" tabindex="-1" role="dialog" class="modal fade">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<form class="modal-content" action="javascript:" onsubmit="addPlayer()">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">add new player</h4>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
|
||||
</div>
|
||||
|
||||
<form class="modal-body">
|
||||
<div class="modal-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="nick">player name</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="nick" name="nick" class="form-control" placeholder="nick" onkeyup="disableAddPlayerForm()">
|
||||
<input id="nick" name="nick" class="form-control" placeholder="nick" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="job">player job</label>
|
||||
<div class="col-sm-8">
|
||||
<select id="job" name="job" class="form-control" title="job"></select>
|
||||
<select id="job" name="job" class="form-control" title="job" required></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
@ -115,13 +115,13 @@
|
||||
<input id="priority" name="priority" type="number" class="form-control" value="0">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">close</button>
|
||||
<button id="submit-player-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="addPlayer()" disabled>add</button>
|
||||
<button type="submit" class="btn btn-primary">add</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -129,6 +129,7 @@
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
|
||||
<ul class="nav">
|
||||
<li><a class="nav-link" href="/" title="home">home</a></li>
|
||||
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
|
||||
</ul>
|
||||
|
||||
<ul class="nav">
|
||||
@ -162,7 +163,6 @@
|
||||
const removeButton = $("#remove-btn");
|
||||
|
||||
const addPlayerDialog = $("#add-player-dialog");
|
||||
const submitPlayerButton = $("#submit-player-btn");
|
||||
|
||||
const jobInput = $("#job");
|
||||
const linkInput = $("#link");
|
||||
@ -187,6 +187,8 @@
|
||||
success: function (_) { reload(); },
|
||||
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
|
||||
});
|
||||
addPlayerDialog.modal("hide");
|
||||
return true; // action expects boolean result
|
||||
}
|
||||
|
||||
function bisLinkFormatter(link, row) {
|
||||
@ -197,10 +199,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function disableAddPlayerForm() {
|
||||
submitPlayerButton.attr("disabled", !nickInput.val());
|
||||
}
|
||||
|
||||
function hideControls() {
|
||||
addButton.attr("hidden", isReadOnly);
|
||||
removeButton.attr("hidden", isReadOnly);
|
||||
|
@ -1,19 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>FFXIV loot helper API</title>
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet" type="text/css">
|
||||
|
||||
<link href="/static/favicon.ico" rel="shortcut icon">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<redoc spec-url="/api-docs/swagger.json"></redoc>
|
||||
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -6,17 +6,17 @@
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link href="/static/favicon.ico" rel="shortcut icon">
|
||||
<link rel="shortcut icon" href="/static/favicon.ico">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" type="text/css">
|
||||
|
||||
<link href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" type="text/css">
|
||||
|
||||
|
||||
<link href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" type="text/css">
|
||||
|
||||
<link href="/static/styles.css" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="/static/styles.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -84,38 +84,38 @@
|
||||
|
||||
<div id="add-user-dialog" tabindex="-1" role="dialog" class="modal fade">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<form class="modal-content" action="javascript:" onsubmit="addUser()">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">add new user</h4>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
|
||||
</div>
|
||||
|
||||
<form class="modal-body">
|
||||
<div class="modal-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="username">login</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="username" name="username" class="form-control" placeholder="username" onkeyup="disableAddUserForm()">
|
||||
<input id="username" name="username" class="form-control" placeholder="username" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="password">password</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="password" name="password" type="password" class="form-control" placeholder="password" onkeyup="disableAddUserForm()">
|
||||
<input id="password" name="password" type="password" class="form-control" placeholder="password" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-4 col-form-label" for="permission">permission</label>
|
||||
<div class="col-sm-8">
|
||||
<select id="permission" name="permission" class="form-control" title="permission"></select>
|
||||
<select id="permission" name="permission" class="form-control" title="permission" required></select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">close</button>
|
||||
<button id="submit-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="addUser()" disabled>add</button>
|
||||
<button type="submit" class="btn btn-primary">add</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -123,6 +123,7 @@
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
|
||||
<ul class="nav">
|
||||
<li><a class="nav-link" href="/" title="home">home</a></li>
|
||||
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
|
||||
</ul>
|
||||
|
||||
<ul class="nav">
|
||||
@ -156,7 +157,6 @@
|
||||
const removeButton = $("#remove-btn");
|
||||
|
||||
const addUserDialog = $("#add-user-dialog");
|
||||
const submitUserButton = $("#submit-btn");
|
||||
|
||||
const usernameInput = $("#username");
|
||||
const passwordInput = $("#password");
|
||||
@ -176,10 +176,8 @@
|
||||
success: function (_) { reload(); },
|
||||
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
|
||||
});
|
||||
}
|
||||
|
||||
function disableAddUserForm() {
|
||||
submitUserButton.attr("disabled", !(usernameInput.val() && passwordInput.val()));
|
||||
addUserDialog.modal("hide");
|
||||
return true; // action expects boolean result
|
||||
}
|
||||
|
||||
function hideControls() {
|
||||
|
@ -50,6 +50,7 @@ me.arcanis.ffxivbis {
|
||||
#hostname = "127.0.0.1:8000"
|
||||
# enable head requests for GET requests
|
||||
enable-head-requests = yes
|
||||
schemes = ["http"]
|
||||
|
||||
authorization-cache {
|
||||
# maximum amount of cached logins
|
||||
|
@ -37,7 +37,7 @@ function loadTypes(url, selector) {
|
||||
}
|
||||
|
||||
function setupFormClear(dialog, reset) {
|
||||
dialog.on("shown.bs.modal", function () {
|
||||
dialog.on("hide.bs.modal", function () {
|
||||
$(this).find("form").trigger("reset");
|
||||
$(this).find("table").bootstrapTable("removeAll");
|
||||
if (reset) {
|
||||
|
@ -50,7 +50,7 @@ class Application(context: ActorContext[Nothing]) extends AbstractBehavior[Nothi
|
||||
val party = context.spawn(PartyService(storage), "party")
|
||||
val http = new RootEndpoint(context.system, party, bisProvider)
|
||||
|
||||
val flow = Route.toFlow(http.route)(context.system)
|
||||
val flow = Route.toFlow(http.routes)(context.system)
|
||||
Http(context.system).newServerAt(host, port).bindFlow(flow)
|
||||
|
||||
case Success(result) =>
|
||||
|
@ -37,23 +37,16 @@ trait Authorization {
|
||||
def authAdmin(partyId: String)(username: String, password: String)(implicit
|
||||
executionContext: ExecutionContext
|
||||
): Future[Option[User]] =
|
||||
authenticator(Permission.admin, partyId)(username, password)
|
||||
auth.authenticator(Permission.admin, partyId)(username, password)
|
||||
|
||||
def authGet(partyId: String)(username: String, password: String)(implicit
|
||||
executionContext: ExecutionContext
|
||||
): Future[Option[User]] =
|
||||
authenticator(Permission.get, partyId)(username, password)
|
||||
auth.authenticator(Permission.get, partyId)(username, password)
|
||||
|
||||
def authPost(partyId: String)(username: String, password: String)(implicit
|
||||
executionContext: ExecutionContext
|
||||
): Future[Option[User]] =
|
||||
authenticator(Permission.post, partyId)(username, password)
|
||||
auth.authenticator(Permission.post, partyId)(username, password)
|
||||
|
||||
private def authenticator(scope: Permission.Value, partyId: String)(username: String, password: String)(implicit
|
||||
executionContext: ExecutionContext
|
||||
): Future[Option[User]] =
|
||||
auth.get(partyId, username).map {
|
||||
case Some(user) if user.verify(password) && user.verityScope(scope) => Some(user)
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
|
@ -14,19 +14,31 @@ import akka.util.Timeout
|
||||
import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache}
|
||||
import com.typesafe.config.Config
|
||||
import me.arcanis.ffxivbis.messages.{GetUser, Message}
|
||||
import me.arcanis.ffxivbis.models.User
|
||||
import me.arcanis.ffxivbis.models.{Permission, User}
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
import scala.concurrent.Future
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
trait AuthorizationProvider {
|
||||
|
||||
def get(partyId: String, username: String): Future[Option[User]]
|
||||
|
||||
def authenticator[T](scope: Permission.Value, partyId: String)(username: String, password: String)(implicit
|
||||
executionContext: ExecutionContext,
|
||||
extractor: User => T
|
||||
): Future[Option[T]] =
|
||||
get(partyId, username).map {
|
||||
case Some(user) if user.verify(password) && user.verityScope(scope) => Some(extractor(user))
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
|
||||
object AuthorizationProvider {
|
||||
|
||||
def apply(config: Config, storage: ActorRef[Message], timeout: Timeout, scheduler: Scheduler): AuthorizationProvider =
|
||||
def apply(config: Config, storage: ActorRef[Message])(implicit
|
||||
timeout: Timeout,
|
||||
scheduler: Scheduler
|
||||
): AuthorizationProvider =
|
||||
new AuthorizationProvider {
|
||||
private val cacheSize = config.getInt("me.arcanis.ffxivbis.web.authorization-cache.cache-size")
|
||||
private val cacheTimeout =
|
||||
|
@ -12,6 +12,7 @@ import akka.actor.typed.{ActorRef, ActorSystem, Scheduler}
|
||||
import akka.http.scaladsl.server.Directives._
|
||||
import akka.http.scaladsl.server._
|
||||
import akka.util.Timeout
|
||||
import ch.megard.akka.http.cors.scaladsl.CorsDirectives.cors
|
||||
import com.typesafe.scalalogging.StrictLogging
|
||||
import me.arcanis.ffxivbis.http.api.v1.RootApiV1Endpoint
|
||||
import me.arcanis.ffxivbis.http.view.RootView
|
||||
@ -27,34 +28,36 @@ class RootEndpoint(system: ActorSystem[Nothing], storage: ActorRef[Message], pro
|
||||
implicit val scheduler: Scheduler = system.scheduler
|
||||
implicit val timeout: Timeout = config.getTimeout("me.arcanis.ffxivbis.settings.request-timeout")
|
||||
|
||||
private val auth = AuthorizationProvider(config, storage, timeout, scheduler)
|
||||
private val auth = AuthorizationProvider(config, storage)
|
||||
|
||||
private val rootApiV1Endpoint = new RootApiV1Endpoint(storage, auth, provider, config)
|
||||
private val rootView = new RootView(auth)
|
||||
private val swagger = new Swagger(config)
|
||||
|
||||
def route: Route =
|
||||
def routes: Route =
|
||||
withHttpLog {
|
||||
ignoreTrailingSlash {
|
||||
apiRoute ~ htmlRoute ~ swagger.routes ~ swaggerUIRoute
|
||||
cors() {
|
||||
apiRoutes ~ htmlRoutes ~ swagger.routes ~ swaggerUIRoutes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def apiRoute: Route =
|
||||
private def apiRoutes: Route =
|
||||
pathPrefix("api") {
|
||||
pathPrefix(Segment) {
|
||||
case "v1" => rootApiV1Endpoint.route
|
||||
case "v1" => rootApiV1Endpoint.routes
|
||||
case _ => reject
|
||||
}
|
||||
}
|
||||
|
||||
private def htmlRoute: Route =
|
||||
private def htmlRoutes: Route =
|
||||
pathPrefix("static") {
|
||||
getFromResourceDirectory("static")
|
||||
} ~ rootView.route
|
||||
} ~ rootView.routes
|
||||
|
||||
private def swaggerUIRoute: Route =
|
||||
private def swaggerUIRoutes: Route =
|
||||
path("api-docs") {
|
||||
getFromResource("html/redoc.html")
|
||||
getFromResource("html/api.html")
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import com.typesafe.config.Config
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme
|
||||
|
||||
import scala.io.Source
|
||||
import scala.jdk.CollectionConverters._
|
||||
|
||||
class Swagger(config: Config) extends SwaggerHttpService {
|
||||
|
||||
@ -38,13 +39,15 @@ class Swagger(config: Config) extends SwaggerHttpService {
|
||||
if (config.hasPath("me.arcanis.ffxivbis.web.hostname")) config.getString("me.arcanis.ffxivbis.web.hostname")
|
||||
else s"${config.getString("me.arcanis.ffxivbis.web.host")}:${config.getInt("me.arcanis.ffxivbis.web.port")}"
|
||||
|
||||
override val schemes: List[String] = config.getStringList("me.arcanis.ffxivbis.web.schemes").asScala.toList
|
||||
|
||||
private val basicAuth = new SecurityScheme()
|
||||
.description("basic http auth")
|
||||
.`type`(SecurityScheme.Type.HTTP)
|
||||
.in(SecurityScheme.In.HEADER)
|
||||
.scheme("bearer")
|
||||
override val securitySchemes: Map[String, SecurityScheme] = Map("basic auth" -> basicAuth)
|
||||
.scheme("basic")
|
||||
override val securitySchemes: Map[String, SecurityScheme] = Map("basic" -> basicAuth)
|
||||
|
||||
override val unwantedDefinitions: Seq[String] =
|
||||
Seq("Function1", "Function1RequestContextFutureRouteResult")
|
||||
Seq("Function1", "Function1RequestContextFutureRouteResult", "SeqLootModel", "SeqPieceModel")
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class BiSEndpoint(
|
||||
with Authorization
|
||||
with JsonSupport {
|
||||
|
||||
def route: Route = createBiS ~ getBiS ~ modifyBiS
|
||||
def routes: Route = createBiS ~ getBiS ~ modifyBiS
|
||||
|
||||
@PUT
|
||||
@Path("party/{partyId}/bis")
|
||||
@ -79,7 +79,7 @@ class BiSEndpoint(
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
|
||||
tags = Array("best in slot"),
|
||||
)
|
||||
def createBiS: Route =
|
||||
@ -140,7 +140,7 @@ class BiSEndpoint(
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
|
||||
tags = Array("best in slot"),
|
||||
)
|
||||
def getBiS: Route =
|
||||
@ -197,7 +197,7 @@ class BiSEndpoint(
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
|
||||
tags = Array("best in slot"),
|
||||
)
|
||||
def modifyBiS: Route =
|
||||
|
@ -11,6 +11,7 @@ package me.arcanis.ffxivbis.http.api.v1
|
||||
import akka.http.scaladsl.model._
|
||||
import akka.http.scaladsl.server.Directives._
|
||||
import akka.http.scaladsl.server._
|
||||
import ch.megard.akka.http.cors.scaladsl.CorsDirectives.corsRejectionHandler
|
||||
import com.typesafe.scalalogging.StrictLogging
|
||||
import me.arcanis.ffxivbis.http.api.v1.json._
|
||||
import spray.json._
|
||||
@ -27,9 +28,26 @@ trait HttpHandler extends StrictLogging { this: JsonSupport =>
|
||||
}
|
||||
|
||||
def rejectionHandler: RejectionHandler =
|
||||
RejectionHandler.default
|
||||
RejectionHandler
|
||||
.newBuilder()
|
||||
.handleAll[MethodRejection] { rejections =>
|
||||
val (methods, names) = rejections.map(r => r.supported -> r.supported.name).unzip
|
||||
|
||||
respondWithHeader(headers.Allow(methods)) {
|
||||
options {
|
||||
complete(StatusCodes.OK, HttpEntity.Empty)
|
||||
} ~
|
||||
complete(
|
||||
StatusCodes.MethodNotAllowed,
|
||||
s"HTTP method not allowed, supported methods: ${names.mkString(", ")}"
|
||||
)
|
||||
}
|
||||
}
|
||||
.result()
|
||||
.withFallback(corsRejectionHandler)
|
||||
.seal
|
||||
.mapRejectionResponse {
|
||||
case response @ HttpResponse(_, _, entity: HttpEntity.Strict, _) =>
|
||||
case response @ HttpResponse(_, _, entity: HttpEntity.Strict, _) if entity.data.nonEmpty =>
|
||||
val message = ErrorModel(entity.data.utf8String).toJson
|
||||
response.withEntity(HttpEntity(ContentTypes.`application/json`, message.compactPrint))
|
||||
case other => other
|
||||
|
@ -37,7 +37,7 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
with JsonSupport
|
||||
with HttpHandler {
|
||||
|
||||
def route: Route = getLoot ~ modifyLoot ~ suggestLoot
|
||||
def routes: Route = getLoot ~ modifyLoot ~ suggestLoot
|
||||
|
||||
@GET
|
||||
@Path("party/{partyId}/loot")
|
||||
@ -81,7 +81,7 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
|
||||
tags = Array("loot"),
|
||||
)
|
||||
def getLoot: Route =
|
||||
@ -137,7 +137,7 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
|
||||
tags = Array("loot"),
|
||||
)
|
||||
def modifyLoot: Route =
|
||||
@ -202,7 +202,7 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
|
||||
tags = Array("loot"),
|
||||
)
|
||||
def suggestLoot: Route =
|
||||
|
@ -40,7 +40,7 @@ class PartyEndpoint(
|
||||
with JsonSupport
|
||||
with HttpHandler {
|
||||
|
||||
def route: Route = getPartyDescription ~ modifyPartyDescription
|
||||
def routes: Route = getPartyDescription ~ modifyPartyDescription
|
||||
|
||||
@GET
|
||||
@Path("party/{partyId}/description")
|
||||
@ -73,7 +73,7 @@ class PartyEndpoint(
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
|
||||
tags = Array("party"),
|
||||
)
|
||||
def getPartyDescription: Route =
|
||||
@ -126,7 +126,7 @@ class PartyEndpoint(
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
|
||||
tags = Array("party"),
|
||||
)
|
||||
def modifyPartyDescription: Route =
|
||||
|
@ -41,7 +41,7 @@ class PlayerEndpoint(
|
||||
with JsonSupport
|
||||
with HttpHandler {
|
||||
|
||||
def route: Route = getParty ~ getPartyStats ~ modifyParty
|
||||
def routes: Route = getParty ~ getPartyStats ~ modifyParty
|
||||
|
||||
@GET
|
||||
@Path("party/{partyId}")
|
||||
@ -85,7 +85,7 @@ class PlayerEndpoint(
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
|
||||
tags = Array("party"),
|
||||
)
|
||||
def getParty: Route =
|
||||
@ -146,7 +146,7 @@ class PlayerEndpoint(
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
|
||||
tags = Array("party"),
|
||||
)
|
||||
def getPartyStats: Route =
|
||||
@ -202,7 +202,7 @@ class PlayerEndpoint(
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
|
||||
tags = Array("party"),
|
||||
)
|
||||
def modifyParty: Route =
|
||||
|
@ -36,11 +36,11 @@ class RootApiV1Endpoint(
|
||||
private val typesEndpoint = new TypesEndpoint(config)
|
||||
private val userEndpoint = new UserEndpoint(storage, auth)
|
||||
|
||||
def route: Route =
|
||||
def routes: Route =
|
||||
handleExceptions(exceptionHandler) {
|
||||
handleRejections(rejectionHandler) {
|
||||
biSEndpoint.route ~ lootEndpoint.route ~ partyEndpoint.route ~ playerEndpoint.route ~
|
||||
statusEndpoint.route ~ typesEndpoint.route ~ userEndpoint.route
|
||||
biSEndpoint.routes ~ lootEndpoint.routes ~ partyEndpoint.routes ~ playerEndpoint.routes ~
|
||||
statusEndpoint.routes ~ typesEndpoint.routes ~ userEndpoint.routes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import me.arcanis.ffxivbis.http.api.v1.json._
|
||||
@Path("/api/v1")
|
||||
class StatusEndpoint extends JsonSupport {
|
||||
|
||||
def route: Route = getServerStatus
|
||||
def routes: Route = getServerStatus
|
||||
|
||||
@GET
|
||||
@Path("status")
|
||||
|
@ -21,7 +21,7 @@ import me.arcanis.ffxivbis.models._
|
||||
@Path("/api/v1")
|
||||
class TypesEndpoint(config: Config) extends JsonSupport {
|
||||
|
||||
def route: Route = getAllJobs ~ getJobs ~ getPermissions ~ getPieces ~ getPieceTypes ~ getPriority
|
||||
def routes: Route = getAllJobs ~ getJobs ~ getPermissions ~ getPieces ~ getPieceTypes ~ getPriority
|
||||
|
||||
@GET
|
||||
@Path("types/jobs/all")
|
||||
|
@ -36,9 +36,9 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
with Authorization
|
||||
with JsonSupport {
|
||||
|
||||
def route: Route = createParty ~ createUser ~ deleteUser ~ getUsers ~ getUsersCurrent
|
||||
def routes: Route = createParty ~ createUser ~ deleteUser ~ getUsers ~ getUsersCurrent
|
||||
|
||||
@PUT
|
||||
@POST
|
||||
@Path("party")
|
||||
@Consumes(value = Array("application/json"))
|
||||
@Operation(
|
||||
@ -76,7 +76,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
def createParty: Route =
|
||||
path("party") {
|
||||
extractExecutionContext { implicit executionContext =>
|
||||
put {
|
||||
post {
|
||||
entity(as[UserModel]) { user =>
|
||||
onSuccess(newPartyId) { partyId =>
|
||||
val admin = user.toUser.copy(partyId = partyId, permission = Permission.admin)
|
||||
@ -126,7 +126,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("admin"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("admin"))),
|
||||
tags = Array("users"),
|
||||
)
|
||||
def createUser: Route =
|
||||
@ -172,7 +172,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("admin"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("admin"))),
|
||||
tags = Array("users"),
|
||||
)
|
||||
def deleteUser: Route =
|
||||
@ -223,7 +223,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
|
||||
tags = Array("users"),
|
||||
)
|
||||
def getUsers: Route =
|
||||
@ -270,7 +270,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
|
||||
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
|
||||
),
|
||||
),
|
||||
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("admin"))),
|
||||
security = Array(new SecurityRequirement(name = "basic", scopes = Array("admin"))),
|
||||
tags = Array("users"),
|
||||
)
|
||||
def getUsersCurrent: Route =
|
||||
|
@ -19,7 +19,10 @@ case class PlayerModel(
|
||||
@Schema(description = "looted pieces") loot: Option[Seq[LootModel]],
|
||||
@Schema(description = "link to best in slot", example = "https://ffxiv.ariyala.com/19V5R") link: Option[String],
|
||||
@Schema(description = "player loot priority", `type` = "number") priority: Option[Int],
|
||||
@Schema(description = "count of looted pieces which are parts of best in slot") lootCountBiS: Option[Int],
|
||||
@Schema(
|
||||
description = "count of looted pieces which are parts of best in slot",
|
||||
`type` = "number"
|
||||
) lootCountBiS: Option[Int],
|
||||
@Schema(description = "total count of looted pieces", `type` = "number") lootCountTotal: Option[Int],
|
||||
) {
|
||||
|
||||
|
@ -15,7 +15,7 @@ import me.arcanis.ffxivbis.http.{Authorization, AuthorizationProvider}
|
||||
|
||||
class RootView(override val auth: AuthorizationProvider) extends Authorization {
|
||||
|
||||
def route: Route = getBiS ~ getIndex ~ getLoot ~ getParty ~ getUsers
|
||||
def routes: Route = getBiS ~ getIndex ~ getLoot ~ getParty ~ getUsers
|
||||
|
||||
def getBiS: Route =
|
||||
path("party" / Segment / "bis") { partyId: String =>
|
||||
|
@ -8,36 +8,38 @@
|
||||
*/
|
||||
package me.arcanis.ffxivbis.messages
|
||||
|
||||
import akka.actor.typed.{ActorRef, Behavior}
|
||||
import akka.actor.typed.ActorRef
|
||||
import me.arcanis.ffxivbis.models._
|
||||
import me.arcanis.ffxivbis.service.LootSelector
|
||||
|
||||
sealed trait DatabaseMessage extends Message {
|
||||
|
||||
def partyId: String
|
||||
}
|
||||
|
||||
object DatabaseMessage {
|
||||
|
||||
type Handler = PartialFunction[DatabaseMessage, Behavior[DatabaseMessage]]
|
||||
def isReadOnly: Boolean
|
||||
}
|
||||
|
||||
// bis handler
|
||||
trait BisDatabaseMessage extends DatabaseMessage
|
||||
|
||||
case class AddPieceToBis(playerId: PlayerId, piece: Piece, replyTo: ActorRef[Unit]) extends BisDatabaseMessage {
|
||||
override def partyId: String = playerId.partyId
|
||||
override val partyId: String = playerId.partyId
|
||||
override val isReadOnly: Boolean = false
|
||||
}
|
||||
|
||||
case class GetBiS(partyId: String, playerId: Option[PlayerId], replyTo: ActorRef[Seq[Player]])
|
||||
extends BisDatabaseMessage
|
||||
extends BisDatabaseMessage {
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
||||
case class RemovePieceFromBiS(playerId: PlayerId, piece: Piece, replyTo: ActorRef[Unit]) extends BisDatabaseMessage {
|
||||
override def partyId: String = playerId.partyId
|
||||
override val partyId: String = playerId.partyId
|
||||
override val isReadOnly: Boolean = false
|
||||
}
|
||||
|
||||
case class RemovePiecesFromBiS(playerId: PlayerId, replyTo: ActorRef[Unit]) extends BisDatabaseMessage {
|
||||
override def partyId: String = playerId.partyId
|
||||
override val partyId: String = playerId.partyId
|
||||
override val isReadOnly: Boolean = false
|
||||
}
|
||||
|
||||
// loot handler
|
||||
@ -45,54 +47,77 @@ trait LootDatabaseMessage extends DatabaseMessage
|
||||
|
||||
case class AddPieceTo(playerId: PlayerId, piece: Piece, isFreeLoot: Boolean, replyTo: ActorRef[Unit])
|
||||
extends LootDatabaseMessage {
|
||||
override def partyId: String = playerId.partyId
|
||||
override val partyId: String = playerId.partyId
|
||||
override val isReadOnly: Boolean = false
|
||||
}
|
||||
|
||||
case class GetLoot(partyId: String, playerId: Option[PlayerId], replyTo: ActorRef[Seq[Player]])
|
||||
extends LootDatabaseMessage
|
||||
extends LootDatabaseMessage {
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
||||
case class RemovePieceFrom(playerId: PlayerId, piece: Piece, isFreeLoot: Boolean, replyTo: ActorRef[Unit])
|
||||
extends LootDatabaseMessage {
|
||||
override def partyId: String = playerId.partyId
|
||||
override val partyId: String = playerId.partyId
|
||||
override val isReadOnly: Boolean = false
|
||||
}
|
||||
|
||||
case class SuggestLoot(partyId: String, piece: Piece, replyTo: ActorRef[LootSelector.LootSelectorResult])
|
||||
extends LootDatabaseMessage
|
||||
extends LootDatabaseMessage {
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
||||
// party handler
|
||||
trait PartyDatabaseMessage extends DatabaseMessage
|
||||
|
||||
case class AddPlayer(player: Player, replyTo: ActorRef[Unit]) extends PartyDatabaseMessage {
|
||||
override def partyId: String = player.partyId
|
||||
override val partyId: String = player.partyId
|
||||
override val isReadOnly: Boolean = false
|
||||
}
|
||||
|
||||
case class GetParty(partyId: String, replyTo: ActorRef[Party]) extends PartyDatabaseMessage
|
||||
case class GetParty(partyId: String, replyTo: ActorRef[Party]) extends PartyDatabaseMessage {
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
||||
case class GetPartyDescription(partyId: String, replyTo: ActorRef[PartyDescription]) extends PartyDatabaseMessage
|
||||
case class GetPartyDescription(partyId: String, replyTo: ActorRef[PartyDescription]) extends PartyDatabaseMessage {
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
||||
case class GetPlayer(playerId: PlayerId, replyTo: ActorRef[Option[Player]]) extends PartyDatabaseMessage {
|
||||
override def partyId: String = playerId.partyId
|
||||
override val partyId: String = playerId.partyId
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
||||
case class RemovePlayer(playerId: PlayerId, replyTo: ActorRef[Unit]) extends PartyDatabaseMessage {
|
||||
override def partyId: String = playerId.partyId
|
||||
override val partyId: String = playerId.partyId
|
||||
override val isReadOnly: Boolean = false
|
||||
}
|
||||
|
||||
case class UpdateParty(partyDescription: PartyDescription, replyTo: ActorRef[Unit]) extends PartyDatabaseMessage {
|
||||
override def partyId: String = partyDescription.partyId
|
||||
override val partyId: String = partyDescription.partyId
|
||||
override val isReadOnly: Boolean = false
|
||||
}
|
||||
|
||||
// user handler
|
||||
trait UserDatabaseMessage extends DatabaseMessage
|
||||
|
||||
case class AddUser(user: User, isHashedPassword: Boolean, replyTo: ActorRef[Unit]) extends UserDatabaseMessage {
|
||||
override def partyId: String = user.partyId
|
||||
override val partyId: String = user.partyId
|
||||
override val isReadOnly: Boolean = false
|
||||
}
|
||||
|
||||
case class DeleteUser(partyId: String, username: String, replyTo: ActorRef[Unit]) extends UserDatabaseMessage
|
||||
case class DeleteUser(partyId: String, username: String, replyTo: ActorRef[Unit]) extends UserDatabaseMessage {
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
||||
case class Exists(partyId: String, replyTo: ActorRef[Boolean]) extends UserDatabaseMessage
|
||||
case class Exists(partyId: String, replyTo: ActorRef[Boolean]) extends UserDatabaseMessage {
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
||||
case class GetUser(partyId: String, username: String, replyTo: ActorRef[Option[User]]) extends UserDatabaseMessage
|
||||
case class GetUser(partyId: String, username: String, replyTo: ActorRef[Option[User]]) extends UserDatabaseMessage {
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
||||
case class GetUsers(partyId: String, replyTo: ActorRef[Seq[User]]) extends UserDatabaseMessage
|
||||
case class GetUsers(partyId: String, replyTo: ActorRef[Seq[User]]) extends UserDatabaseMessage {
|
||||
override val isReadOnly: Boolean = true
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import com.typesafe.scalalogging.StrictLogging
|
||||
import me.arcanis.ffxivbis.messages._
|
||||
import me.arcanis.ffxivbis.models.Party
|
||||
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
class PartyService(context: ActorContext[Message], storage: ActorRef[DatabaseMessage])
|
||||
@ -62,7 +61,8 @@ class PartyService(context: ActorContext[Message], storage: ActorRef[DatabaseMes
|
||||
|
||||
case req: DatabaseMessage =>
|
||||
storage ! req
|
||||
Behaviors.receiveMessage(handle(cache - req.partyId))
|
||||
val result = if (req.isReadOnly) cache else cache - req.partyId
|
||||
Behaviors.receiveMessage(handle(result))
|
||||
}
|
||||
|
||||
private def getPartyId: Future[String] = {
|
||||
|
@ -8,30 +8,32 @@
|
||||
*/
|
||||
package me.arcanis.ffxivbis.service.database.impl
|
||||
|
||||
import akka.actor.typed.Behavior
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import me.arcanis.ffxivbis.messages._
|
||||
import me.arcanis.ffxivbis.service.database.Database
|
||||
|
||||
trait DatabaseBiSHandler { this: Database =>
|
||||
|
||||
def bisHandler: DatabaseMessage.Handler = {
|
||||
case AddPieceToBis(playerId, piece, client) =>
|
||||
run(profile.insertPieceBiS(playerId, piece))(_ => client ! ())
|
||||
Behaviors.same
|
||||
def bisHandler(msg: BisDatabaseMessage): Behavior[DatabaseMessage] =
|
||||
msg match {
|
||||
case AddPieceToBis(playerId, piece, client) =>
|
||||
run(profile.insertPieceBiS(playerId, piece))(_ => client ! ())
|
||||
Behaviors.same
|
||||
|
||||
case GetBiS(partyId, maybePlayerId, client) =>
|
||||
run {
|
||||
getParty(partyId, withBiS = true, withLoot = false)
|
||||
.map(filterParty(_, maybePlayerId))
|
||||
}(client ! _)
|
||||
Behaviors.same
|
||||
case GetBiS(partyId, maybePlayerId, client) =>
|
||||
run {
|
||||
getParty(partyId, withBiS = true, withLoot = false)
|
||||
.map(filterParty(_, maybePlayerId))
|
||||
}(client ! _)
|
||||
Behaviors.same
|
||||
|
||||
case RemovePieceFromBiS(playerId, piece, client) =>
|
||||
run(profile.deletePieceBiS(playerId, piece))(_ => client ! ())
|
||||
Behaviors.same
|
||||
case RemovePieceFromBiS(playerId, piece, client) =>
|
||||
run(profile.deletePieceBiS(playerId, piece))(_ => client ! ())
|
||||
Behaviors.same
|
||||
|
||||
case RemovePiecesFromBiS(playerId, client) =>
|
||||
run(profile.deletePiecesBiS(playerId))(_ => client ! ())
|
||||
Behaviors.same
|
||||
}
|
||||
case RemovePiecesFromBiS(playerId, client) =>
|
||||
run(profile.deletePiecesBiS(playerId))(_ => client ! ())
|
||||
Behaviors.same
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ package me.arcanis.ffxivbis.service.database.impl
|
||||
import akka.actor.typed.scaladsl.{AbstractBehavior, ActorContext}
|
||||
import akka.actor.typed.{Behavior, DispatcherSelector}
|
||||
import com.typesafe.config.Config
|
||||
import me.arcanis.ffxivbis.messages.DatabaseMessage
|
||||
import me.arcanis.ffxivbis.messages.{BisDatabaseMessage, DatabaseMessage, LootDatabaseMessage, PartyDatabaseMessage, UserDatabaseMessage}
|
||||
import me.arcanis.ffxivbis.service.database.Database
|
||||
import me.arcanis.ffxivbis.storage.DatabaseProfile
|
||||
|
||||
@ -32,8 +32,12 @@ class DatabaseImpl(context: ActorContext[DatabaseMessage])
|
||||
override val config: Config = context.system.settings.config
|
||||
override val profile: DatabaseProfile = new DatabaseProfile(executionContext, config)
|
||||
|
||||
override def onMessage(msg: DatabaseMessage): Behavior[DatabaseMessage] = handle(msg)
|
||||
override def onMessage(msg: DatabaseMessage): Behavior[DatabaseMessage] =
|
||||
msg match {
|
||||
case msg: BisDatabaseMessage => bisHandler(msg)
|
||||
case msg: LootDatabaseMessage => lootHandler(msg)
|
||||
case msg: PartyDatabaseMessage => partyHandler(msg)
|
||||
case msg: UserDatabaseMessage => userHandler(msg)
|
||||
}
|
||||
|
||||
private def handle: DatabaseMessage.Handler =
|
||||
bisHandler.orElse(lootHandler).orElse(partyHandler).orElse(userHandler)
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
package me.arcanis.ffxivbis.service.database.impl
|
||||
|
||||
import akka.actor.typed.Behavior
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import me.arcanis.ffxivbis.messages._
|
||||
import me.arcanis.ffxivbis.models.Loot
|
||||
@ -17,28 +18,29 @@ import java.time.Instant
|
||||
|
||||
trait DatabaseLootHandler { this: Database =>
|
||||
|
||||
def lootHandler: DatabaseMessage.Handler = {
|
||||
case AddPieceTo(playerId, piece, isFreeLoot, client) =>
|
||||
val loot = Loot(-1, piece, Instant.now, isFreeLoot)
|
||||
run(profile.insertPiece(playerId, loot))(_ => client ! ())
|
||||
Behaviors.same
|
||||
def lootHandler(msg: LootDatabaseMessage): Behavior[DatabaseMessage] =
|
||||
msg match {
|
||||
case AddPieceTo(playerId, piece, isFreeLoot, client) =>
|
||||
val loot = Loot(-1, piece, Instant.now, isFreeLoot)
|
||||
run(profile.insertPiece(playerId, loot))(_ => client ! ())
|
||||
Behaviors.same
|
||||
|
||||
case GetLoot(partyId, maybePlayerId, client) =>
|
||||
run {
|
||||
getParty(partyId, withBiS = false, withLoot = true)
|
||||
.map(filterParty(_, maybePlayerId))
|
||||
}(client ! _)
|
||||
Behaviors.same
|
||||
case GetLoot(partyId, maybePlayerId, client) =>
|
||||
run {
|
||||
getParty(partyId, withBiS = false, withLoot = true)
|
||||
.map(filterParty(_, maybePlayerId))
|
||||
}(client ! _)
|
||||
Behaviors.same
|
||||
|
||||
case RemovePieceFrom(playerId, piece, isFreeLoot, client) =>
|
||||
run(profile.deletePiece(playerId, piece, isFreeLoot))(_ => client ! ())
|
||||
Behaviors.same
|
||||
case RemovePieceFrom(playerId, piece, isFreeLoot, client) =>
|
||||
run(profile.deletePiece(playerId, piece, isFreeLoot))(_ => client ! ())
|
||||
Behaviors.same
|
||||
|
||||
case SuggestLoot(partyId, piece, client) =>
|
||||
run {
|
||||
getParty(partyId, withBiS = true, withLoot = true)
|
||||
.map(_.suggestLoot(piece))
|
||||
}(client ! _)
|
||||
Behaviors.same
|
||||
}
|
||||
case SuggestLoot(partyId, piece, client) =>
|
||||
run {
|
||||
getParty(partyId, withBiS = true, withLoot = true)
|
||||
.map(_.suggestLoot(piece))
|
||||
}(client ! _)
|
||||
Behaviors.same
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
package me.arcanis.ffxivbis.service.database.impl
|
||||
|
||||
import akka.actor.typed.Behavior
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import me.arcanis.ffxivbis.messages._
|
||||
import me.arcanis.ffxivbis.models.{BiS, Player}
|
||||
@ -17,50 +18,51 @@ import scala.concurrent.Future
|
||||
|
||||
trait DatabasePartyHandler { this: Database =>
|
||||
|
||||
def partyHandler: DatabaseMessage.Handler = {
|
||||
case AddPlayer(player, client) =>
|
||||
run(profile.insertPlayer(player))(_ => client ! ())
|
||||
Behaviors.same
|
||||
def partyHandler(msg: PartyDatabaseMessage): Behavior[DatabaseMessage] =
|
||||
msg match {
|
||||
case AddPlayer(player, client) =>
|
||||
run(profile.insertPlayer(player))(_ => client ! ())
|
||||
Behaviors.same
|
||||
|
||||
case GetParty(partyId, client) =>
|
||||
run(getParty(partyId, withBiS = true, withLoot = true))(client ! _)
|
||||
Behaviors.same
|
||||
case GetParty(partyId, client) =>
|
||||
run(getParty(partyId, withBiS = true, withLoot = true))(client ! _)
|
||||
Behaviors.same
|
||||
|
||||
case GetPartyDescription(partyId, client) =>
|
||||
run(profile.getPartyDescription(partyId))(client ! _)
|
||||
Behaviors.same
|
||||
case GetPartyDescription(partyId, client) =>
|
||||
run(profile.getPartyDescription(partyId))(client ! _)
|
||||
Behaviors.same
|
||||
|
||||
case GetPlayer(playerId, client) =>
|
||||
run {
|
||||
profile
|
||||
.getPlayerFull(playerId)
|
||||
.flatMap { maybePlayerData =>
|
||||
Future.traverse(maybePlayerData.toSeq) { playerData =>
|
||||
for {
|
||||
bis <- profile.getPiecesBiS(playerId)
|
||||
loot <- profile.getPieces(playerId)
|
||||
} yield Player(
|
||||
playerData.id,
|
||||
playerId.partyId,
|
||||
playerId.job,
|
||||
playerId.nick,
|
||||
BiS(bis.map(_.piece)),
|
||||
loot,
|
||||
playerData.link,
|
||||
playerData.priority
|
||||
)
|
||||
case GetPlayer(playerId, client) =>
|
||||
run {
|
||||
profile
|
||||
.getPlayerFull(playerId)
|
||||
.flatMap { maybePlayerData =>
|
||||
Future.traverse(maybePlayerData.toSeq) { playerData =>
|
||||
for {
|
||||
bis <- profile.getPiecesBiS(playerId)
|
||||
loot <- profile.getPieces(playerId)
|
||||
} yield Player(
|
||||
playerData.id,
|
||||
playerId.partyId,
|
||||
playerId.job,
|
||||
playerId.nick,
|
||||
BiS(bis.map(_.piece)),
|
||||
loot,
|
||||
playerData.link,
|
||||
playerData.priority
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.map(_.headOption)
|
||||
}(client ! _)
|
||||
Behaviors.same
|
||||
.map(_.headOption)
|
||||
}(client ! _)
|
||||
Behaviors.same
|
||||
|
||||
case RemovePlayer(playerId, client) =>
|
||||
run(profile.deletePlayer(playerId))(_ => client ! ())
|
||||
Behaviors.same
|
||||
case RemovePlayer(playerId, client) =>
|
||||
run(profile.deletePlayer(playerId))(_ => client ! ())
|
||||
Behaviors.same
|
||||
|
||||
case UpdateParty(description, client) =>
|
||||
run(profile.insertPartyDescription(description))(_ => client ! ())
|
||||
Behaviors.same
|
||||
}
|
||||
case UpdateParty(description, client) =>
|
||||
run(profile.insertPartyDescription(description))(_ => client ! ())
|
||||
Behaviors.same
|
||||
}
|
||||
}
|
||||
|
@ -8,32 +8,34 @@
|
||||
*/
|
||||
package me.arcanis.ffxivbis.service.database.impl
|
||||
|
||||
import akka.actor.typed.Behavior
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import me.arcanis.ffxivbis.messages._
|
||||
import me.arcanis.ffxivbis.service.database.Database
|
||||
|
||||
trait DatabaseUserHandler { this: Database =>
|
||||
|
||||
def userHandler: DatabaseMessage.Handler = {
|
||||
case AddUser(user, isHashedPassword, client) =>
|
||||
val toInsert = if (isHashedPassword) user else user.withHashedPassword
|
||||
run(profile.insertUser(toInsert))(_ => client ! ())
|
||||
Behaviors.same
|
||||
def userHandler(msg: UserDatabaseMessage): Behavior[DatabaseMessage] =
|
||||
msg match {
|
||||
case AddUser(user, isHashedPassword, client) =>
|
||||
val toInsert = if (isHashedPassword) user else user.withHashedPassword
|
||||
run(profile.insertUser(toInsert))(_ => client ! ())
|
||||
Behaviors.same
|
||||
|
||||
case DeleteUser(partyId, username, client) =>
|
||||
run(profile.deleteUser(partyId, username))(_ => client ! ())
|
||||
Behaviors.same
|
||||
case DeleteUser(partyId, username, client) =>
|
||||
run(profile.deleteUser(partyId, username))(_ => client ! ())
|
||||
Behaviors.same
|
||||
|
||||
case Exists(partyId, client) =>
|
||||
run(profile.exists(partyId))(client ! _)
|
||||
Behaviors.same
|
||||
case Exists(partyId, client) =>
|
||||
run(profile.exists(partyId))(client ! _)
|
||||
Behaviors.same
|
||||
|
||||
case GetUser(partyId, username, client) =>
|
||||
run(profile.getUser(partyId, username))(client ! _)
|
||||
Behaviors.same
|
||||
case GetUser(partyId, username, client) =>
|
||||
run(profile.getUser(partyId, username))(client ! _)
|
||||
Behaviors.same
|
||||
|
||||
case GetUsers(partyId, client) =>
|
||||
run(profile.getUsers(partyId))(client ! _)
|
||||
Behaviors.same
|
||||
}
|
||||
case GetUsers(partyId, client) =>
|
||||
run(profile.getUsers(partyId))(client ! _)
|
||||
Behaviors.same
|
||||
}
|
||||
}
|
||||
|
@ -84,4 +84,5 @@ object Fixtures {
|
||||
lazy val users: Seq[User] = Seq(userAdmin, userGet)
|
||||
|
||||
lazy val authProvider: AuthorizationProvider = (_: String, _: String) => Future.successful(Some(userAdmin))
|
||||
lazy val rejectingProvider: AuthorizationProvider = (_: String, _: String) => Future.successful(None)
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package me.arcanis.ffxivbis.http
|
||||
|
||||
import akka.http.scaladsl.model.{StatusCodes, Uri}
|
||||
import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials}
|
||||
import akka.http.scaladsl.server.Route
|
||||
import akka.http.scaladsl.testkit.ScalatestRouteTest
|
||||
import me.arcanis.ffxivbis.Fixtures
|
||||
import me.arcanis.ffxivbis.http.view.RootView
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
|
||||
class AuthorizationTest extends AnyWordSpecLike with Matchers with ScalatestRouteTest {
|
||||
|
||||
private val auth =
|
||||
Authorization(BasicHttpCredentials(Fixtures.userAdmin.username, Fixtures.userPassword))
|
||||
|
||||
"authorization directive" must {
|
||||
|
||||
"accept credentials" in {
|
||||
val route = new RootView(Fixtures.authProvider).routes
|
||||
|
||||
Get(Uri(s"/party/${Fixtures.partyId}")).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
}
|
||||
}
|
||||
|
||||
"reject credentials" in {
|
||||
val route = new RootView(Fixtures.rejectingProvider).routes
|
||||
|
||||
Get(Uri(s"/party/${Fixtures.partyId}")).withHeaders(auth) ~> Route.seal(route) ~> check {
|
||||
status shouldEqual StatusCodes.Unauthorized
|
||||
}
|
||||
}
|
||||
|
||||
"reject with empty credentials" in {
|
||||
val route = new RootView(Fixtures.authProvider).routes
|
||||
|
||||
Get(Uri(s"/party/${Fixtures.partyId}")) ~> Route.seal(route) ~> check {
|
||||
status shouldEqual StatusCodes.Unauthorized
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
22
src/test/scala/me/arcanis/ffxivbis/http/HttpLogTest.scala
Normal file
22
src/test/scala/me/arcanis/ffxivbis/http/HttpLogTest.scala
Normal file
@ -0,0 +1,22 @@
|
||||
package me.arcanis.ffxivbis.http
|
||||
|
||||
import akka.http.scaladsl.model.{StatusCodes, Uri}
|
||||
import akka.http.scaladsl.server.Directives.complete
|
||||
import akka.http.scaladsl.testkit.ScalatestRouteTest
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
|
||||
class HttpLogTest extends AnyWordSpecLike with Matchers with ScalatestRouteTest {
|
||||
|
||||
private val log = new HttpLog {}
|
||||
|
||||
"log directive" must {
|
||||
|
||||
"work with empty request" in {
|
||||
Get(Uri("/")) ~> log.withHttpLog(complete(StatusCodes.OK)) ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package me.arcanis.ffxivbis.http
|
||||
|
||||
import akka.actor.testkit.typed.scaladsl.ActorTestKit
|
||||
import akka.http.scaladsl.model.{StatusCodes, Uri}
|
||||
import akka.http.scaladsl.testkit.ScalatestRouteTest
|
||||
import com.typesafe.config.Config
|
||||
import me.arcanis.ffxivbis.Settings
|
||||
import me.arcanis.ffxivbis.service.PartyService
|
||||
import me.arcanis.ffxivbis.service.bis.BisProvider
|
||||
import me.arcanis.ffxivbis.service.database.Database
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
|
||||
class RootEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRouteTest {
|
||||
|
||||
private val testKit = ActorTestKit(Settings.withRandomDatabase)
|
||||
override val testConfig: Config = testKit.system.settings.config
|
||||
|
||||
private val storage = testKit.spawn(Database())
|
||||
private val provider = testKit.spawn(BisProvider())
|
||||
private val party = testKit.spawn(PartyService(storage))
|
||||
private val route = new RootEndpoint(testKit.system, party, provider).routes
|
||||
|
||||
"root route" must {
|
||||
|
||||
"return swagger ui" in {
|
||||
Get(Uri("/api-docs")) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
}
|
||||
}
|
||||
|
||||
"return static routes" in {
|
||||
Get(Uri("/static/favicon.ico")) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
28
src/test/scala/me/arcanis/ffxivbis/http/SwaggerTest.scala
Normal file
28
src/test/scala/me/arcanis/ffxivbis/http/SwaggerTest.scala
Normal file
@ -0,0 +1,28 @@
|
||||
package me.arcanis.ffxivbis.http
|
||||
|
||||
import akka.http.scaladsl.model.{StatusCodes, Uri}
|
||||
import akka.http.scaladsl.testkit.ScalatestRouteTest
|
||||
import me.arcanis.ffxivbis.Settings
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
|
||||
class SwaggerTest extends AnyWordSpecLike with Matchers with ScalatestRouteTest {
|
||||
|
||||
private val swagger = new Swagger(Settings.withRandomDatabase)
|
||||
|
||||
"swagger guard" must {
|
||||
|
||||
"generate json" in {
|
||||
Get(Uri("/api-docs/swagger.json")) ~> swagger.routes ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
}
|
||||
}
|
||||
|
||||
"generate yml" in {
|
||||
Get(Uri("/api-docs/swagger.yaml")) ~> swagger.routes ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ class BiSEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRouteT
|
||||
private val storage = testKit.spawn(Database())
|
||||
private val provider = testKit.spawn(BisProvider())
|
||||
private val party = testKit.spawn(PartyService(storage))
|
||||
private val route = new BiSEndpoint(party, provider, Fixtures.authProvider)(askTimeout, testKit.scheduler).route
|
||||
private val route = new BiSEndpoint(party, provider, Fixtures.authProvider)(askTimeout, testKit.scheduler).routes
|
||||
|
||||
override def beforeAll(): Unit = {
|
||||
super.beforeAll()
|
||||
|
@ -34,7 +34,7 @@ class LootEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRoute
|
||||
|
||||
private val storage = testKit.spawn(Database())
|
||||
private val party = testKit.spawn(PartyService(storage))
|
||||
private val route = new LootEndpoint(party, Fixtures.authProvider)(askTimeout, testKit.scheduler).route
|
||||
private val route = new LootEndpoint(party, Fixtures.authProvider)(askTimeout, testKit.scheduler).routes
|
||||
|
||||
override def beforeAll(): Unit = {
|
||||
super.beforeAll()
|
||||
@ -95,5 +95,15 @@ class LootEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRoute
|
||||
}
|
||||
}
|
||||
|
||||
"suggest loot" in {
|
||||
val entity = PieceModel.fromPiece(Fixtures.lootBody)
|
||||
val response = Seq(Fixtures.playerEmpty.withCounters(Some(Fixtures.lootBody))).map(PlayerIdWithCountersModel.fromPlayerId)
|
||||
|
||||
Put(endpoint, entity).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
responseAs[Seq[PlayerIdWithCountersModel]] shouldEqual response
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class PartyEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRout
|
||||
private val storage = testKit.spawn(Database())
|
||||
private val provider = testKit.spawn(BisProvider())
|
||||
private val party = testKit.spawn(PartyService(storage))
|
||||
private val route = new PartyEndpoint(party, provider, Fixtures.authProvider)(askTimeout, testKit.scheduler).route
|
||||
private val route = new PartyEndpoint(party, provider, Fixtures.authProvider)(askTimeout, testKit.scheduler).routes
|
||||
|
||||
override def beforeAll(): Unit = {
|
||||
super.beforeAll()
|
||||
|
@ -7,6 +7,7 @@ import akka.http.scaladsl.model.{StatusCodes, Uri}
|
||||
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
|
||||
import akka.testkit.TestKit
|
||||
import com.typesafe.config.Config
|
||||
import me.arcanis.ffxivbis
|
||||
import me.arcanis.ffxivbis.http.api.v1.json._
|
||||
import me.arcanis.ffxivbis.messages.{AddPlayer, AddUser}
|
||||
import me.arcanis.ffxivbis.service.PartyService
|
||||
@ -34,7 +35,7 @@ class PlayerEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRou
|
||||
private val storage = testKit.spawn(Database())
|
||||
private val provider = testKit.spawn(BisProvider())
|
||||
private val party = testKit.spawn(PartyService(storage))
|
||||
private val route = new PlayerEndpoint(party, provider, Fixtures.authProvider)(askTimeout, testKit.scheduler).route
|
||||
private val route = new PlayerEndpoint(party, provider, Fixtures.authProvider)(askTimeout, testKit.scheduler).routes
|
||||
|
||||
override def beforeAll(): Unit = {
|
||||
super.beforeAll()
|
||||
@ -52,7 +53,7 @@ class PlayerEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRou
|
||||
|
||||
"api v1 player endpoint" must {
|
||||
|
||||
"get users" in {
|
||||
"get users belonging to the party" in {
|
||||
val response = Seq(PlayerModel.fromPlayer(Fixtures.playerEmpty))
|
||||
|
||||
Get(endpoint).withHeaders(auth) ~> route ~> check {
|
||||
@ -61,5 +62,42 @@ class PlayerEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRou
|
||||
}
|
||||
}
|
||||
|
||||
"get party stats" in {
|
||||
val response = Seq(PlayerIdWithCountersModel.fromPlayerId(Fixtures.playerEmpty.withCounters(None)))
|
||||
|
||||
Get(endpoint.withPath(endpoint.path / "stats")).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
responseAs[Seq[PlayerIdWithCountersModel]] shouldEqual response
|
||||
}
|
||||
}
|
||||
|
||||
"add new player to the party" in {
|
||||
val entity = PlayerActionModel(ApiAction.add, PlayerModel.fromPlayer(Fixtures.playerWithBiS))
|
||||
|
||||
Post(endpoint, entity).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.Accepted
|
||||
responseAs[String] shouldEqual ""
|
||||
}
|
||||
|
||||
Get(endpoint).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
responseAs[Seq[PlayerModel]].map(_.toPlayer.playerId) should contain(Fixtures.playerWithBiS.playerId)
|
||||
}
|
||||
}
|
||||
|
||||
"remove player from the party" in {
|
||||
val entity = PlayerActionModel(ApiAction.remove, PlayerModel.fromPlayer(Fixtures.playerEmpty))
|
||||
|
||||
Post(endpoint, entity).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.Accepted
|
||||
responseAs[String] shouldEqual ""
|
||||
}
|
||||
|
||||
Get(endpoint).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
responseAs[Seq[PlayerModel]].map(_.toPlayer.playerId) should not contain(Fixtures.playerEmpty.playerId)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package me.arcanis.ffxivbis.http.api.v1
|
||||
|
||||
import akka.http.scaladsl.model.StatusCodes
|
||||
import akka.http.scaladsl.testkit.ScalatestRouteTest
|
||||
import com.typesafe.config.Config
|
||||
import me.arcanis.ffxivbis.Settings
|
||||
import me.arcanis.ffxivbis.http.api.v1.json._
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
@ -13,9 +11,7 @@ import scala.language.postfixOps
|
||||
class StatusEndpointTest extends AnyWordSpecLike
|
||||
with Matchers with ScalatestRouteTest with JsonSupport {
|
||||
|
||||
override val testConfig: Config = Settings.withRandomDatabase
|
||||
|
||||
private val route = new StatusEndpoint().route
|
||||
private val route = new StatusEndpoint().routes
|
||||
|
||||
"api v1 status endpoint" must {
|
||||
|
||||
|
@ -16,7 +16,7 @@ class TypesEndpointTest extends AnyWordSpecLike
|
||||
|
||||
override val testConfig: Config = Settings.withRandomDatabase
|
||||
|
||||
private val route = new TypesEndpoint(testConfig).route
|
||||
private val route = new TypesEndpoint(testConfig).routes
|
||||
|
||||
"api v1 types endpoint" must {
|
||||
|
||||
|
@ -30,7 +30,7 @@ class UserEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRoute
|
||||
private var partyId = Fixtures.partyId
|
||||
private val storage = testKit.spawn(Database())
|
||||
private val party = testKit.spawn(PartyService(storage))
|
||||
private val route = new UserEndpoint(party, Fixtures.authProvider)(askTimeout, testKit.scheduler).route
|
||||
private val route = new UserEndpoint(party, Fixtures.authProvider)(askTimeout, testKit.scheduler).routes
|
||||
|
||||
override def beforeAll(): Unit = {
|
||||
super.beforeAll()
|
||||
@ -50,7 +50,7 @@ class UserEndpointTest extends AnyWordSpecLike with Matchers with ScalatestRoute
|
||||
val uri = Uri(s"/party")
|
||||
val entity = UserModel.fromUser(Fixtures.userAdmin).copy(password = Fixtures.userPassword)
|
||||
|
||||
Put(uri, entity) ~> route ~> check {
|
||||
Post(uri, entity) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
partyId = responseAs[PartyIdModel].partyId
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
package me.arcanis.ffxivbis.http.view
|
||||
|
||||
import akka.http.scaladsl.model.{StatusCodes, Uri}
|
||||
import akka.http.scaladsl.model.headers.{Authorization, BasicHttpCredentials}
|
||||
import akka.http.scaladsl.testkit.ScalatestRouteTest
|
||||
import me.arcanis.ffxivbis.Fixtures
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
|
||||
class RootViewTest extends AnyWordSpecLike with Matchers with ScalatestRouteTest {
|
||||
|
||||
private val auth =
|
||||
Authorization(BasicHttpCredentials(Fixtures.userAdmin.username, Fixtures.userPassword))
|
||||
|
||||
private val route = new RootView(Fixtures.authProvider).routes
|
||||
|
||||
"html view endpoint" must {
|
||||
|
||||
"return root view" in {
|
||||
Get(Uri("/")) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
responseAs[String] should not be empty
|
||||
}
|
||||
}
|
||||
|
||||
"return root party view" in {
|
||||
Get(Uri(s"/party/${Fixtures.partyId}")).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
responseAs[String] should not be empty
|
||||
}
|
||||
}
|
||||
|
||||
"return bis view" in {
|
||||
Get(Uri(s"/party/${Fixtures.partyId}/bis")).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
responseAs[String] should not be empty
|
||||
}
|
||||
}
|
||||
|
||||
"return loot view" in {
|
||||
Get(Uri(s"/party/${Fixtures.partyId}/loot")).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
responseAs[String] should not be empty
|
||||
}
|
||||
}
|
||||
|
||||
"return users view" in {
|
||||
Get(Uri(s"/party/${Fixtures.partyId}/users")).withHeaders(auth) ~> route ~> check {
|
||||
status shouldEqual StatusCodes.OK
|
||||
responseAs[String] should not be empty
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -6,5 +6,7 @@ import java.time.Instant
|
||||
import scala.language.implicitConversions
|
||||
|
||||
object Converters {
|
||||
|
||||
implicit def pieceToLoot(piece: Piece): Loot = Loot(-1, piece, Instant.ofEpochMilli(0), isFreeLoot = false)
|
||||
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
version := "0.12.0"
|
||||
version := "0.13.3"
|
||||
|
Reference in New Issue
Block a user