1
0
Fork 0

[golang] implement sending the starting probe to a shipyard that sells other probes

This commit is contained in:
Julien Dessaux 2025-02-18 00:05:48 +01:00
parent bd2fb50c81
commit 3656b87b86
Signed by: adyxax
GPG key ID: F92E51B86E07177E
6 changed files with 98 additions and 61 deletions

View file

@ -24,24 +24,6 @@ func (c *Client) GetSystem(symbol string, db *database.DB) (*model.System, error
return &system, nil
}
func (c *Client) ListWaypointsInSystem(system *model.System, db *database.DB) ([]model.Waypoint, error) {
if waypoints, err := db.LoadWaypointsInSystem(system); err == nil && waypoints != nil {
// TODO check last updated time
return waypoints, nil
}
uriRef := url.URL{Path: path.Join("systems", system.Symbol, "waypoints")}
var waypoints []model.Waypoint
if err := c.Send("GET", &uriRef, nil, &waypoints); err != nil {
return nil, fmt.Errorf("failed to list waypoints in system %s: %w", system.Symbol, err)
}
for _, waypoint := range waypoints {
if err := db.SaveWaypoint(&waypoint); err != nil {
return nil, fmt.Errorf("failed to list waypoints in system %s: %w", system.Symbol, err)
}
}
return waypoints, nil
}
func (c *Client) GetShipyard(waypoint *model.Waypoint, db *database.DB) (*model.Shipyard, error) {
if shipyard, err := db.LoadShipyard(waypoint.Symbol); err == nil && shipyard != nil &&
(shipyard.Ships != nil) { // TODO || !IsThereAShipAtWaypoint(waypoint)) {
@ -75,3 +57,21 @@ func (c *Client) GetWaypoint(symbol string, db *database.DB) (*model.Waypoint, e
}
return &waypoint, nil
}
func (c *Client) ListWaypointsInSystem(systemSymbol string, db *database.DB) ([]model.Waypoint, error) {
if waypoints, err := db.LoadWaypointsInSystem(systemSymbol); err == nil && waypoints != nil {
// TODO check last updated time
return waypoints, nil
}
uriRef := url.URL{Path: path.Join("systems", systemSymbol, "waypoints")}
var waypoints []model.Waypoint
if err := c.Send("GET", &uriRef, nil, &waypoints); err != nil {
return nil, fmt.Errorf("failed to list waypoints in system %s: %w", systemSymbol, err)
}
for _, waypoint := range waypoints {
if err := db.SaveWaypoint(&waypoint); err != nil {
return nil, fmt.Errorf("failed to list waypoints in system %s: %w", systemSymbol, err)
}
}
return waypoints, nil
}