[DEV] add univers and set corect naming of REST call (back not compatible)

This commit is contained in:
Edouard DUPIN 2020-01-09 22:01:44 +01:00
parent e3811efeb6
commit cd05e28102
15 changed files with 345 additions and 46 deletions

View File

@ -78,8 +78,8 @@ def add(_app, _name_api):
return response.json(value)
raise ServerError("No data found", status_code=404)
@elem_blueprint.get('/' + _name_api + '/<id:int>/video', strict_slashes=True)
@doc.summary("get videos list")
@elem_blueprint.get('/' + _name_api + '/<id:int>/video_all', strict_slashes=True)
@doc.summary("get all videos list")
@doc.description("List all the videos availlable for this group.")
@doc.produces(content_type='application/json')
async def retrive_video(request, id):
@ -88,7 +88,7 @@ def add(_app, _name_api):
return response.json(value)
raise ServerError("No data found", status_code=404)
@elem_blueprint.get('/' + _name_api + '/<id:int>/video_no_saison', strict_slashes=True)
@elem_blueprint.get('/' + _name_api + '/<id:int>/video', strict_slashes=True)
@doc.summary("get videos list who have no saison")
@doc.description("List all the videos availlable for this group tht does not depend on saison.")
@doc.produces(content_type='application/json')

View File

@ -95,28 +95,36 @@ def add(_app, _name_api):
return response.json({"count":count_value})
@elem_blueprint.get('/' + _name_api + '/<id:int>/video', strict_slashes=True)
@doc.summary("List the whole video ids")
@elem_blueprint.get('/' + _name_api + '/<id:int>/video_all', strict_slashes=True)
@doc.summary("List the whole video ids even if they are in a group or a univers...")
@doc.description("List all video availlable with this type (list of ids).")
@doc.produces(content_type='application/json')
async def retrive_video(request, id):
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "type_id", id]], filter=["id"])
return response.json(list_values)
@elem_blueprint.get('/' + _name_api + '/<id:int>/video_no_group', strict_slashes=True)
@doc.summary("List the whole video ids")
@doc.description("List all video availlable with this type (list of ids).")
@elem_blueprint.get('/' + _name_api + '/<id:int>/video', strict_slashes=True)
@doc.summary("List the whole video free")
@doc.description("List all video availlable with this type ... not link with an univers or a group.")
@doc.produces(content_type='application/json')
async def retrive_video_no_group(request, id):
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "type_id", id], ["==", "group_id", None]], filter=["id"])
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "type_id", id], ["==", "group_id", None], ["==", "univers_id", None]], filter=["id"])
return response.json(list_values)
@elem_blueprint.get('/' + _name_api + '/<id:int>/group', strict_slashes=True)
@doc.summary("List the whole video ids")
@doc.description("List all video availlable with this type (list of ids).")
@doc.summary("List all group availlable.")
@doc.description("List all groups availlable in this type (not depending of an univers).")
@doc.produces(content_type='application/json')
async def retrive_group(request, id):
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "type_id", id], ["!=", "group_id", None]], filter=["group_id"])
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "type_id", id], ["!=", "group_id", None], ["==", "univers_id", None]], filter=["group_id"])
return response.json(list_values)
@elem_blueprint.get('/' + _name_api + '/<id:int>/univers', strict_slashes=True)
@doc.summary("List all univers availlable.")
@doc.description("List all univers availlable.")
@doc.produces(content_type='application/json')
async def retrive_group(request, id):
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "type_id", id], ["!=", "univers_id", None]], filter=["univers_id"])
return response.json(list_values)
_app.blueprint(elem_blueprint)

122
back/src/api/univers.py Normal file
View File

