Compare commits

..

2 Commits

Author SHA1 Message Date
114eaddc94 Set up tailwind maybe... 2024-10-30 15:47:43 +01:00
385b22d4e4 Return more data per player on listing all players 2024-10-30 15:47:38 +01:00
8 changed files with 88 additions and 8 deletions

View File

@@ -40,6 +40,9 @@ var as AssociationService
//go:embed selectPlayer.sql
var selectPlayer string
//go:embed selectPlayers.sql
var selectPlayers string
//go:embed selectAssociation.sql
var selectAssociation string
@@ -122,7 +125,7 @@ func GetPlayer(c fiber.Ctx) error {
}
func GetPlayers(c fiber.Ctx) error {
players, err := ps.Query(PlayerServiceQuery{})
players, err := ps.GetAllPlayers()
if err != nil {
Error.Printf("Failed getting players: %v", err)
return c.Status(500).JSON(Response{

View File

@@ -29,7 +29,7 @@ func (ps *PlayerService) Query(query PlayerServiceQuery) ([]Player, error) {
for rows.Next() {
player := Player{}
err := rows.Scan(&player.ID, &player.Name, &player.Guild.ID)
err := rows.Scan(&player.ID, &player.Name, &player.Guild.ID, &player.Notes, &player.Associations)
if err != nil {
return res, fmt.Errorf("failed scanning player: %v", err)
}
@@ -147,3 +147,24 @@ func (ps *PlayerService) GetAllPlayerInfo(name string, nnotes int) (FullPlayer,
return res, nil
}
func (ps *PlayerService) GetAllPlayers() ([]Player, error) {
res := []Player{}
rows, err := ps.db.readConn.Query(selectPlayers)
if err != nil {
return res, fmt.Errorf("failed getting players: %v", err)
}
for rows.Next() {
player := Player{}
err := rows.Scan(&player.ID, &player.Name, &player.Guild.ID, &player.Guild.Name, &player.Notes, &player.Associations)
if err != nil {
return res, fmt.Errorf("failed scanning player: %v", err)
}
res = append(res, player)
}
rows.Close()
return res, nil
}

20
backend/selectPlayers.sql Normal file
View File

@@ -0,0 +1,20 @@
select
p.id,
p.name,
p.guild,
g.name,
count(distinct n.player) as nnotes,
count(
distinct case
when a.lhs = p.id
or a.rhs = p.id then a.id
end
) as nassoc
from
player p
left join note n on n.player = p.id
left join association a on a.lhs = p.id
or a.rhs = p.id
join guild g on p.guild = g.id
group by
p.id

View File

@@ -8,9 +8,11 @@ type (
Name string `json:"name"`
}
Player struct {
ID int64 `json:"id"`
Name string `json:"name"`
Guild Guild `json:"guild,omitempty"`
ID int64 `json:"id"`
Name string `json:"name"`
Guild Guild `json:"guild,omitempty"`
Notes int `json:"notes"`
Associations int `json:"associations"`
}
Association struct {
ID int64 `json:"id"`

View File

@@ -1,7 +1,10 @@
// @ts-check
import { defineConfig } from 'astro/config';
import tailwind from "@astrojs/tailwind";
// https://astro.build/config
export default defineConfig({
output: "server",
});
output: "server",
integrations: [tailwind()],
});

View File

@@ -11,6 +11,7 @@
},
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/tailwind": "^5.1.2",
"astro": "^4.16.7",
"typescript": "^5.6.3"
},

View File

@@ -11,6 +11,9 @@ importers:
'@astrojs/check':
specifier: ^0.9.4
version: 0.9.4(typescript@5.6.3)
'@astrojs/tailwind':
specifier: ^5.1.2
version: 5.1.2(astro@4.16.7(rollup@4.24.2)(typescript@5.6.3))(tailwindcss@3.4.14)
astro:
specifier: ^4.16.7
version: 4.16.7(rollup@4.24.2)(typescript@5.6.3)
@@ -69,6 +72,12 @@ packages:
resolution: {integrity: sha512-Z9IYjuXSArkAUx3N6xj6+Bnvx8OdUSHA8YoOgyepp3+zJmtVYJIl/I18GozdJVW1p5u/CNpl3Km7/gwTJK85cw==}
engines: {node: ^18.17.1 || ^20.3.0 || >=21.0.0}
'@astrojs/tailwind@5.1.2':
resolution: {integrity: sha512-IvOF0W/dtHElcXvhrPR35nHmhyV3cfz1EzPitMGtU7sYy9Hci3BNK1To6FWmVuuNKPxza1IgCGetSynJZL7fOg==}
peerDependencies:
astro: ^3.0.0 || ^4.0.0 || ^5.0.0-beta.0
tailwindcss: ^3.0.24
'@astrojs/telemetry@3.1.0':
resolution: {integrity: sha512-/ca/+D8MIKEC8/A9cSaPUqQNZm+Es/ZinRv0ZAzvu2ios7POQSsVD+VOj7/hypWNsNM3T7RpfgNq7H2TU1KEHA==}
engines: {node: ^18.17.1 || ^20.3.0 || >=21.0.0}
@@ -2161,6 +2170,16 @@ snapshots:
dependencies:
prismjs: 1.29.0
'@astrojs/tailwind@5.1.2(astro@4.16.7(rollup@4.24.2)(typescript@5.6.3))(tailwindcss@3.4.14)':
dependencies:
astro: 4.16.7(rollup@4.24.2)(typescript@5.6.3)
autoprefixer: 10.4.20(postcss@8.4.47)
postcss: 8.4.47
postcss-load-config: 4.0.2(postcss@8.4.47)
tailwindcss: 3.4.14
transitivePeerDependencies:
- ts-node
'@astrojs/telemetry@3.1.0':
dependencies:
ci-info: 4.0.0

View File

@@ -1,4 +1,15 @@
export type Player = {
id: number;
name: string;
guild: {
id: number;
name: string;
};
associations: number;
notes: number;
};
export type PlayerFull = {
id: number;
name: string;
guild: {
@@ -26,4 +37,4 @@ export type APIResponse<T> = {
success: boolean;
message: string;
data: T;
}
};