M2-T03: add read-only data JSON API
- GET /api/locations (inclusive time window start/end, pagination, cap 5000) - GET /api/poo (pagination, cap 1000, newest first) - GET /api/public-ip (current state + recent history, cap 1000) - all session-protected, read-only, bounded (no full-table export) - typed response schemas; register router; regenerate openapi/ - tests/test_api_data.py
This commit is contained in:
@@ -350,6 +350,198 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/locations": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"api-data"
|
||||
],
|
||||
"summary": "Get Locations",
|
||||
"description": "Return location records with optional time-window filtering and pagination.\n\n- ``start`` / ``end`` are ISO8601 strings; filtering is **inclusive** on both bounds.\n- Results are ordered by ``datetime`` ascending.\n- ``limit`` is capped at 5000 to prevent full-table exports.",
|
||||
"operationId": "get_locations_api_locations_get",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"maximum": 5000,
|
||||
"minimum": 1,
|
||||
"default": 1000,
|
||||
"title": "Limit"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "offset",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"default": 0,
|
||||
"title": "Offset"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "start",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"title": "Start"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "end",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"title": "End"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/LocationsResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Validation Error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/HTTPValidationError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/poo": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"api-data"
|
||||
],
|
||||
"summary": "Get Poo",
|
||||
"description": "Return poo records ordered by timestamp descending (most recent first).\n\n``limit`` is capped at 1000 to prevent full-table exports.",
|
||||
"operationId": "get_poo_api_poo_get",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"maximum": 1000,
|
||||
"minimum": 1,
|
||||
"default": 100,
|
||||
"title": "Limit"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "offset",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"default": 0,
|
||||
"title": "Offset"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/PooResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Validation Error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/HTTPValidationError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/public-ip": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"api-data"
|
||||
],
|
||||
"summary": "Get Public Ip",
|
||||
"description": "Return the current public IP state and recent history.\n\n- ``state`` is ``null`` if no IP check has been performed yet.\n- ``history`` is ordered by ``observed_at`` descending (most recent first).\n- ``limit`` applies to the history list and is capped at 1000.",
|
||||
"operationId": "get_public_ip_api_public_ip_get",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"maximum": 1000,
|
||||
"minimum": 1,
|
||||
"default": 100,
|
||||
"title": "Limit"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/PublicIPResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Validation Error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/HTTPValidationError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/session": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@@ -843,6 +1035,72 @@
|
||||
"type": "object",
|
||||
"title": "HTTPValidationError"
|
||||
},
|
||||
"LocationRecord": {
|
||||
"properties": {
|
||||
"person": {
|
||||
"type": "string",
|
||||
"title": "Person"
|
||||
},
|
||||
"datetime": {
|
||||
"type": "string",
|
||||
"title": "Datetime"
|
||||
},
|
||||
"latitude": {
|
||||
"type": "number",
|
||||
"title": "Latitude"
|
||||
},
|
||||
"longitude": {
|
||||
"type": "number",
|
||||
"title": "Longitude"
|
||||
},
|
||||
"altitude": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"title": "Altitude"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"required": [
|
||||
"person",
|
||||
"datetime",
|
||||
"latitude",
|
||||
"longitude",
|
||||
"altitude"
|
||||
],
|
||||
"title": "LocationRecord"
|
||||
},
|
||||
"LocationsResponse": {
|
||||
"properties": {
|
||||
"items": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/LocationRecord"
|
||||
},
|
||||
"type": "array",
|
||||
"title": "Items"
|
||||
},
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
"title": "Limit"
|
||||
},
|
||||
"offset": {
|
||||
"type": "integer",
|
||||
"title": "Offset"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"required": [
|
||||
"items",
|
||||
"limit",
|
||||
"offset"
|
||||
],
|
||||
"title": "LocationsResponse"
|
||||
},
|
||||
"LoginRequest": {
|
||||
"properties": {
|
||||
"username": {
|
||||
@@ -884,6 +1142,60 @@
|
||||
],
|
||||
"title": "PasswordChangeRequest"
|
||||
},
|
||||
"PooRecord": {
|
||||
"properties": {
|
||||
"timestamp": {
|
||||
"type": "string",
|
||||
"title": "Timestamp"
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"title": "Status"
|
||||
},
|
||||
"latitude": {
|
||||
"type": "number",
|
||||
"title": "Latitude"
|
||||
},
|
||||
"longitude": {
|
||||
"type": "number",
|
||||
"title": "Longitude"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"required": [
|
||||
"timestamp",
|
||||
"status",
|
||||
"latitude",
|
||||
"longitude"
|
||||
],
|
||||
"title": "PooRecord"
|
||||
},
|
||||
"PooResponse": {
|
||||
"properties": {
|
||||
"items": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/PooRecord"
|
||||
},
|
||||
"type": "array",
|
||||
"title": "Items"
|
||||
},
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
"title": "Limit"
|
||||
},
|
||||
"offset": {
|
||||
"type": "integer",
|
||||
"title": "Offset"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"required": [
|
||||
"items",
|
||||
"limit",
|
||||
"offset"
|
||||
],
|
||||
"title": "PooResponse"
|
||||
},
|
||||
"PublicIPCheckResponse": {
|
||||
"properties": {
|
||||
"status": {
|
||||
@@ -914,6 +1226,158 @@
|
||||
],
|
||||
"title": "PublicIPCheckResponse"
|
||||
},
|
||||
"PublicIPHistorySchema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"title": "Id"
|
||||
},
|
||||
"ipv4": {
|
||||
"type": "string",
|
||||
"title": "Ipv4"
|
||||
},
|
||||
"observed_at": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"title": "Observed At"
|
||||
},
|
||||
"change_type": {
|
||||
"type": "string",
|
||||
"title": "Change Type"
|
||||
},
|
||||
"provider": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"title": "Provider"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"ipv4",
|
||||
"observed_at",
|
||||
"change_type",
|
||||
"provider"
|
||||
],
|
||||
"title": "PublicIPHistorySchema"
|
||||
},
|
||||
"PublicIPResponse": {
|
||||
"properties": {
|
||||
"state": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/PublicIPStateSchema"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"history": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/PublicIPHistorySchema"
|
||||
},
|
||||
"type": "array",
|
||||
"title": "History"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"required": [
|
||||
"state",
|
||||
"history"
|
||||
],
|
||||
"title": "PublicIPResponse"
|
||||
},
|
||||
"PublicIPStateSchema": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"title": "Id"
|
||||
},
|
||||
"current_ipv4": {
|
||||
"type": "string",
|
||||
"title": "Current Ipv4"
|
||||
},
|
||||
"previous_ipv4": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"title": "Previous Ipv4"
|
||||
},
|
||||
"first_seen_at": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"title": "First Seen At"
|
||||
},
|
||||
"last_checked_at": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"title": "Last Checked At"
|
||||
},
|
||||
"last_changed_at": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"title": "Last Changed At"
|
||||
},
|
||||
"last_check_status": {
|
||||
"type": "string",
|
||||
"title": "Last Check Status"
|
||||
},
|
||||
"last_check_error": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"title": "Last Check Error"
|
||||
},
|
||||
"last_provider": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"title": "Last Provider"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"current_ipv4",
|
||||
"previous_ipv4",
|
||||
"first_seen_at",
|
||||
"last_checked_at",
|
||||
"last_changed_at",
|
||||
"last_check_status",
|
||||
"last_check_error",
|
||||
"last_provider"
|
||||
],
|
||||
"title": "PublicIPStateSchema"
|
||||
},
|
||||
"SessionResponse": {
|
||||
"properties": {
|
||||
"user": {
|
||||
|
||||
@@ -222,6 +222,148 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/HTTPValidationError'
|
||||
/api/locations:
|
||||
get:
|
||||
tags:
|
||||
- api-data
|
||||
summary: Get Locations
|
||||
description: 'Return location records with optional time-window filtering and
|
||||
pagination.
|
||||
|
||||
|
||||
- ``start`` / ``end`` are ISO8601 strings; filtering is **inclusive** on both
|
||||
bounds.
|
||||
|
||||
- Results are ordered by ``datetime`` ascending.
|
||||
|
||||
- ``limit`` is capped at 5000 to prevent full-table exports.'
|
||||
operationId: get_locations_api_locations_get
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
maximum: 5000
|
||||
minimum: 1
|
||||
default: 1000
|
||||
title: Limit
|
||||
- name: offset
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
minimum: 0
|
||||
default: 0
|
||||
title: Offset
|
||||
- name: start
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: 'null'
|
||||
title: Start
|
||||
- name: end
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: 'null'
|
||||
title: End
|
||||
responses:
|
||||
'200':
|
||||
description: Successful Response
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/LocationsResponse'
|
||||
'422':
|
||||
description: Validation Error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/HTTPValidationError'
|
||||
/api/poo:
|
||||
get:
|
||||
tags:
|
||||
- api-data
|
||||
summary: Get Poo
|
||||
description: 'Return poo records ordered by timestamp descending (most recent
|
||||
first).
|
||||
|
||||
|
||||
``limit`` is capped at 1000 to prevent full-table exports.'
|
||||
operationId: get_poo_api_poo_get
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
maximum: 1000
|
||||
minimum: 1
|
||||
default: 100
|
||||
title: Limit
|
||||
- name: offset
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
minimum: 0
|
||||
default: 0
|
||||
title: Offset
|
||||
responses:
|
||||
'200':
|
||||
description: Successful Response
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PooResponse'
|
||||
'422':
|
||||
description: Validation Error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/HTTPValidationError'
|
||||
/api/public-ip:
|
||||
get:
|
||||
tags:
|
||||
- api-data
|
||||
summary: Get Public Ip
|
||||
description: 'Return the current public IP state and recent history.
|
||||
|
||||
|
||||
- ``state`` is ``null`` if no IP check has been performed yet.
|
||||
|
||||
- ``history`` is ordered by ``observed_at`` descending (most recent first).
|
||||
|
||||
- ``limit`` applies to the history list and is capped at 1000.'
|
||||
operationId: get_public_ip_api_public_ip_get
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
maximum: 1000
|
||||
minimum: 1
|
||||
default: 100
|
||||
title: Limit
|
||||
responses:
|
||||
'200':
|
||||
description: Successful Response
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PublicIPResponse'
|
||||
'422':
|
||||
description: Validation Error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/HTTPValidationError'
|
||||
/api/session:
|
||||
get:
|
||||
tags:
|
||||
@@ -566,6 +708,52 @@ components:
|
||||
title: Detail
|
||||
type: object
|
||||
title: HTTPValidationError
|
||||
LocationRecord:
|
||||
properties:
|
||||
person:
|
||||
type: string
|
||||
title: Person
|
||||
datetime:
|
||||
type: string
|
||||
title: Datetime
|
||||
latitude:
|
||||
type: number
|
||||
title: Latitude
|
||||
longitude:
|
||||
type: number
|
||||
title: Longitude
|
||||
altitude:
|
||||
anyOf:
|
||||
- type: number
|
||||
- type: 'null'
|
||||
title: Altitude
|
||||
type: object
|
||||
required:
|
||||
- person
|
||||
- datetime
|
||||
- latitude
|
||||
- longitude
|
||||
- altitude
|
||||
title: LocationRecord
|
||||
LocationsResponse:
|
||||
properties:
|
||||
items:
|
||||
items:
|
||||
$ref: '#/components/schemas/LocationRecord'
|
||||
type: array
|
||||
title: Items
|
||||
limit:
|
||||
type: integer
|
||||
title: Limit
|
||||
offset:
|
||||
type: integer
|
||||
title: Offset
|
||||
type: object
|
||||
required:
|
||||
- items
|
||||
- limit
|
||||
- offset
|
||||
title: LocationsResponse
|
||||
LoginRequest:
|
||||
properties:
|
||||
username:
|
||||
@@ -596,6 +784,46 @@ components:
|
||||
- new_password
|
||||
- confirm_password
|
||||
title: PasswordChangeRequest
|
||||
PooRecord:
|
||||
properties:
|
||||
timestamp:
|
||||
type: string
|
||||
title: Timestamp
|
||||
status:
|
||||
type: string
|
||||
title: Status
|
||||
latitude:
|
||||
type: number
|
||||
title: Latitude
|
||||
longitude:
|
||||
type: number
|
||||
title: Longitude
|
||||
type: object
|
||||
required:
|
||||
- timestamp
|
||||
- status
|
||||
- latitude
|
||||
- longitude
|
||||
title: PooRecord
|
||||
PooResponse:
|
||||
properties:
|
||||
items:
|
||||
items:
|
||||
$ref: '#/components/schemas/PooRecord'
|
||||
type: array
|
||||
title: Items
|
||||
limit:
|
||||
type: integer
|
||||
title: Limit
|
||||
offset:
|
||||
type: integer
|
||||
title: Offset
|
||||
type: object
|
||||
required:
|
||||
- items
|
||||
- limit
|
||||
- offset
|
||||
title: PooResponse
|
||||
PublicIPCheckResponse:
|
||||
properties:
|
||||
status:
|
||||
@@ -619,6 +847,102 @@ components:
|
||||
- checked_at
|
||||
- changed
|
||||
title: PublicIPCheckResponse
|
||||
PublicIPHistorySchema:
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
title: Id
|
||||
ipv4:
|
||||
type: string
|
||||
title: Ipv4
|
||||
observed_at:
|
||||
type: string
|
||||
format: date-time
|
||||
title: Observed At
|
||||
change_type:
|
||||
type: string
|
||||
title: Change Type
|
||||
provider:
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: 'null'
|
||||
title: Provider
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- ipv4
|
||||
- observed_at
|
||||
- change_type
|
||||
- provider
|
||||
title: PublicIPHistorySchema
|
||||
PublicIPResponse:
|
||||
properties:
|
||||
state:
|
||||
anyOf:
|
||||
- $ref: '#/components/schemas/PublicIPStateSchema'
|
||||
- type: 'null'
|
||||
history:
|
||||
items:
|
||||
$ref: '#/components/schemas/PublicIPHistorySchema'
|
||||
type: array
|
||||
title: History
|
||||
type: object
|
||||
required:
|
||||
- state
|
||||
- history
|
||||
title: PublicIPResponse
|
||||
PublicIPStateSchema:
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
title: Id
|
||||
current_ipv4:
|
||||
type: string
|
||||
title: Current Ipv4
|
||||
previous_ipv4:
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: 'null'
|
||||
title: Previous Ipv4
|
||||
first_seen_at:
|
||||
type: string
|
||||
format: date-time
|
||||
title: First Seen At
|
||||
last_checked_at:
|
||||
type: string
|
||||
format: date-time
|
||||
title: Last Checked At
|
||||
last_changed_at:
|
||||
anyOf:
|
||||
- type: string
|
||||
format: date-time
|
||||
- type: 'null'
|
||||
title: Last Changed At
|
||||
last_check_status:
|
||||
type: string
|
||||
title: Last Check Status
|
||||
last_check_error:
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: 'null'
|
||||
title: Last Check Error
|
||||
last_provider:
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: 'null'
|
||||
title: Last Provider
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- current_ipv4
|
||||
- previous_ipv4
|
||||
- first_seen_at
|
||||
- last_checked_at
|
||||
- last_changed_at
|
||||
- last_check_status
|
||||
- last_check_error
|
||||
- last_provider
|
||||
title: PublicIPStateSchema
|
||||
SessionResponse:
|
||||
properties:
|
||||
user:
|
||||
|
||||
Reference in New Issue
Block a user