Various changes
This commit is contained in:
+36
-58
@@ -2,22 +2,16 @@ import html.WebDocument;
|
||||
import tink.http.containers.*;
|
||||
import tink.http.Response;
|
||||
import tink.web.routing.*;
|
||||
import haxe.Json;
|
||||
import tink.sql.drivers.Sqlite;
|
||||
import db.Db;
|
||||
|
||||
import model.MUser;
|
||||
|
||||
import controller.IDGen;
|
||||
import controller.User;
|
||||
|
||||
|
||||
|
||||
typedef T_project = {
|
||||
name : String,
|
||||
description : String,
|
||||
url : String
|
||||
}
|
||||
typedef T_projects = {
|
||||
version : Int,
|
||||
projects : Array<T_project>
|
||||
}
|
||||
|
||||
class Server {
|
||||
static function main() {
|
||||
@@ -40,29 +34,34 @@ class Root {
|
||||
return WebDocument.render();
|
||||
}
|
||||
|
||||
@:get('/test')
|
||||
@:produces('text/html')
|
||||
@async
|
||||
public function create(){
|
||||
//return "yeet";
|
||||
var yeet = "yote";
|
||||
var driver = new tink.sql.drivers.Sqlite();
|
||||
@await var db = new Db('daba2', driver);
|
||||
@await var one = db.MUser.create();
|
||||
@await var two = db.User.insertOne({
|
||||
id: cast null,
|
||||
name: 'Alice',
|
||||
email: 'alice@example.com',
|
||||
password: 'jew'
|
||||
});
|
||||
@await var three = db.User.select({name: User.name, email: User.email}).where(User.email == 'alice@example.com').first().next(function(row) {
|
||||
trace(row.name);return "";
|
||||
});
|
||||
// trace(@await one);
|
||||
// trace(@await two);
|
||||
trace(@await three);
|
||||
return '$yeet';
|
||||
}
|
||||
// @:get('/test')
|
||||
// @:produces('text/html')
|
||||
// @async
|
||||
// public function create(){
|
||||
// //return "yeet";
|
||||
// var yeet = "yote";
|
||||
// var driver = new tink.sql.drivers.Sqlite();
|
||||
// @await var db = new Db('daba2', driver);
|
||||
// @await var one = db.MUser.create();
|
||||
// @await var two = db.MUser.insertOne({
|
||||
// id: cast null,
|
||||
// name: 'Alice',
|
||||
// email: 'alice@example.com',
|
||||
// password: 'jew'
|
||||
// });
|
||||
// @await var three = db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) {
|
||||
// trace(row.name);return "";
|
||||
// });
|
||||
// // trace(@await one);
|
||||
// // trace(@await two);
|
||||
// trace(@await three);
|
||||
// return '$yeet';
|
||||
// }
|
||||
|
||||
@:sub('/user')
|
||||
@:produces('application/json')
|
||||
public function user()
|
||||
return new User();
|
||||
|
||||
@:sub('/projects')
|
||||
@:produces('application/json')
|
||||
@@ -77,30 +76,9 @@ class Root {
|
||||
return strout;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Projects {
|
||||
public function new() {}
|
||||
|
||||
public var path:String = "./res/json/projects.json";
|
||||
|
||||
@:get('/')
|
||||
@:sub('/idgen')
|
||||
@:produces('application/json')
|
||||
public function projects(){
|
||||
var json:String = Utils.getJson(path);
|
||||
return json;
|
||||
}
|
||||
@:get('/project/by_name/$name')
|
||||
@:produces('application/json')
|
||||
public function project(name:String){
|
||||
var json:String = Utils.getJson(path);
|
||||
var _projects:T_projects = Json.parse(json);
|
||||
json = "{}";
|
||||
for(_project in _projects.projects){
|
||||
if(_project.name == name){
|
||||
json = tink.Json.stringify(_project);
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
public function idGen()
|
||||
return new IDGen();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user