@ -0,0 +1,122 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
## @author Edouard DUPIN
##
## @copyright 2019, Edouard DUPIN, all right reserved
##
## @license MPL v2.0 (see license file)
##
import time
import json
import os
import sys
import datetime
import time, threading
import realog.debug as debug
from sanic import Sanic
from sanic import response
from sanic import views
from sanic import Blueprint
from sanic.exceptions import ServerError
from sanic_simple_swagger import swagger_blueprint, openapi_blueprint
from sanic_simple_swagger import doc
import tools
import data_interface
import data_global_elements
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)
class DataModelBdd:
id = int
name = str
description = str
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
class DataModel:
name = str
description = str
@elem_blueprint.get('/' + _name_api, strict_slashes=True)
@doc.summary("Show resources")
@doc.description("Display a listing of the resource.")
@doc.produces(content_type='application/json')
async def list(request):
return response.json(data_global_elements.get_interface(_name_api).gets())
@elem_blueprint.post('/' + _name_api, strict_slashes=True)
@doc.summary("Create new resource")
@doc.description("Store a newly created resource in storage.")
@doc.consumes(DataModel, location='body')#, required=True)
@doc.response_success(status=201, description='If successful created')
async def create(request):
return response.json(data_global_elements.get_interface(_name_api).post(request.json))
@elem_blueprint.get('/' + _name_api + '/<id:int>', strict_slashes=True)
@doc.summary("Show resources")
@doc.description("Display a listing of the resource.")
@doc.produces(content_type='application/json')
async def retrive(request, id):
value = data_global_elements.get_interface(_name_api).get(id)
if value != None:
return response.json(value)
raise ServerError("No data found", status_code=404)
@elem_blueprint.put('/' + _name_api + '/<id:int>', strict_slashes=True)
@doc.summary("Update resource")
@doc.description("Update the specified resource in storage.")
@doc.response_success(status=201, description='If successful updated')
async def update(request, id):
ret = data_global_elements.get_interface(_name_api).put(id)
return response.json({})
@elem_blueprint.delete('/' + _name_api + '/<id:int>', strict_slashes=True)
@doc.summary("Remove resource")
@doc.description("Remove the specified resource from storage.")
@doc.response_success(status=201, description='If successful deleted')
async def delete(request, id):
ret = data_global_elements.get_interface(_name_api).delete(id)
if ret == True:
return response.json({})
raise ServerError("No data found", status_code=404)
@elem_blueprint.get('/' + _name_api + '/<id:int>/count', strict_slashes=True)
@doc.summary("Count resources in this cathegory")
@doc.description("count resources in this cathegory, in the whole tree.")
@doc.produces(content_type='application/json')
async def count_values(request, id):
count_value = data_global_elements.get_interface(data_global_elements.API_VIDEO).count(select=[["==", "univers_id", id]])
return response.json({"count":count_value})
@elem_blueprint.get('/' + _name_api + '/<id:int>/video_all', strict_slashes=True)
@doc.summary("List the whole video ids even if they are in a group or a univers...")
@doc.description("List all video availlable with this univers (list of ids).")
@doc.produces(content_type='application/json')
async def retrive_video(request, id):
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "univers_id", id]], filter=["id"])
return response.json(list_values)
@elem_blueprint.get('/' + _name_api + '/<id:int>/video', strict_slashes=True)
@doc.summary("List the whole video free")
@doc.description("List all video availlable with this univers ... not link with an univers or a group.")
@doc.produces(content_type='application/json')
async def retrive_video_no_group(request, id):
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "univers_id", id], ["==", "group_id", None], ["==", "univers_id", None]], filter=["id"])
return response.json(list_values)
@elem_blueprint.get('/' + _name_api + '/<id:int>/group', strict_slashes=True)
@doc.summary("List all group availlable.")
@doc.description("List all groups availlable in this univers (not depending of an univers).")
@doc.produces(content_type='application/json')
async def retrive_group(request, id):
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "univers_id", id], ["!=", "group_id", None], ["==", "univers_id", None]], filter=["group_id"])
return response.json(list_values)
_app.blueprint(elem_blueprint)

View File

