Compare commits
No commits in common. "master" and "electron-second-service" have entirely different histories.
master
...
electron-s
3427
tools/app/angular-tour-of-heroes/package-lock.json
generated
3427
tools/app/angular-tour-of-heroes/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,8 +4,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
"build": "ng build",
|
"build": "ng build && cp ./src/electron-app.js ./dist",
|
||||||
"build-prod": "ng build --prod",
|
"electron-start": "./node_modules/.bin/electron dist/electron-app.js",
|
||||||
"test": "ng test",
|
"test": "ng test",
|
||||||
"lint": "ng lint",
|
"lint": "ng lint",
|
||||||
"e2e": "ng e2e"
|
"e2e": "ng e2e"
|
||||||
@ -17,7 +17,6 @@
|
|||||||
"@angular/compiler": "~11.0.6",
|
"@angular/compiler": "~11.0.6",
|
||||||
"@angular/core": "~11.0.6",
|
"@angular/core": "~11.0.6",
|
||||||
"@angular/forms": "~11.0.6",
|
"@angular/forms": "~11.0.6",
|
||||||
"@angular/http": "^7.2.16",
|
|
||||||
"@angular/platform-browser": "~11.0.6",
|
"@angular/platform-browser": "~11.0.6",
|
||||||
"@angular/platform-browser-dynamic": "~11.0.6",
|
"@angular/platform-browser-dynamic": "~11.0.6",
|
||||||
"@angular/router": "~11.0.6",
|
"@angular/router": "~11.0.6",
|
||||||
@ -30,8 +29,9 @@
|
|||||||
"@angular/cli": "~11.0.6",
|
"@angular/cli": "~11.0.6",
|
||||||
"@angular/compiler-cli": "~11.0.6",
|
"@angular/compiler-cli": "~11.0.6",
|
||||||
"@types/jasmine": "~3.6.0",
|
"@types/jasmine": "~3.6.0",
|
||||||
"@types/node": "^12.19.13",
|
"@types/node": "^12.11.1",
|
||||||
"codelyzer": "^6.0.0",
|
"codelyzer": "^6.0.0",
|
||||||
|
"electron": "^11.1.1",
|
||||||
"jasmine-core": "~3.6.0",
|
"jasmine-core": "~3.6.0",
|
||||||
"jasmine-spec-reporter": "~5.0.0",
|
"jasmine-spec-reporter": "~5.0.0",
|
||||||
"karma": "~5.1.0",
|
"karma": "~5.1.0",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
import { HttpClientModule } from '@angular/common/http'
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { HeroesComponent } from './heroes/heroes.component';
|
import { HeroesComponent } from './heroes/heroes.component';
|
||||||
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
|
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
|
||||||
@ -20,8 +20,7 @@ import { DashboardComponent } from './dashboard/dashboard.component';
|
|||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
AppRoutingModule,
|
AppRoutingModule
|
||||||
HttpClientModule
|
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { Hero } from '../hero';
|
import { Hero } from '../hero';
|
||||||
import { HeroService } from '../hero.service';
|
import { HeroService } from '../hero.service';
|
||||||
import { MessageService } from '../message.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dashboard',
|
selector: 'app-dashboard',
|
||||||
@ -11,18 +10,14 @@ import { MessageService } from '../message.service';
|
|||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
heroes: Hero[] = [];
|
heroes: Hero[] = [];
|
||||||
|
|
||||||
constructor(private heroService: HeroService, private messageService: MessageService) { }
|
constructor(private heroService: HeroService) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.getHeroes();
|
this.getHeroes();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHeroes(): Promise<void> {
|
getHeroes(): void {
|
||||||
try {
|
this.heroService.getHeroes().subscribe(heroes => this.heroes = heroes.slice(1, 5));
|
||||||
this.heroes = await this.heroService.getHeroes();
|
|
||||||
} catch (err) {
|
|
||||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import { Location } from '@angular/common';
|
|||||||
|
|
||||||
import { Hero } from '../hero';
|
import { Hero } from '../hero';
|
||||||
import { HeroService } from '../hero.service';
|
import { HeroService } from '../hero.service';
|
||||||
import { MessageService } from '../message.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-hero-detail',
|
selector: 'app-hero-detail',
|
||||||
@ -15,31 +14,22 @@ export class HeroDetailComponent implements OnInit {
|
|||||||
|
|
||||||
@Input() hero: Hero;
|
@Input() hero: Hero;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private heroService: HeroService, private location: Location, private messageService: MessageService) { }
|
constructor(private route: ActivatedRoute, private heroService: HeroService, private location: Location) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.getHero();
|
this.getHero();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHero(): Promise<void> {
|
getHero(): void {
|
||||||
try {
|
const id = +this.route.snapshot.paramMap.get('id');
|
||||||
const id = +this.route.snapshot.paramMap.get('id');
|
this.heroService.getHero(id).subscribe(hero => this.hero = hero);
|
||||||
this.hero = await this.heroService.getHero(id)
|
|
||||||
} catch (err) {
|
|
||||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
goBack(): void {
|
goBack(): void {
|
||||||
this.location.back();
|
this.location.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(): Promise<void> {
|
save(): void {
|
||||||
try {
|
this.heroService.updateHero(this.hero).subscribe(() => this.goBack());
|
||||||
await this.heroService.updateHero(this.hero)
|
|
||||||
this.goBack()
|
|
||||||
} catch (err) {
|
|
||||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,29 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable, of } from 'rxjs';
|
import { Observable, of } from 'rxjs';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
||||||
|
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
|
import { HEROES } from './mock-heroes';
|
||||||
import { MessageService } from './message.service';
|
import { MessageService } from './message.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class HeroService {
|
export class HeroService {
|
||||||
constructor(private messageService: MessageService, private http: HttpClient) { }
|
|
||||||
|
|
||||||
getHeroes(): Promise<Hero[]> {
|
constructor(private messageService: MessageService) { }
|
||||||
|
|
||||||
|
getHeroes(): Observable<Hero[]> {
|
||||||
this.messageService.add('HeroService: fetched heroes');
|
this.messageService.add('HeroService: fetched heroes');
|
||||||
return this.http.get<Hero[]>(`http://172.16.3.185:5000/heroes/heroes`).toPromise()
|
return of(HEROES);
|
||||||
}
|
}
|
||||||
|
|
||||||
getHero(id: number): Promise<Hero> {
|
getHero(id: number): Observable<Hero> {
|
||||||
this.messageService.add(`HeroService: fetch hero id=${id}`);
|
this.messageService.add(`HeroService: fetch hero id=${id}`);
|
||||||
return this.http.get<Hero>(`http://172.16.3.185:5000/heroes/hero/${id}`).toPromise()
|
return of(HEROES.find(hero => hero.id === id));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHero(hero: Hero): Promise<any> {
|
updateHero(hero: Hero): Observable<any> {
|
||||||
this.messageService.add(`HeroService: save change: id=${hero.id}, name=${hero.name}`);
|
this.messageService.add(`HeroService: save change: id=${hero.id}, name=${hero.name}`);
|
||||||
return this.http.put<Hero>(`http://172.16.3.185:5000/heroes/hero/${hero.id}`, hero).toPromise()
|
return of(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,8 @@ export class HeroesComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(private heroService: HeroService, private messageService: MessageService) { }
|
constructor(private heroService: HeroService, private messageService: MessageService) { }
|
||||||
|
|
||||||
async getHeroes() {
|
getHeroes(): void {
|
||||||
try {
|
this.heroService.getHeroes().subscribe(heroes => this.heroes = heroes);
|
||||||
this.heroes = await this.heroService.getHeroes();
|
|
||||||
} catch (err) {
|
|
||||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
30
tools/app/angular-tour-of-heroes/src/electron-app.js
vendored
Normal file
30
tools/app/angular-tour-of-heroes/src/electron-app.js
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
const { create } = require('domain')
|
||||||
|
const { app, BrowserWindow } = require('electron')
|
||||||
|
|
||||||
|
let mainWindow
|
||||||
|
function createWindow() {
|
||||||
|
mainWindow = new BrowserWindow({
|
||||||
|
width: 800,
|
||||||
|
height: 600,
|
||||||
|
autoHideMenuBar: false
|
||||||
|
})
|
||||||
|
mainWindow.loadURL('file://' + __dirname + '/angular-tour-of-heroes/index.html')
|
||||||
|
mainWindow.webContents.openDevTools()
|
||||||
|
mainWindow.on('closed', () => {
|
||||||
|
mainWindow = null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
app.on('ready', createWindow)
|
||||||
|
|
||||||
|
app.on('window-all-closed', () => {
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
app.quit()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.on('activate', () => {
|
||||||
|
if (mainWindow === null) {
|
||||||
|
createWindow()
|
||||||
|
}
|
||||||
|
})
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>AngularTourOfHeroes</title>
|
<title>AngularTourOfHeroes</title>
|
||||||
<base href="/">
|
<base href="./">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
</head>
|
</head>
|
||||||
|
@ -1,64 +1,27 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
const mariadb = require('mariadb');
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const mariadb_1 = __importDefault(require("mariadb"));
|
|
||||||
let conn;
|
let conn;
|
||||||
class DbHandle {
|
mariadb.createConnection({
|
||||||
constructor() { }
|
host: 'database',
|
||||||
async connect() {
|
user: 'heroes',
|
||||||
this._conn = await mariadb_1.default.createConnection({
|
password: 'test123',
|
||||||
host: '172.16.10.18',
|
database: 'heroes'
|
||||||
user: 'heroes',
|
})
|
||||||
password: 'test123',
|
.then(conn => {
|
||||||
database: 'heroes'
|
conn.query("SELECT * FROM hero")
|
||||||
});
|
.then((rows) => {
|
||||||
}
|
console.log(rows);
|
||||||
async getHeroes() {
|
return rows;
|
||||||
var _a, _b;
|
|
||||||
const result = (_b = await ((_a = this._conn) === null || _a === void 0 ? void 0 : _a.query("SELECT id, name FROM hero"))) !== null && _b !== void 0 ? _b : Promise.reject(new Error('Connection not ready 1'));
|
|
||||||
return result.map((row) => {
|
|
||||||
var _a;
|
|
||||||
return { id: row.id, name: (_a = row.name) !== null && _a !== void 0 ? _a : 'unknown' };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
close() {
|
|
||||||
var _a, _b;
|
|
||||||
return (_b = (_a = this._conn) === null || _a === void 0 ? void 0 : _a.end()) !== null && _b !== void 0 ? _b : Promise.reject(new Error('Connection not ready 2'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
const dbHandle = new DbHandle()
|
|
||||||
dbHandle.connect()
|
|
||||||
.then(() => dbHandle.get("SELECT * FROM hero"))
|
|
||||||
.then((result) => {
|
|
||||||
console.log(result)
|
|
||||||
return dbHandle.close()
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.then((res) => {
|
||||||
console.log(err)
|
console.log(res);
|
||||||
|
conn.end();
|
||||||
})
|
})
|
||||||
*/
|
.catch(err => {
|
||||||
async function exec() {
|
console.log(err);
|
||||||
const dbHandle = new DbHandle();
|
conn.end();
|
||||||
try {
|
});
|
||||||
await dbHandle.connect();
|
})
|
||||||
const heroes = await dbHandle.getHeroes();
|
.catch(err => {
|
||||||
console.log(heroes);
|
console.log('not connected');
|
||||||
}
|
});
|
||||||
finally {
|
|
||||||
await dbHandle.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exec().catch((err) => console.log(err.message));
|
|
||||||
/*
|
|
||||||
dbHandle.get("SELECT * FROM hero")
|
|
||||||
.then((result) => {
|
|
||||||
console.log(result)
|
|
||||||
return dbHandle.close()
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err.message)
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "rm -rf ./build && tsc",
|
||||||
"start": "npm run build && node build/index.js",
|
"start": "npm run build && node build/index.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
|
@ -1,75 +1,31 @@
|
|||||||
import mariadb from 'mariadb'
|
const mariadb = require('mariadb')
|
||||||
import { stringify } from 'querystring'
|
|
||||||
|
|
||||||
let conn : mariadb.Connection
|
let conn : mariadb.Connection
|
||||||
|
|
||||||
|
mariadb.createConnection({
|
||||||
interface Hero {
|
host: 'database',
|
||||||
id: number
|
user: 'heroes',
|
||||||
name: string
|
password: 'test123',
|
||||||
}
|
database: 'heroes'
|
||||||
|
|
||||||
class DbHandle {
|
|
||||||
private _conn? : mariadb.Connection
|
|
||||||
|
|
||||||
public constructor() {}
|
|
||||||
|
|
||||||
public async connect() : Promise<void> {
|
|
||||||
this._conn = await mariadb.createConnection({
|
|
||||||
host: '172.16.10.18',
|
|
||||||
user: 'heroes',
|
|
||||||
password: 'test123',
|
|
||||||
database: 'heroes'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getHeroes() : Promise<Hero[]> {
|
|
||||||
const result = await this._conn?.query("SELECT id, name FROM hero") ?? Promise.reject(new Error('Connection not ready 1'))
|
|
||||||
return result.map((row: Record<string, unknown>) => {
|
|
||||||
return { id: row.id, name: row.name ?? 'unknown' }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
public close() : Promise<void> {
|
|
||||||
return this._conn?.end() ?? Promise.reject(new Error('Connection not ready 2'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
const dbHandle = new DbHandle()
|
|
||||||
dbHandle.connect()
|
|
||||||
.then(() => dbHandle.get("SELECT * FROM hero"))
|
|
||||||
.then((result) => {
|
|
||||||
console.log(result)
|
|
||||||
return dbHandle.close()
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.then(conn => {
|
||||||
console.log(err)
|
conn.query("SELECT * FROM hero")
|
||||||
|
.then((rows) => {
|
||||||
|
console.log(rows)
|
||||||
|
return rows
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res)
|
||||||
|
conn.end()
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
conn.end()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
*/
|
.catch(err => {
|
||||||
|
console.log('not connected')
|
||||||
async function exec() : Promise<void> {
|
|
||||||
const dbHandle = new DbHandle()
|
|
||||||
try {
|
|
||||||
await dbHandle.connect()
|
|
||||||
const heroes : Hero[] = await dbHandle.getHeroes()
|
|
||||||
console.log(heroes)
|
|
||||||
} finally {
|
|
||||||
await dbHandle.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exec().catch((err) => console.log(err.message))
|
|
||||||
|
|
||||||
/*
|
|
||||||
dbHandle.get("SELECT * FROM hero")
|
|
||||||
.then((result) => {
|
|
||||||
console.log(result)
|
|
||||||
return dbHandle.close()
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
|
||||||
console.log(err.message)
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
1
tools/ws/.gitignore
vendored
1
tools/ws/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
__pycache__/
|
|
@ -1,36 +0,0 @@
|
|||||||
FROM python:latest
|
|
||||||
|
|
||||||
LABEL Maintainer="Wolfgang Hottgenroth wolfgang.hottgenroth@icloud.com"
|
|
||||||
|
|
||||||
ARG APP_DIR="/opt/app"
|
|
||||||
ARG CONF_DIR="${APP_DIR}/config"
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
apt update && \
|
|
||||||
apt install -y libmariadbclient-dev && \
|
|
||||||
pip3 install mariadb && \
|
|
||||||
pip3 install connexion && \
|
|
||||||
pip3 install connexion[swagger-ui] && \
|
|
||||||
pip3 install uwsgi && \
|
|
||||||
pip3 install flask-cors
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
mkdir -p ${APP_DIR} && \
|
|
||||||
mkdir -p ${CONF_DIR} && \
|
|
||||||
useradd -d ${APP_DIR} -u 1000 user
|
|
||||||
|
|
||||||
COPY *.py ${APP_DIR}/
|
|
||||||
COPY swagger.yaml ${APP_DIR}/
|
|
||||||
COPY server.ini ${CONF_DIR}/
|
|
||||||
|
|
||||||
USER 1000:1000
|
|
||||||
WORKDIR ${APP_DIR}
|
|
||||||
VOLUME ${CONF_DIR}
|
|
||||||
|
|
||||||
EXPOSE 5000
|
|
||||||
EXPOSE 9191
|
|
||||||
|
|
||||||
CMD [ "uwsgi", "./config/server.ini" ]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
|||||||
import mariadb
|
|
||||||
|
|
||||||
pool = None
|
|
||||||
|
|
||||||
def createConnectionPool(config):
|
|
||||||
global pool
|
|
||||||
|
|
||||||
pool = mariadb.ConnectionPool(
|
|
||||||
user = config['user'],
|
|
||||||
password = config['password'],
|
|
||||||
host = config['host'],
|
|
||||||
database = config['database'],
|
|
||||||
pool_name = 'heroes-wep-app',
|
|
||||||
pool_size = 5
|
|
||||||
)
|
|
||||||
|
|
||||||
def getConnection():
|
|
||||||
global pool
|
|
||||||
return pool.get_connection()
|
|
@ -1,2 +0,0 @@
|
|||||||
def say_hello(name=None):
|
|
||||||
return { "message": "Hello {}, from API!".format(name or "") }
|
|
@ -1,63 +0,0 @@
|
|||||||
from dbpool import getConnection
|
|
||||||
|
|
||||||
def get_heroes():
|
|
||||||
try:
|
|
||||||
dbh = getConnection()
|
|
||||||
heroes = []
|
|
||||||
cur = dbh.cursor()
|
|
||||||
cur.execute("SELECT id, name FROM hero")
|
|
||||||
for (id, name) in cur:
|
|
||||||
heroes.append({"id": id, "name": name})
|
|
||||||
return heroes
|
|
||||||
except Exception as err:
|
|
||||||
return str(err), 500
|
|
||||||
finally:
|
|
||||||
dbh.close()
|
|
||||||
|
|
||||||
|
|
||||||
def get_hero(id=None):
|
|
||||||
try:
|
|
||||||
dbh = getConnection()
|
|
||||||
cur = dbh.cursor()
|
|
||||||
cur.execute("SELECT id, name FROM hero WHERE id = ?", (id,))
|
|
||||||
hero = None
|
|
||||||
try:
|
|
||||||
(id, name) = cur.next()
|
|
||||||
hero = { "id": id, "name": name }
|
|
||||||
print("x1: {}\n".format(hero))
|
|
||||||
except StopIteration:
|
|
||||||
return "Hero not found", 404
|
|
||||||
try:
|
|
||||||
(id, name) = cur.next()
|
|
||||||
return "More than one hero by that id ({}, {})".format(id, name), 500
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return hero
|
|
||||||
except Exception as err:
|
|
||||||
return str(err), 500
|
|
||||||
finally:
|
|
||||||
dbh.close()
|
|
||||||
|
|
||||||
|
|
||||||
def put_hero(id=None, hero=None):
|
|
||||||
try:
|
|
||||||
dbh = getConnection()
|
|
||||||
cur = dbh.cursor()
|
|
||||||
cur.execute("UPDATE hero SET name = ? WHERE id = ?", (hero["name"], id))
|
|
||||||
dbh.commit()
|
|
||||||
return 'Hero updated', 200
|
|
||||||
except StopIteration:
|
|
||||||
return 'Hero not found', 404
|
|
||||||
except Exception as err:
|
|
||||||
return str(err), 500
|
|
||||||
finally:
|
|
||||||
dbh.close()
|
|
||||||
|
|
||||||
def post_hero(hero=None):
|
|
||||||
try:
|
|
||||||
newHeroId = len(HEROES)
|
|
||||||
hero["id"] = newHeroId
|
|
||||||
HEROES.append(hero)
|
|
||||||
return 'Hero inserted', 201
|
|
||||||
except Exception as err:
|
|
||||||
return str(err), 403
|
|
@ -1,13 +0,0 @@
|
|||||||
[uwsgi]
|
|
||||||
http = :5000
|
|
||||||
wsgi-file = server.py
|
|
||||||
processes = 4
|
|
||||||
threads = 2
|
|
||||||
stats = :9191
|
|
||||||
|
|
||||||
[database]
|
|
||||||
host = 172.16.10.18
|
|
||||||
user = heroes
|
|
||||||
password = test123
|
|
||||||
database = heroes
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
import connexion
|
|
||||||
from flask_cors import CORS
|
|
||||||
from dbpool import createConnectionPool
|
|
||||||
import configparser
|
|
||||||
|
|
||||||
|
|
||||||
# load configuration
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read('./config/server.ini')
|
|
||||||
|
|
||||||
# prepare database connections
|
|
||||||
createConnectionPool(config['database'])
|
|
||||||
|
|
||||||
# instantiate the webservice
|
|
||||||
app = connexion.App(__name__)
|
|
||||||
app.add_api('swagger.yaml')
|
|
||||||
|
|
||||||
# CORSify it - otherwise Angular won't accept it
|
|
||||||
CORS(app.app)
|
|
||||||
|
|
||||||
# provide the webservice application to uwsgi
|
|
||||||
application = app.app
|
|
@ -1,116 +0,0 @@
|
|||||||
swagger: '2.0'
|
|
||||||
info:
|
|
||||||
title: Heroes
|
|
||||||
version: "0.1"
|
|
||||||
|
|
||||||
paths:
|
|
||||||
/greeting/hello:
|
|
||||||
get:
|
|
||||||
tags: [ "greeting" ]
|
|
||||||
operationId: greeting.say_hello
|
|
||||||
summary: Returns a greeting
|
|
||||||
parameters:
|
|
||||||
- name: name
|
|
||||||
in: query
|
|
||||||
type: string
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: Successful response.
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
message:
|
|
||||||
type: string
|
|
||||||
description: Message greeting
|
|
||||||
|
|
||||||
/heroes/hero/{id}:
|
|
||||||
get:
|
|
||||||
tags: [ "heroes" ]
|
|
||||||
operationId: heroes.get_hero
|
|
||||||
summary: Returns hero by id
|
|
||||||
parameters:
|
|
||||||
- name: id
|
|
||||||
in: path
|
|
||||||
type: integer
|
|
||||||
required: true
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: Successful response.
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/Hero'
|
|
||||||
404:
|
|
||||||
description: Hero not found
|
|
||||||
500:
|
|
||||||
description: Some server error
|
|
||||||
put:
|
|
||||||
tags: [ "heroes" ]
|
|
||||||
operationId: heroes.put_hero
|
|
||||||
summary: Update a hero
|
|
||||||
parameters:
|
|
||||||
- name: id
|
|
||||||
in: path
|
|
||||||
type: integer
|
|
||||||
required: true
|
|
||||||
- name: hero
|
|
||||||
in: body
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/Hero'
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: Hero updated
|
|
||||||
403:
|
|
||||||
description: Some error
|
|
||||||
409:
|
|
||||||
description: Duplicate name
|
|
||||||
404:
|
|
||||||
description: Hero not found
|
|
||||||
500:
|
|
||||||
description: Some server error
|
|
||||||
/heroes/hero:
|
|
||||||
post:
|
|
||||||
tags: [ "heroes" ]
|
|
||||||
operationId: heroes.post_hero
|
|
||||||
summary: Insert a hero
|
|
||||||
parameters:
|
|
||||||
- name: hero
|
|
||||||
in: body
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/Hero'
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: Hero inserted
|
|
||||||
403:
|
|
||||||
description: Some error
|
|
||||||
409:
|
|
||||||
description: Duplicate name
|
|
||||||
500:
|
|
||||||
description: Some server error
|
|
||||||
/heroes/heroes:
|
|
||||||
get:
|
|
||||||
tags: [ "heroes" ]
|
|
||||||
operationId: heroes.get_heroes
|
|
||||||
summary: Returns all heroes
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: Successful response.
|
|
||||||
schema:
|
|
||||||
type: array
|
|
||||||
items:
|
|
||||||
$ref: '#/definitions/Hero'
|
|
||||||
404:
|
|
||||||
description: No heroes available
|
|
||||||
500:
|
|
||||||
description: Some server error
|
|
||||||
|
|
||||||
|
|
||||||
definitions:
|
|
||||||
Hero:
|
|
||||||
description: Hero type
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
name:
|
|
||||||
type: string
|
|
Loading…
x
Reference in New Issue
Block a user