Compare commits
3 Commits
b22ba8e787
...
50ca3bc2bc
Author | SHA1 | Date | |
---|---|---|---|
50ca3bc2bc | |||
2dbb1cbd80 | |||
79351c7402 |
@@ -6,6 +6,6 @@ select
|
|||||||
g.name as GuildName
|
g.name as GuildName
|
||||||
from
|
from
|
||||||
player p
|
player p
|
||||||
join guild g on p.guild = g.id
|
left join guild g on p.guild = g.id
|
||||||
where
|
where
|
||||||
p.name = $1;
|
p.name = $1;
|
@@ -2,7 +2,7 @@ select
|
|||||||
p.id,
|
p.id,
|
||||||
p.name,
|
p.name,
|
||||||
p.guild,
|
p.guild,
|
||||||
g.name,
|
coalesce(g.name, 'N/A'),
|
||||||
count(distinct n.player) as nnotes,
|
count(distinct n.player) as nnotes,
|
||||||
count(
|
count(
|
||||||
distinct case
|
distinct case
|
||||||
@@ -15,6 +15,6 @@ from
|
|||||||
left join note n on n.player = p.id
|
left join note n on n.player = p.id
|
||||||
left join association a on a.lhs = p.id
|
left join association a on a.lhs = p.id
|
||||||
or a.rhs = p.id
|
or a.rhs = p.id
|
||||||
join guild g on p.guild = g.id
|
left join guild g on p.guild = g.id
|
||||||
group by
|
group by
|
||||||
p.id
|
p.id
|
@@ -98,7 +98,7 @@ func PersistNoteData(note NoteData) (Note, []Association, error) {
|
|||||||
player.Guild = guild
|
player.Guild = guild
|
||||||
|
|
||||||
for _, assoc := range note.Associations {
|
for _, assoc := range note.Associations {
|
||||||
assocPlayer, err := ps.GetOrCreate(assoc.Player, guild)
|
assocPlayer, err := ps.GetOrCreate(assoc.Player, Guild{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, ass, fmt.Errorf("failed getting player for %s: %v", assoc.Player, err)
|
return res, ass, fmt.Errorf("failed getting player for %s: %v", assoc.Player, err)
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,66 @@
|
|||||||
---
|
---
|
||||||
import Layout from "../layouts/Layout.astro";
|
import Layout from "../layouts/Layout.astro";
|
||||||
import type { APIResponse, Player } from "../types";
|
import type { APIResponse, Player, Note } from "../types";
|
||||||
|
|
||||||
const res = await fetch("http://localhost:3000/player");
|
const res = await fetch("http://localhost:3000/player");
|
||||||
const data: APIResponse<Player[]> = await res.json();
|
const data: APIResponse<Player[]> = await res.json();
|
||||||
console.log(data);
|
|
||||||
|
const request = { success: true, message: "" };
|
||||||
|
if (Astro.request.method === "POST") {
|
||||||
|
try {
|
||||||
|
const body = await Astro.request.text();
|
||||||
|
const res = await fetch("http://localhost:3000/note/new", {
|
||||||
|
method: "POST",
|
||||||
|
body,
|
||||||
|
});
|
||||||
|
const data: APIResponse<Note> = await res.json();
|
||||||
|
request.success = data.success;
|
||||||
|
request.message = data.message;
|
||||||
|
return new Response(null, {
|
||||||
|
status: res.status,
|
||||||
|
statusText: data.message,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(request);
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const form = document.querySelector("form");
|
||||||
|
if (form) {
|
||||||
|
form.addEventListener("submit", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const note = document.querySelector("#note");
|
||||||
|
if (!note) {
|
||||||
|
console.error("No note found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch(window.location.href, {
|
||||||
|
method: "POST",
|
||||||
|
body: note.innerText,
|
||||||
|
}).then((res) => {
|
||||||
|
if (res.status != 200) {
|
||||||
|
console.error(res);
|
||||||
|
const err = res.statusText;
|
||||||
|
const kaput = document.querySelector("#kaput");
|
||||||
|
kaput.classList.remove("display-none");
|
||||||
|
kaput.innerText = err;
|
||||||
|
} else {
|
||||||
|
const kaput = document.querySelector("#kaput");
|
||||||
|
kaput.classList.add("display-none");
|
||||||
|
note.innerText = "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<Layout title="Players">
|
<Layout title="Players">
|
||||||
|
<div id="kaput" class="display-none text-center text-2xl text-red-600 py-2">
|
||||||
|
</div>
|
||||||
<form class="p-5 min-h-[25rem] h-[25rem]">
|
<form class="p-5 min-h-[25rem] h-[25rem]">
|
||||||
<div class="h-full w-full mb-4 border rounded-lg shadow-lg overflow-hidden flex flex-col">
|
<div class="h-full w-full mb-4 border rounded-lg shadow-lg overflow-hidden flex flex-col">
|
||||||
<div
|
<div
|
||||||
@@ -18,6 +71,7 @@ console.log(data);
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex items-center justify-between px-3 py-2 border-t">
|
<div class="flex items-center justify-between px-3 py-2 border-t">
|
||||||
<button
|
<button
|
||||||
|
id="note-submit-btn"
|
||||||
type="submit"
|
type="submit"
|
||||||
class="inline-flex items-center py-2.5 px-4 text-xs font-medium text-center text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:ring-4 transition-all duration-200"
|
class="inline-flex items-center py-2.5 px-4 text-xs font-medium text-center text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:ring-4 transition-all duration-200"
|
||||||
>
|
>
|
||||||
|
Reference in New Issue
Block a user