-
Notifications
You must be signed in to change notification settings - Fork 0
/
evesolarsystem.go
49 lines (44 loc) · 1.44 KB
/
evesolarsystem.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package storage
import (
"context"
"database/sql"
"errors"
"fmt"
"github.com/ErikKalkoken/evebuddy/internal/model"
"github.com/ErikKalkoken/evebuddy/internal/storage/queries"
)
func (r *Storage) CreateEveSolarSystem(ctx context.Context, id int32, eve_constellation_id int32, name string, security_status float64) error {
if id == 0 {
return fmt.Errorf("invalid ID %d", id)
}
arg := queries.CreateEveSolarSystemParams{
ID: int64(id),
EveConstellationID: int64(eve_constellation_id),
Name: name,
SecurityStatus: float64(security_status),
}
err := r.q.CreateEveSolarSystem(ctx, arg)
if err != nil {
return fmt.Errorf("failed to create EveSolarSystem %v, %w", arg, err)
}
return nil
}
func (r *Storage) GetEveSolarSystem(ctx context.Context, id int32) (*model.EveSolarSystem, error) {
row, err := r.q.GetEveSolarSystem(ctx, int64(id))
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
err = ErrNotFound
}
return nil, fmt.Errorf("failed to get EveSolarSystem for id %d: %w", id, err)
}
t := eveSolarSystemFromDBModel(row.EveSolarSystem, row.EveConstellation, row.EveRegion)
return t, nil
}
func eveSolarSystemFromDBModel(s queries.EveSolarSystem, c queries.EveConstellation, r queries.EveRegion) *model.EveSolarSystem {
return &model.EveSolarSystem{
Constellation: eveConstellationFromDBModel(c, r),
ID: int32(s.ID),
Name: s.Name,
SecurityStatus: s.SecurityStatus,
}
}