@ -32,6 +32,10 @@ import data_global_elements
def generate_name(_value):
group_name = ""
if "univers_id" in _value.keys():
univers_property = data_global_elements.get_interface(data_global_elements.API_UNIVERS).get(_value["univers_id"])
if univers_property != None:
group_name = univers_property["name"] + ":"
if "group_id" in _value.keys():
group_property = data_global_elements.get_interface(data_global_elements.API_GROUP).get(_value["group_id"])
if group_property != None:
@ -70,6 +74,7 @@ def add(_app, _name_api):
type_id = int
saison_id = [int, type(None)]
episode = [int, type(None)]
univers_id = [int, type(None)]
group_id = [int, type(None)]
name = str
description = [str, type(None)]
@ -86,6 +91,7 @@ def add(_app, _name_api):
type_id = int
saison_id = int
episode = int
univers_id = int
group_id = int
name = str
description = str
@ -115,7 +121,7 @@ def add(_app, _name_api):
for type_key in ["create_date"]:
if type_key in request.json.keys():
raise ServerError("Forbidden: Must not be set Key '" + type_key + "'", status_code=403)
for type_key in ["saison_id","episode","date","time","group_id","description"]:
for type_key in ["saison_id","episode","date","time","univers_id","group_id","description"]:
if type_key not in request.json.keys():
request.json[type_key] = None
request.json["create_date"] = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'

View File

@ -121,6 +121,7 @@ def add_interface(_name, _default_value = None):
add_interface(data_global_elements.API_DATA)
add_interface(data_global_elements.API_TYPE, default_values_type)
add_interface(data_global_elements.API_UNIVERS)
add_interface(data_global_elements.API_GROUP)
add_interface(data_global_elements.API_SAISON)
add_interface(data_global_elements.API_VIDEO)
@ -131,6 +132,9 @@ api_root.add(app)
import api.type as api_type
api_type.add(app, data_global_elements.API_TYPE)
import api.univers as api_univers
api_univers.add(app, data_global_elements.API_UNIVERS)
import api.group as api_group
api_group.add(app, data_global_elements.API_GROUP)

View File

@ -54,8 +54,8 @@ def check_save():
check_save()
API_TYPE = "type"
API_UNIVERS = "univers"
API_GROUP = "group"
API_SAISON = "saison"
API_VIDEO = "video"

View File

@ -37,6 +37,7 @@ import { ArianeService } from './ariane.service';
import { CookiesService } from './cookies.service';
import { HttpWrapperService } from './http-wrapper.service';
import { UserService } from './user.service';
import { UniversService } from './univers.service';
import { GroupService } from './group.service';
import { TypeService } from './type.service';
import { SaisonService } from './saison.service';
@ -83,6 +84,7 @@ import { AppComponent } from './app.component';
CookiesService,
UserService,
TypeService,
UniversService,
GroupService,
SaisonService,
VideoService,

View File

