add source.list, source.create and source.get messages

This commit is contained in:
Emmanuel Garette 2019-12-16 15:13:28 +01:00
parent b567fd88ac
commit b4c48ebc10
8 changed files with 119 additions and 24 deletions

View File

@ -0,0 +1,25 @@
---
uri: source.create
description: |
Créer une source.
pattern: rpc
public: true
parameters:
source_name:
type: String
shortarg: n
description: |
Nom de la source.
source_url:
type: String
shortarg: u
description: |
URL de téléchargement de la source.
response:
type: 'Source'
description: Information sur la source.

View File

@ -1,4 +1,4 @@
uri: source.dataset.updated
uri: source.dataset.update
description: |
Initialise la table pour les versions.
@ -8,14 +8,10 @@ pattern: rpc
public: true
parameters:
source_name:
type: String
source_id:
type: Number
shortarg: s
description: Nom de la source.
source_url:
type: String
shortarg: u
description: URL de la source.
description: ID de la source.
release_name:
type: String
shortarg: r

View File

@ -0,0 +1,20 @@
---
uri: source.get
description: |
Retourne une source.
pattern: rpc
public: true
parameters:
source_name:
type: String
shortarg: n
description: |
Nom de la source.
response:
type: 'Source'
description: Information sur la source.

View File

@ -1,18 +1,13 @@
---
uri: servermodel.source.list
uri: source.list
description: |
Retourne la liste des sources.
sampleuse: |
zephir-client servermodel.source.list
pattern: rpc
public: true
domain: servermodel-domain
response:
type: '[]Dict'
type: '[]Source'
description: Liste des sources disponibles.

View File

@ -0,0 +1,20 @@
---
title: Source
type: object
description: Description d'un source.
properties:
source_id:
type: number
description: ID de la source.
ref: Source.SourceId
source_name:
type: string
description: Nom de la source.
source_url:
type: string
description: URL de téléchargement de la source.
required:
- source_id
- source_name
- source_url

View File

@ -22,5 +22,6 @@ def get_config():
'global': {'message_root_path': 'messages',
'debug': DEBUG,
'internal_user': 'internal',
'rougail_dtd_path': '../rougail/data/creole.dtd'}
'rougail_dtd_path': '../rougail/data/creole.dtd'},
'source': {'root_path': '/srv/seed'}
}

View File

@ -42,7 +42,7 @@ class Risotto(Controller):
def parse_parents(self,
servermodels: Dict,
servermodel: Dist,
servermodel: Dict,
parents: List=None) -> List:
if parents is None:
parents = [servermodel]
@ -95,7 +95,7 @@ class Risotto(Controller):
if not servermodels[new_servermodel]['done']:
servermodel_description = servermodels[new_servermodel]
parent = servermodel_description['parent']
if not servermodelparent_id and parent None:
if not servermodelparent_id and parent is not None:
# parent is a str, so get ID
servermodelparent_id = [await self.get_servermodel_id_by_name(risotto_context,
parent,

View File

@ -1,5 +1,7 @@
from typing import Dict, List
from ...controller import Controller
from ...register import register
from ...context import Context
VERSION_INIT = """
-- Création de la table Source
@ -21,19 +23,55 @@ CREATE TABLE Release (
RELEASE_QUERY = """SELECT ReleaseId as release_id, SourceName as source_name, SourceURL as source_url, ReleaseName as release_name FROM Release, Source WHERE Source.SourceId=Release.ReleaseSourceId"""
class Risotto(Controller):
@register('v1.source.dataset.updated', None, database=True)
async def version_update(self, risotto_context, source_name, source_url, release_name):
@register('v1.source.create', None, database=True)
async def source_create(self,
risotto_context: Context,
source_name: str,
source_url: str) -> Dict:
source_upsert = """INSERT INTO Source(SourceName, SourceURL) VALUES ($1, $2)
ON CONFLICT (SourceName) DO UPDATE SET SourceURL = $2
RETURNING SourceId
"""
source_id = await risotto_context.connection.fetchval(source_upsert,
source_name,
source_url)
return {'source_name': source_name,
'source_url': source_url,
'source_id': source_id}
@register('v1.source.get', None, database=True)
async def source_get(self,
risotto_context: Context,
source_name: str) -> Dict:
source_get = """SELECT SourceId as source_id, SourceName as source_name, SourceURL as source_url
FROM Source
WHERE SourceName = $1
"""
return dict(await risotto_context.connection.fetchrow(source_get,
source_name))
@register('v1.source.list', None, database=True)
async def source_list(self,
risotto_context: Context) -> List[Dict]:
source_list = """SELECT SourceId as source_id, SourceName as source_name, SourceURL as source_url
FROM Source
"""
result = await risotto_context.connection.fetch(source_list)
return [dict(r) for r in result]
@register('v1.source.dataset.update', None, database=True)
async def version_update(self,
risotto_context: Context,
source_id: int,
release_name: str):
release_insert = """INSERT INTO Release(ReleaseName, ReleaseSourceId) VALUES ($1, $2)
RETURNING ReleaseId
"""
source_id = await risotto_context.connection.fetchval(source_upsert, source_name, source_url)
result = await risotto_context.connection.fetchval(release_insert, release_name, source_id)
return {'release_id': result, 'source_name': source_name, 'source_url': source_url, 'release_name': release_name}
release_id = await risotto_context.connection.fetchval(release_insert,
release_name,
source_id)
return {'release_id': release_id,
'release_name': release_name}
@register('v1.source.release.list', None, database=True)
async def release_list(self, risotto_context):