Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
samj committed Aug 13, 2024
2 parents 451c30d + 2379f71 commit 5ca8f9d
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 128 deletions.
54 changes: 27 additions & 27 deletions apis/paios/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ paths:
description: Not Found
parameters:
- $ref: '#/components/parameters/id'
/channels:
/resources:
get:
tags:
- Channel Management
summary: Retrieve all channels
description: Retrieve the information of all channels.
- Resource Management
summary: Retrieve all resources
description: Retrieve the information of all resources.
parameters:
- $ref: '#/components/parameters/sort'
- $ref: '#/components/parameters/range'
Expand All @@ -264,31 +264,31 @@ paths:
schema:
type: array
items:
$ref: '#/components/schemas/Channel'
$ref: '#/components/schemas/Resource'
headers:
X-Total-Count:
$ref: '#/components/headers/X-Total-Count'
post:
summary: Create new channel
summary: Create new resource
tags:
- Channel Management
- Resource Management
responses:
'200':
description: OK
'400':
description: Missing Required Information
description: Create a new channel.
description: Create a new resource.
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChannelCreate'
'/channels/{id}':
'/resources/{id}':
get:
tags:
- Channel Management
summary: Retrieve channel by id
description: Retrieve the information of the channel with the specified id.
- Resource Management
summary: Retrieve resource by id
description: Retrieve the information of the resource with the specified id.
parameters:
- $ref: '#/components/parameters/id'
responses:
Expand All @@ -297,27 +297,27 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/Channel'
$ref: '#/components/schemas/Resource'
put:
tags:
- Channel Management
summary: Update channel by key
description: Updates the channel with the specified id.
- Resource Management
summary: Update resource by key
description: Updates the resource with the specified id.
parameters:
- $ref: '#/components/parameters/id'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Channel'
$ref: '#/components/schemas/Resource'
responses:
'200':
description: OK
delete:
tags:
- Channel Management
summary: Delete channel by key
description: Delete a channel with the specified ID.
- Resource Management
summary: Delete resource by key
description: Delete a resource with the specified ID.
parameters:
- $ref: '#/components/parameters/id'
responses:
Expand Down Expand Up @@ -639,8 +639,8 @@ tags:
description: Installation and configuration of abilities
- name: Asset Management
description: Management of assets
- name: Channel Management
description: Discovery and configuration of input/output interfaces/channels
- name: Resource Management
description: Discovery and configuration of input/output interfaces/resources
- name: Configuration Management
description: Management of configuration
- name: Downloads Management
Expand Down Expand Up @@ -908,10 +908,10 @@ components:
$ref: '#/components/schemas/textShort'
required:
- title
Channel:
Resource:
type: object
title: Channel
description: Channels (input/output)
title: Resource
description: Resources (input/output)
properties:
id:
$ref: '#/components/schemas/uuid4ReadOnly'
Expand All @@ -925,8 +925,8 @@ components:
- uri
ChannelCreate:
type: object
title: Channel
description: Channels (input/output)
title: Resource
description: Resources (input/output)
properties:
name:
$ref: '#/components/schemas/name'
Expand Down
18 changes: 9 additions & 9 deletions apis/paios/channel.http → apis/paios/resource.http
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# API testing with Visual Studio Code - REST Client Extention

POST http://localhost:3080/api/v1/channels
POST http://localhost:3080/api/v1/resources
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

{
"name": "My Channel",
"uri": "http://localhost:3080/channels/my-channel"
"name": "My Resource",
"uri": "http://localhost:3080/resources/my-resource"
}

###
PUT http://localhost:3080/api/v1/channels/llm-api
PUT http://localhost:3080/api/v1/resources/llm-api
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

{
"id": "llm-api",
"name": "LLM API",
"uri": "http://localhost:3080/channels/llm-api"
"uri": "http://localhost:3080/resources/llm-api"
}

###
PUT http://localhost:3080/api/v1/channels/imap-sync
PUT http://localhost:3080/api/v1/resources/imap-sync
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

Expand All @@ -33,18 +33,18 @@ Content-Type: application/json

###

DELETE http://localhost:3080/api/v1/channels/llm-api
DELETE http://localhost:3080/api/v1/resources/llm-api
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

GET http://localhost:3080/api/v1/channels/llm-api
GET http://localhost:3080/api/v1/resources/llm-api
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

GET http://localhost:3080/api/v1/channels
GET http://localhost:3080/api/v1/resources
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json
46 changes: 0 additions & 46 deletions backend/api/ChannelsView.py

This file was deleted.

46 changes: 46 additions & 0 deletions backend/api/ResourcesView.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from starlette.responses import JSONResponse, Response
from common.paths import api_base_url
from backend.managers.ResourcesManager import ResourcesManager
from backend.pagination import parse_pagination_params
from backend.schemas import ChannelCreateSchema
from typing import List

class ResourcesView:
def __init__(self):
self.cm = ResourcesManager()

async def get(self, resource_id: str):
resource = await self.cm.retrieve_resource(resource_id)
if resource is None:
return JSONResponse({"error": "Resource not found"}, status_code=404)
return JSONResponse(resource.model_dump(), status_code=200)

async def post(self, body: ChannelCreateSchema):
new_resource = await self.cm.create_resource(body)
return JSONResponse(new_resource.model_dump(), status_code=201, headers={'Location': f'{api_base_url}/resources/{new_resource.id}'})

async def put(self, resource_id: str, body: ChannelCreateSchema):
updated_resource = await self.cm.update_resource(resource_id, body)
if updated_resource is None:
return JSONResponse({"error": "Resource not found"}, status_code=404)
return JSONResponse(updated_resource.model_dump(), status_code=200)

async def delete(self, resource_id: str):
success = await self.cm.delete_resource(resource_id)
if not success:
return JSONResponse({"error": "Resource not found"}, status_code=404)
return Response(status_code=204)

async def search(self, filter: str = None, range: str = None, sort: str = None):
result = parse_pagination_params(filter, range, sort)
if isinstance(result, JSONResponse):
return result

offset, limit, sort_by, sort_order, filters = result

resources, total_count = await self.cm.retrieve_resources(limit=limit, offset=offset, sort_by=sort_by, sort_order=sort_order, filters=filters)
headers = {
'X-Total-Count': str(total_count),
'Content-Range': f'resources {offset}-{offset + len(resources) - 1}/{total_count}'
}
return JSONResponse([resource.model_dump() for resource in resources], status_code=200, headers=headers)
2 changes: 1 addition & 1 deletion backend/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# otherwise connexion will throw "TypeError: 'module' object is not callable"
from .AbilitiesView import AbilitiesView
from .AssetsView import AssetsView
from .ChannelsView import ChannelsView
from .ResourcesView import ResourcesView
from .ConfigView import ConfigView
from .DownloadsView import DownloadsView
from .UsersView import UsersView
Expand Down
Loading

0 comments on commit 5ca8f9d

Please sign in to comment.