Skip to content

Commit

Permalink
✨ Add endpoint to list workers
Browse files Browse the repository at this point in the history
  • Loading branch information
pajowu committed Nov 16, 2023
1 parent b98265f commit e3d3780
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
40 changes: 40 additions & 0 deletions backend/openapi-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,19 @@ components:
- token
title: Worker
type: object
WorkerBase:
properties:
last_seen:
format: date-time
title: Last Seen
type: string
name:
title: Name
type: string
required:
- name
title: WorkerBase
type: object
info:
title: FastAPI
version: 0.1.0
Expand Down Expand Up @@ -1412,6 +1425,33 @@ paths:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: Read User
/api/v1/worker/:
get:
operationId: list_workers_api_v1_worker__get
parameters:
- in: header
name: Api-Token
required: true
schema:
title: Api-Token
type: string
responses:
'200':
content:
application/json:
schema:
items:
$ref: '#/components/schemas/WorkerBase'
title: Response List Workers Api V1 Worker Get
type: array
description: Successful Response
'422':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: List Workers
/api/v1/worker/create/:
post:
operationId: create_worker_endpoint_api_v1_worker_create__post
Expand Down
18 changes: 16 additions & 2 deletions backend/transcribee_backend/routers/worker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import List

from fastapi import APIRouter, Depends
from sqlmodel import Session
from sqlmodel import Session, select
from sqlmodel.main import SQLModel

from transcribee_backend.auth import (
Expand All @@ -10,7 +12,7 @@
from transcribee_backend.models import (
ApiToken,
)
from transcribee_backend.models.worker import Worker
from transcribee_backend.models.worker import Worker, WorkerBase

worker_router = APIRouter()

Expand All @@ -26,3 +28,15 @@ def create_worker_endpoint(
_token: ApiToken = Depends(get_api_token),
) -> Worker:
return create_worker(session=session, name=worker.name)


@worker_router.get("/")
def list_workers(
session: Session = Depends(get_session),
_token: ApiToken = Depends(get_api_token),
) -> List[WorkerBase]:
statement = select(Worker)
return [
WorkerBase(name=worker.name, last_seen=worker.last_seen)
for worker in session.exec(statement).all()
]
36 changes: 36 additions & 0 deletions frontend/src/openapi-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export interface paths {
/** Read User */
get: operations["read_user_api_v1_users_me__get"];
};
"/api/v1/worker/": {
/** List Workers */
get: operations["list_workers_api_v1_worker__get"];
};
"/api/v1/worker/create/": {
/** Create Worker Endpoint */
post: operations["create_worker_endpoint_api_v1_worker_create__post"];
Expand Down Expand Up @@ -471,6 +475,16 @@ export interface components {
/** Token */
token: string;
};
/** WorkerBase */
WorkerBase: {
/**
* Last Seen
* Format: date-time
*/
last_seen?: string;
/** Name */
name: string;
};
};
responses: never;
parameters: never;
Expand Down Expand Up @@ -1150,6 +1164,28 @@ export interface operations {
};
};
};
/** List Workers */
list_workers_api_v1_worker__get: {
parameters: {
header: {
"Api-Token": string;
};
};
responses: {
/** @description Successful Response */
200: {
content: {
"application/json": (components["schemas"]["WorkerBase"])[];
};
};
/** @description Validation Error */
422: {
content: {
"application/json": components["schemas"]["HTTPValidationError"];
};
};
};
};
/** Create Worker Endpoint */
create_worker_endpoint_api_v1_worker_create__post: {
parameters: {
Expand Down

0 comments on commit e3d3780

Please sign in to comment.