@ -7,6 +7,7 @@
import { Injectable, Output, EventEmitter } from '@angular/core'
import { TypeService } from 'app/type.service';
import { UniversService } from 'app/univers.service';
import { GroupService } from 'app/group.service';
import { SaisonService } from 'app/saison.service';
@ -30,6 +31,7 @@ export class ArianeService {
constructor(
private typeService: TypeService,
private universService: UniversService,
private groupService: GroupService,
private saisonService: SaisonService) {
@ -73,15 +75,13 @@ export class ArianeService {
this.univers_id = id;
this.univers_name = "??--??";
let self = this;
/*
this.universService.get(id)
.then(function(response) {
self.univers_name = response.number
self.saison_change.emit(self.univers_id);
self.univers_change.emit(self.univers_id);
}).catch(function(response) {
self.saison_change.emit(self.univers_id);
self.univers_change.emit(self.univers_id);
});
*/
}
getUniversId():number {
return this.univers_id;
@ -97,9 +97,9 @@ export class ArianeService {
this.groupService.get(id)
.then(function(response) {
self.group_name = response.name
self.group_change.emit(self.type_id);
self.group_change.emit(self.group_id);
}).catch(function(response) {
self.group_change.emit(self.type_id);
self.group_change.emit(self.group_id);
});
}
getGroupId():number {

View File

@ -46,7 +46,7 @@ export class GroupDetailComponent implements OnInit {
self.saisons_error = "Can not get the list of saison in this group";
self.saisons = []
});
this.groupService.getVideoNoSaison(this.id_group)
this.groupService.getVideo(this.id_group)
.then(function(response) {
self.videos_error = "";
self.videos = response

View File

@ -41,6 +41,10 @@ export class GroupService {
return this.get_specific(_id);
};
getVideoAll(_id:number):any {
return this.get_specific(_id, "video_all");
};
getVideo(_id:number):any {
return this.get_specific(_id, "video");
};
@ -48,9 +52,5 @@ export class GroupService {
getSaison(_id:number):any {
return this.get_specific(_id, "saison");
};
getVideoNoSaison(_id:number):any {
return this.get_specific(_id, "video_no_saison");
};
}

View File

@ -20,7 +20,7 @@ import { ArianeService } from '../ariane.service';
host: { '[@fadeInAnimation]': '' }
})
export class HomeComponent implements OnInit {
data_list = [{name:"lkjlkjlkj"}, {name:"lkjlkj222lkj"}, {name:"lkjlk333jlkj"}];
data_list = [];
error = "";
constructor(private router: Router,
private locate: Location,

View File

@ -26,14 +26,14 @@ export class TopMenuComponent implements OnInit {
public ariane_type_id: number = null;
public ariane_type_name: string = null;
public ariane_univers_id: number = 5;
public ariane_univers_name: string = "sdfsdf";
public ariane_univers_id: number = null;
public ariane_univers_name: string = null;
public ariane_group_id: number = null;
public ariane_group_name: string = null;
public ariane_saison_id: number = 6;
public ariane_saison_name: string = "lkjlkjlkjlkjlkjlkj";
public ariane_saison_id: number = null;
public ariane_saison_name: string = null;
constructor(private router: Router,
private sessionService: SessionService,
@ -56,21 +56,20 @@ export class TopMenuComponent implements OnInit {
console.log(" avatar:" + this.avatar);
}
});
this.arianeService.type_change.subscribe(id => {
console.log("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
this.ariane_type_id = id;
this.arianeService.type_change.subscribe(type_id => {
this.ariane_type_id = type_id;
this.ariane_type_name = this.arianeService.getTypeName();
});
this.arianeService.univers_change.subscribe(id => {
this.ariane_univers_id = id;
this.arianeService.univers_change.subscribe(univers_id => {
this.ariane_univers_id = univers_id;
this.ariane_univers_name = this.arianeService.getUniversName();
});
this.arianeService.group_change.subscribe(id => {
this.ariane_group_id = id;
this.arianeService.group_change.subscribe(group_id => {
this.ariane_group_id = group_id;
this.ariane_group_name = this.arianeService.getGroupName();
});
this.arianeService.saison_change.subscribe(id => {
this.ariane_saison_id = id;
this.arianeService.saison_change.subscribe(saison_id => {
this.ariane_saison_id = saison_id;
this.ariane_saison_name = this.arianeService.getSaisonName();
});
}
@ -122,19 +121,35 @@ export class TopMenuComponent implements OnInit {
}
onArianeType(): void {
console.log("onArianeType()");
console.log("onArianeType(" + this.ariane_type_id + ")");
this.router.navigate(['type/' + this.ariane_type_id ]);
this.ariane_univers_id = null;
this.ariane_univers_name = null;
this.ariane_group_id = null;
this.ariane_group_name = null;
this.ariane_saison_id = null;
this.ariane_saison_name = null;
}
onArianeUnivers(): void {
console.log("onArianeUnivers()");
console.log("onArianeUnivers(" + this.ariane_univers_id + ")");
this.router.navigate(['univers/' + this.ariane_univers_id ]);
this.ariane_group_id = null;
this.ariane_group_name = null;
this.ariane_saison_id = null;
this.ariane_saison_name = null;
}
onArianeGroup(): void {
console.log("onArianeGroup()");
console.log("onArianeGroup(" + this.ariane_group_id + ")");
this.router.navigate(['group/' + this.ariane_group_id ]);
this.ariane_saison_id = null;
this.ariane_saison_name = null;
}
onArianeSaison(): void {
console.log("onArianeSaison()");
console.log("onArianeSaison(" + this.ariane_saison_id + ")");
this.router.navigate(['saison/' + this.ariane_saison_id ]);
}
}

View File

@ -53,7 +53,7 @@ export class TypeDetailComponent implements OnInit {
self.groups_error = "Wrong e-mail/login or password";
self.groups = []
});
this.typeService.getSubVideoNoGroup(this.type_id)
this.typeService.getSubVideo(this.type_id)
.then(function(response) {
self.videos_error = "";
self.videos = response

View File

@ -100,11 +100,11 @@ export class TypeService {
};
getSubVideoNoGroup(_id: number):any {
getSubVideo(_id: number):any {
console.log("Get All data from types");
let currentDate:number = dateFormat(new Date(), 'm-d-Y h:i:s ms');
const httpOption = { 'Content-Type': 'application/json' };
let url = "type/" + _id + "/video_no_group";
let url = "type/" + _id + "/video";
console.log("call GET " + url);
return new Promise((resolve, reject) => {
@ -124,7 +124,32 @@ export class TypeService {
}
});
});
};
getSubUnivers(_id: number):any {
console.log("Get All data from types");
let currentDate:number = dateFormat(new Date(), 'm-d-Y h:i:s ms');
const httpOption = { 'Content-Type': 'application/json' };
let url = "type/" + _id + "/univers";
console.log("call GET " + url);
return new Promise((resolve, reject) => {
this.http.get(url, httpOption, {})
.then(function(response: any) {
if (response.status == 200) {
resolve(response.data);
console.log("get data from type : " + response.data);
return;
}
reject("An error occured");
}, function(response: any) {
if (typeof response.data === 'undefined') {
reject("return ERROR undefined");
} else {
reject("return ERROR " + JSON.stringify(response.data, null, 2));
}
});
});
};
}

View File

@ -0,0 +1,117 @@
import { Injectable } from '@angular/core';
import { HttpWrapperService } from 'app/http-wrapper.service';
@Injectable()
export class UniversService {
// 0: Not hide password; 1 hide password;
private identificationVersion: number = 1;
constructor(private http: HttpWrapperService) {
console.log("Start universService");
}
getData():any {
console.log("Get All data from types");
const httpOption = { 'Content-Type': 'application/json' };
let url = "univers";
console.log("call GET " + url);
return new Promise((resolve, reject) => {
this.http.get(url, httpOption, {})
.then(function(response: any) {
if (response.status == 200) {
resolve(response.data);
console.log("get data from univers : " + response.data);
return;
}
reject("An error occured");
}, function(response: any) {
if (typeof response.data === 'undefined') {
reject("return ERROR undefined");
} else {
reject("return ERROR " + JSON.stringify(response.data, null, 2));
}
});
});
};
get(_id:number):any {
console.log("Get All data from univers");
const httpOption = { 'Content-Type': 'application/json' };
let url = "univers/" + _id;
console.log("call GET " + url);
return new Promise((resolve, reject) => {
this.http.get(url, httpOption, {})
.then(function(response: any) {
if (response.status == 200) {
resolve(response.data);
console.log("get data from type : " + response.data);
return;
}
reject("An error occured");
}, function(response: any) {
if (typeof response.data === 'undefined') {
reject("return ERROR undefined");
} else {
reject("return ERROR " + JSON.stringify(response.data, null, 2));
}
});
});
};
getSubGroup(_id: number):any {
console.log("Get All data from types");
const httpOption = { 'Content-Type': 'application/json' };
let url = "univers/" + _id + "/group";
console.log("call GET " + url);
return new Promise((resolve, reject) => {
this.http.get(url, httpOption, {})
.then(function(response: any) {
if (response.status == 200) {
resolve(response.data);
console.log("get data from type : " + response.data);
return;
}
reject("An error occured");
}, function(response: any) {
if (typeof response.data === 'undefined') {
reject("return ERROR undefined");
} else {
reject("return ERROR " + JSON.stringify(response.data, null, 2));
}
});
});
};
getSubVideo(_id: number):any {
console.log("Get All data from types");
const httpOption = { 'Content-Type': 'application/json' };
let url = "univers/" + _id + "/video_no_group";
console.log("call GET " + url);
return new Promise((resolve, reject) => {
this.http.get(url, httpOption, {})
.then(function(response: any) {
if (response.status == 200) {
resolve(response.data);
console.log("get data from type : " + response.data);
return;
}
reject("An error occured");
}, function(response: any) {
if (typeof response.data === 'undefined') {
reject("return ERROR undefined");
} else {
reject("return ERROR " + JSON.stringify(response.data, null, 2));
}
});
});
};
}