mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-14 19:55:51 +00:00
feat: added static system info to api (#101)
* feat: added static system info to api
This commit is contained in:
1535
CHANGELOG.md
1535
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@@ -7,14 +7,49 @@ defmodule WandererAppWeb.APIController do
|
|||||||
alias WandererApp.MapSystemRepo
|
alias WandererApp.MapSystemRepo
|
||||||
alias WandererApp.MapCharacterSettingsRepo
|
alias WandererApp.MapCharacterSettingsRepo
|
||||||
alias WandererApp.Api.Character
|
alias WandererApp.Api.Character
|
||||||
|
alias WandererApp.CachedInfo
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
# SYSTEMS
|
# Common
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
GET /api/system-static-info
|
||||||
|
|
||||||
|
Requires 'id' (the solar_system_id)
|
||||||
|
|
||||||
|
Example:
|
||||||
|
GET /api/common/system_static?id=31002229
|
||||||
|
GET /api/common/system_static?id=31002229
|
||||||
|
"""
|
||||||
|
def show_system_static(conn, params) do
|
||||||
|
with {:ok, solar_system_str} <- require_param(params, "id"),
|
||||||
|
{:ok, solar_system_id} <- parse_int(solar_system_str) do
|
||||||
|
case CachedInfo.get_system_static_info(solar_system_id) do
|
||||||
|
{:ok, system} ->
|
||||||
|
data = static_system_to_json(system)
|
||||||
|
json(conn, %{data: data})
|
||||||
|
|
||||||
|
{:error, :not_found} ->
|
||||||
|
conn
|
||||||
|
|> put_status(:not_found)
|
||||||
|
|> json(%{error: "System not found"})
|
||||||
|
end
|
||||||
|
else
|
||||||
|
{:error, msg} ->
|
||||||
|
conn
|
||||||
|
|> put_status(:bad_request)
|
||||||
|
|> json(%{error: msg})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
# Map
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
GET /api/systems
|
GET /api/map/systems
|
||||||
|
|
||||||
Requires either `?map_id=<UUID>` **OR** `?slug=<map-slug>` in the query params.
|
Requires either `?map_id=<UUID>` **OR** `?slug=<map-slug>` in the query params.
|
||||||
|
|
||||||
@@ -22,9 +57,9 @@ If `?all=true` is provided, **all** systems are returned.
|
|||||||
Otherwise, only "visible" systems are returned.
|
Otherwise, only "visible" systems are returned.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
GET /api/systems?map_id=466e922b-e758-485e-9b86-afae06b88363
|
GET /api/map/systems?map_id=466e922b-e758-485e-9b86-afae06b88363
|
||||||
GET /api/systems?slug=my-unique-wormhole-map
|
GET /api/map/systems?slug=my-unique-wormhole-map
|
||||||
GET /api/systems?map_id=<UUID>&all=true
|
GET /api/map/systems?map_id=<UUID>&all=true
|
||||||
"""
|
"""
|
||||||
def list_systems(conn, params) do
|
def list_systems(conn, params) do
|
||||||
with {:ok, map_id} <- fetch_map_id(params) do
|
with {:ok, map_id} <- fetch_map_id(params) do
|
||||||
@@ -56,14 +91,14 @@ end
|
|||||||
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
GET /api/system
|
GET /api/map/system
|
||||||
|
|
||||||
Requires 'id' (the solar_system_id)
|
Requires 'id' (the solar_system_id)
|
||||||
plus either ?map_id=<UUID> or ?slug=<map-slug>.
|
plus either ?map_id=<UUID> or ?slug=<map-slug>.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
GET /api/system?id=31002229&map_id=466e922b-e758-485e-9b86-afae06b88363
|
GET /api/map/system?id=31002229&map_id=466e922b-e758-485e-9b86-afae06b88363
|
||||||
GET /api/system?id=31002229&slug=my-unique-wormhole-map
|
GET /api/map/system?id=31002229&slug=my-unique-wormhole-map
|
||||||
"""
|
"""
|
||||||
def show_system(conn, params) do
|
def show_system(conn, params) do
|
||||||
with {:ok, solar_system_str} <- require_param(params, "id"),
|
with {:ok, solar_system_str} <- require_param(params, "id"),
|
||||||
@@ -87,16 +122,14 @@ end
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
|
||||||
# Characters
|
|
||||||
# -----------------------------------------------------------------
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
GET /api/tracked_characters_with_info
|
GET /api/map/tracked_characters_with_info
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
GET /api/tracked_characters_with_info?map_id=<uuid>
|
GET /api/map/tracked_characters_with_info?map_id=<uuid>
|
||||||
GET /api/tracked_characters_with_info?slug=<map-slug>
|
GET /api/map/tracked_characters_with_info?slug=<map-slug>
|
||||||
|
|
||||||
Returns a list of tracked records, plus their fully-loaded `character` data.
|
Returns a list of tracked records, plus their fully-loaded `character` data.
|
||||||
"""
|
"""
|
||||||
@@ -211,39 +244,65 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp map_system_to_json(system) do
|
defp map_system_to_json(system) do
|
||||||
%{
|
Map.take(system, [
|
||||||
id: system.id,
|
:id,
|
||||||
map_id: system.map_id,
|
:map_id,
|
||||||
solar_system_id: system.solar_system_id,
|
:solar_system_id,
|
||||||
name: system.name,
|
:name,
|
||||||
custom_name: system.custom_name,
|
:custom_name,
|
||||||
temporary_name: system.temporary_name,
|
:temporary_name,
|
||||||
description: system.description,
|
:description,
|
||||||
tag: system.tag,
|
:tag,
|
||||||
labels: system.labels,
|
:labels,
|
||||||
locked: system.locked,
|
:locked,
|
||||||
visible: system.visible,
|
:visible,
|
||||||
status: system.status,
|
:status,
|
||||||
position_x: system.position_x,
|
:position_x,
|
||||||
position_y: system.position_y,
|
:position_y,
|
||||||
inserted_at: system.inserted_at,
|
:inserted_at,
|
||||||
updated_at: system.updated_at
|
:updated_at
|
||||||
}
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp character_to_json(ch) do
|
defp character_to_json(ch) do
|
||||||
%{
|
Map.take(ch, [
|
||||||
id: ch.id,
|
:id,
|
||||||
eve_id: ch.eve_id,
|
:eve_id,
|
||||||
name: ch.name,
|
:name,
|
||||||
corporation_id: ch.corporation_id,
|
:corporation_id,
|
||||||
corporation_name: ch.corporation_name,
|
:corporation_name,
|
||||||
corporation_ticker: ch.corporation_ticker,
|
:corporation_ticker,
|
||||||
alliance_id: ch.alliance_id,
|
:alliance_id,
|
||||||
alliance_name: ch.alliance_name,
|
:alliance_name,
|
||||||
alliance_ticker: ch.alliance_ticker,
|
:alliance_ticker,
|
||||||
inserted_at: ch.inserted_at,
|
:inserted_at,
|
||||||
updated_at: ch.updated_at
|
:updated_at
|
||||||
}
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
defp static_system_to_json(system) do
|
||||||
|
system
|
||||||
|
|> Map.take([
|
||||||
|
:solar_system_id,
|
||||||
|
:region_id,
|
||||||
|
:constellation_id,
|
||||||
|
:solar_system_name,
|
||||||
|
:solar_system_name_lc,
|
||||||
|
:constellation_name,
|
||||||
|
:region_name,
|
||||||
|
:system_class,
|
||||||
|
:security,
|
||||||
|
:type_description,
|
||||||
|
:class_title,
|
||||||
|
:is_shattered,
|
||||||
|
:effect_name,
|
||||||
|
:effect_power,
|
||||||
|
:statics,
|
||||||
|
:wandering,
|
||||||
|
:triglavian_invasion_status,
|
||||||
|
:sun_type_id
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -107,23 +107,36 @@ defmodule WandererAppWeb.Router do
|
|||||||
pipeline :api do
|
pipeline :api do
|
||||||
plug(:accepts, ["json"])
|
plug(:accepts, ["json"])
|
||||||
plug WandererAppWeb.Plugs.CheckApiDisabled
|
plug WandererAppWeb.Plugs.CheckApiDisabled
|
||||||
|
end
|
||||||
|
|
||||||
|
pipeline :api_map do
|
||||||
plug WandererAppWeb.Plugs.CheckMapApiKey
|
plug WandererAppWeb.Plugs.CheckMapApiKey
|
||||||
end
|
end
|
||||||
|
|
||||||
if not WandererApp.Env.public_api_disabled?() do
|
scope "/api/map", WandererAppWeb do
|
||||||
scope "/api", WandererAppWeb do
|
pipe_through [:api_map]
|
||||||
pipe_through [:api]
|
pipe_through [:api]
|
||||||
|
|
||||||
# GET /api/systems?map_id=... or ?slug=...
|
# GET /api/map/systems?map_id=... or ?slug=...
|
||||||
get "/systems", APIController, :list_systems
|
get "/systems", APIController, :list_systems
|
||||||
|
|
||||||
# GET /api/system?id=... plus either map_id=... or slug=...
|
# GET /api/map/system-static-info?id=... plus either map_id=... or slug=...
|
||||||
get "/system", APIController, :show_system
|
get "/system-static-info", APIController, :show_system_static
|
||||||
|
|
||||||
# GET /api/characters?map_id=... or slug=...
|
# GET /api/map/system?id=... plus either map_id=... or slug=...
|
||||||
get "/characters", APIController, :tracked_characters_with_info
|
get "/system", APIController, :show_system
|
||||||
end
|
|
||||||
end
|
# GET /api/map/characters?map_id=... or slug=...
|
||||||
|
get "/characters", APIController, :tracked_characters_with_info
|
||||||
|
end
|
||||||
|
|
||||||
|
scope "/api/common", WandererAppWeb do
|
||||||
|
pipe_through [:api]
|
||||||
|
|
||||||
|
# GET /api/common/system-static-info?id=...
|
||||||
|
get "/system-static-info", APIController, :show_system_static
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
scope "/", WandererAppWeb do
|
scope "/", WandererAppWeb do
|
||||||
pipe_through [:browser, :blog, :redirect_if_user_is_authenticated]
|
pipe_through [:browser, :blog, :redirect_if_user_is_authenticated]
|
||||||
|
|||||||
1
mix.exs
1
mix.exs
@@ -2,6 +2,7 @@ defmodule WandererApp.MixProject do
|
|||||||
use Mix.Project
|
use Mix.Project
|
||||||
|
|
||||||
@source_url "https://github.com/wanderer-industries/wanderer"
|
@source_url "https://github.com/wanderer-industries/wanderer"
|
||||||
|
|
||||||
@version "1.35.0"
|
@version "1.35.0"
|
||||||
|
|
||||||
def project do
|
def project do
|
||||||
|
|||||||
@@ -20,20 +20,22 @@ As part of the Wanderer platform, a public API has been introduced to help users
|
|||||||
|
|
||||||
## Authentication
|
## Authentication
|
||||||
|
|
||||||
Each request to the Wanderer API must include a valid API key in the `Authorization` header. The format is:
|
Each request to the Wanderer APIs that being with /api/map must include a valid API key in the `Authorization` header. The format is:
|
||||||
|
|
||||||
Authorization: Bearer <YOUR_MAP_API_KEY>
|
Authorization: Bearer <YOUR_MAP_API_KEY>
|
||||||
|
|
||||||
If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` response.
|
If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` response.
|
||||||
|
|
||||||
|
No api key is required for routes that being with /api/common
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Endpoints Overview
|
## Endpoints Overview
|
||||||
|
|
||||||
### 1. List Systems
|
### 1. List Systems
|
||||||
|
|
||||||
GET /api/systems?map_id=<UUID>
|
GET /api/map/systems?map_id=<UUID>
|
||||||
GET /api/systems?slug=<map-slug>
|
GET /api/map/systems?slug=<map-slug>
|
||||||
|
|
||||||
- **Description:** Retrieves a list of systems associated with the specified map (by `map_id` or `slug`).
|
- **Description:** Retrieves a list of systems associated with the specified map (by `map_id` or `slug`).
|
||||||
- **Authentication:** Required via `Authorization` header.
|
- **Authentication:** Required via `Authorization` header.
|
||||||
@@ -44,7 +46,7 @@ If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` re
|
|||||||
|
|
||||||
#### Example Request
|
#### Example Request
|
||||||
```
|
```
|
||||||
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/systems?slug=some-slug"
|
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/map/systems?slug=some-slug"
|
||||||
```
|
```
|
||||||
#### Example Response
|
#### Example Response
|
||||||
```
|
```
|
||||||
@@ -75,8 +77,8 @@ If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` re
|
|||||||
|
|
||||||
### 2. Show Single System
|
### 2. Show Single System
|
||||||
|
|
||||||
GET /api/system?id=<SOLAR_SYSTEM_ID>&map_id=<UUID>
|
GET /api/map/system?id=<SOLAR_SYSTEM_ID>&map_id=<UUID>
|
||||||
GET /api/system?id=<SOLAR_SYSTEM_ID>&slug=<map-slug>
|
GET /api/map/system?id=<SOLAR_SYSTEM_ID>&slug=<map-slug>
|
||||||
|
|
||||||
- **Description:** Retrieves information for a specific system on the specified map. You must provide:
|
- **Description:** Retrieves information for a specific system on the specified map. You must provide:
|
||||||
- `id` (the `solar_system_id`).
|
- `id` (the `solar_system_id`).
|
||||||
@@ -85,7 +87,7 @@ If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` re
|
|||||||
|
|
||||||
#### Example Request
|
#### Example Request
|
||||||
```
|
```
|
||||||
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/system?id=<REDACTED_NUMBER>&slug=<REDACTED_SLUG>"
|
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/map/system?id=<REDACTED_NUMBER>&slug=<REDACTED_SLUG>"
|
||||||
```
|
```
|
||||||
#### Example Response
|
#### Example Response
|
||||||
```
|
```
|
||||||
@@ -111,17 +113,63 @@ If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` re
|
|||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 2. Show Single System Static Info
|
||||||
|
|
||||||
|
GET /api/common/static-system-info?id=<SOLAR_SYSTEM_ID>
|
||||||
|
|
||||||
|
- **Description:** Retrieves the static information for a specific system.
|
||||||
|
|
||||||
|
- **Authentication:** No API token required
|
||||||
|
|
||||||
|
#### Example Request
|
||||||
|
```
|
||||||
|
curl "https://wanderer.example.com/api/common/static-system-info?id=31002229
|
||||||
|
```
|
||||||
|
#### Example Response
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"solar_system_id": 31002229,
|
||||||
|
"triglavian_invasion_status": "Normal",
|
||||||
|
"solar_system_name": "J132946",
|
||||||
|
"system_class": 5,
|
||||||
|
"region_id": 11000028,
|
||||||
|
"constellation_id": 21000278,
|
||||||
|
"solar_system_name_lc": "j132946",
|
||||||
|
"constellation_name": "E-C00278",
|
||||||
|
"region_name": "E-R00028",
|
||||||
|
"security": "-1.0",
|
||||||
|
"type_description": "Class 5",
|
||||||
|
"class_title": "C5",
|
||||||
|
"is_shattered": false,
|
||||||
|
"effect_name": null,
|
||||||
|
"effect_power": 5,
|
||||||
|
"statics": [
|
||||||
|
"H296"
|
||||||
|
],
|
||||||
|
"wandering": [
|
||||||
|
"D792",
|
||||||
|
"C140",
|
||||||
|
"Z142"
|
||||||
|
],
|
||||||
|
"sun_type_id": 38
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
---
|
||||||
|
|
||||||
### 3. List Tracked Characters
|
### 3. List Tracked Characters
|
||||||
|
|
||||||
GET /api/characters?map_id=<UUID>
|
GET /api/map/characters?map_id=<UUID>
|
||||||
GET /api/characters?slug=<map-slug>
|
GET /api/map/characters?slug=<map-slug>
|
||||||
|
|
||||||
- **Description:** Retrieves a list of tracked characters for the specified map (by `map_id` or `slug`), including metadata such as corporation/alliance details.
|
- **Description:** Retrieves a list of tracked characters for the specified map (by `map_id` or `slug`), including metadata such as corporation/alliance details.
|
||||||
- **Authentication:** Required via `Authorization` header.
|
- **Authentication:** Required via `Authorization` header.
|
||||||
|
|
||||||
#### Example Request
|
#### Example Request
|
||||||
```
|
```
|
||||||
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/characters?slug=some-slug"
|
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/map/characters?slug=some-slug"
|
||||||
```
|
```
|
||||||
#### Example Response
|
#### Example Response
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user