Implements full player get
This commit is contained in:
@@ -81,3 +81,69 @@ func (ps *PlayerService) GetOrCreate(name string, guild Guild) (Player, error) {
|
||||
}
|
||||
return player, nil
|
||||
}
|
||||
|
||||
type (
|
||||
FullPlayer struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Guild struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"guild"`
|
||||
Associations []FullPlayerAssociation `json:"associations"`
|
||||
Notes []FullPlayerNote `json:"notes"`
|
||||
}
|
||||
|
||||
FullPlayerAssociation struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Note string `json:"note"`
|
||||
}
|
||||
|
||||
FullPlayerNote struct {
|
||||
ID int64 `json:"id"`
|
||||
Content string `json:"content"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
)
|
||||
|
||||
func (ps *PlayerService) GetAllPlayerInfo(name string, nnotes int) (FullPlayer, error) {
|
||||
res := FullPlayer{}
|
||||
|
||||
err := ps.db.readConn.QueryRow(selectPlayer, name).Scan(&res.ID, &res.Name, &res.Guild.ID, &res.Guild.Name)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed getting player info: %v", err)
|
||||
}
|
||||
|
||||
rows, err := ps.db.readConn.Query(selectAssociation, res.ID)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed getting player associations: %v", err)
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
assoc := FullPlayerAssociation{}
|
||||
err := rows.Scan(&assoc.ID, &assoc.Name, &assoc.Note)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed scanning association: %v", err)
|
||||
}
|
||||
res.Associations = append(res.Associations, assoc)
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
rows, err = ps.db.readConn.Query(selectNotes, res.ID, nnotes)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed getting player notes: %v", err)
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
note := FullPlayerNote{}
|
||||
err := rows.Scan(¬e.ID, ¬e.Content, ¬e.Timestamp)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed scanning note: %v", err)
|
||||
}
|
||||
res.Notes = append(res.Notes, note)
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user