Various changes
This commit is contained in:
parent
5e0768263f
commit
87a3014c8d
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
api2/
|
||||
**/build/
|
||||
out.js
|
||||
out.js
|
||||
api/node_modules/
|
||||
2081
api/package-lock.json
generated
Normal file
2081
api/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
4945
api/res/txt/first-names.txt
Normal file
4945
api/res/txt/first-names.txt
Normal file
File diff suppressed because it is too large
Load Diff
88799
api/res/txt/last-names.txt
Normal file
88799
api/res/txt/last-names.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -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();
|
||||
|
||||
}
|
||||
|
||||
@ -21,4 +21,28 @@ class Utils{
|
||||
}
|
||||
return strout;
|
||||
}
|
||||
public static function getTXT(path:String):String
|
||||
{
|
||||
var strout:String = "";
|
||||
if(FileSystem.exists(path)){
|
||||
strout = File.getContent(path);
|
||||
}
|
||||
return strout;
|
||||
}
|
||||
public static function parseLines(str:String):Array<String>
|
||||
{
|
||||
var lineArray:Array<String> = [];
|
||||
if(str.indexOf("\r") == -1)
|
||||
lineArray = str.split("\n");
|
||||
else if(str.indexOf("\n") == -1){
|
||||
lineArray = str.split("\r");
|
||||
}
|
||||
else if(str.indexOf("\r\n") == -1){
|
||||
lineArray = str.split("\n\r");
|
||||
}
|
||||
else{
|
||||
lineArray = str.split("\r\n");
|
||||
}
|
||||
return lineArray;
|
||||
}
|
||||
}
|
||||
67
api/src/controller/IDGen.hx
Normal file
67
api/src/controller/IDGen.hx
Normal file
@ -0,0 +1,67 @@
|
||||
package controller;
|
||||
|
||||
import haxe.Json;
|
||||
import Utils;
|
||||
|
||||
typedef T_IDInfo = {
|
||||
var firstname:String;
|
||||
var lastname:String;
|
||||
var birthDay:String;
|
||||
var email:String;
|
||||
var password:String;
|
||||
}
|
||||
|
||||
class IDGen{
|
||||
public function new() {}
|
||||
public static var path:String = "./res/txt/first-names.txt";
|
||||
public static var path2:String = "./res/txt/last-names.txt";
|
||||
|
||||
public static function genID()
|
||||
{
|
||||
|
||||
var firstnames = Utils.parseLines(Utils.getTXT(path));
|
||||
var lastnames = Utils.parseLines(Utils.getTXT(path2));
|
||||
|
||||
var firstname:String = firstnames[ Math.floor(Math.random()*firstnames.length)].toLowerCase();
|
||||
var lastname:String = lastnames[ Math.floor(Math.random()*lastnames.length)].toLowerCase();
|
||||
|
||||
var birthyear:Int = 2003-Math.floor(Math.random()*60);
|
||||
var birthyear2dig:Int = birthyear - 1900;
|
||||
|
||||
while(birthyear2dig >100){
|
||||
birthyear2dig -=100;
|
||||
}
|
||||
|
||||
var id:T_IDInfo = {
|
||||
firstname: firstname,
|
||||
lastname: lastname,
|
||||
birthDay: "01/01/"+birthyear,
|
||||
email: firstname+lastname+(birthyear2dig)+"@gmail.com",
|
||||
password: "4123jk54jhejkrtsdr"
|
||||
};
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
@:get('/')
|
||||
@:produces('application/json')
|
||||
public function id(){
|
||||
var json:String = Json.stringify(genID());
|
||||
return json;
|
||||
}
|
||||
|
||||
@:get('/firstnames')
|
||||
@:produces('text/plain')
|
||||
public function listfirstnames(){
|
||||
var json:String = Utils.getTXT(path);
|
||||
return json;
|
||||
}
|
||||
|
||||
@:get('/lastnames')
|
||||
@:produces('text/plain')
|
||||
public function listlastnames(){
|
||||
var json:String = Utils.getTXT(path2);
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
60
api/src/controller/User.hx
Normal file
60
api/src/controller/User.hx
Normal file
@ -0,0 +1,60 @@
|
||||
package controller;
|
||||
|
||||
import haxe.Json;
|
||||
import Utils;
|
||||
import db.Db;
|
||||
import model.MUser;
|
||||
|
||||
|
||||
class User{
|
||||
public function new() {}
|
||||
public static var driver = new tink.sql.drivers.Sqlite();
|
||||
@await public static var db = new Db('db.sqlite', driver);
|
||||
|
||||
|
||||
@:get('/')
|
||||
@:produces('text/plain')
|
||||
public function id(){
|
||||
var json:String = "test";
|
||||
return json;
|
||||
}
|
||||
|
||||
@:get('/registerDummyUser')
|
||||
@:produces('text/plain')
|
||||
public function registerdummyuser(){
|
||||
|
||||
//@await var db = new Db('daba2', driver);
|
||||
db.MUser.create().next(function(){
|
||||
db.MUser.insertOne({
|
||||
id: cast null,
|
||||
name: 'Alice',
|
||||
email: 'alice@example.com',
|
||||
password: 'jew'
|
||||
}).next(function(){
|
||||
db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) {
|
||||
trace(row.name);
|
||||
// return "$row";
|
||||
})
|
||||
});
|
||||
});
|
||||
return "success";
|
||||
// @await var three = ;
|
||||
// trace(@await one);
|
||||
// trace(@await two);
|
||||
// trace(three);
|
||||
//return '$yeet';
|
||||
// var json:String = Json.stringify(three);
|
||||
// @await return json;
|
||||
}
|
||||
|
||||
@:get('/fetchalice')
|
||||
@:produces('application/json')
|
||||
public function fetchalice(){
|
||||
var driver = new tink.sql.drivers.Sqlite();
|
||||
|
||||
return db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) {
|
||||
return row;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -10,7 +10,7 @@ import model.MUser;
|
||||
|
||||
|
||||
typedef Db = tink.sql.Database<Def>;
|
||||
@:tables(User)
|
||||
@:tables(MUser)
|
||||
interface Def extends tink.sql.DatabaseDefinition {
|
||||
//@:procedure var func:Int->{x:Int, point:tink.s2d.Point};
|
||||
//@:table('user') var UserAlias:User;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package db;
|
||||
// package db;
|
||||
|
||||
import tink.sql.Types;
|
||||
// import tink.sql.Types;
|
||||
|
||||
|
||||
typedef User = {
|
||||
@:autoIncrement @:primary public var id(default, null):Id<User>;
|
||||
var name:VarChar<255>;
|
||||
@:unique var email:VarChar<255>;
|
||||
var password:VarChar<255>;
|
||||
}
|
||||
// typedef User = {
|
||||
// @:autoIncrement @:primary public var id(default, null):Id<User>;
|
||||
// var name:VarChar<255>;
|
||||
// @:unique var email:VarChar<255>;
|
||||
// var password:VarChar<255>;
|
||||
// }
|
||||
@ -5,4 +5,5 @@ import tink.sql.Types;
|
||||
typedef MService = {
|
||||
@:autoIncrement @:primary public var id(default, null):Id<MService>;
|
||||
public var name:VarChar<50>;
|
||||
public var description:VarChar<1024>;
|
||||
}
|
||||
10
api/src/model/MSubscription.hx
Normal file
10
api/src/model/MSubscription.hx
Normal file
@ -0,0 +1,10 @@
|
||||
package model;
|
||||
|
||||
import tink.sql.Types;
|
||||
|
||||
|
||||
typedef MSubscription = {
|
||||
@:autoIncrement @:primary public var id(default, null):Id<MSubscription>;
|
||||
public var subscriber:Id<MUser>;
|
||||
public var service:Id<MService>;
|
||||
}
|
||||
@ -8,5 +8,4 @@ typedef MUser = {
|
||||
public var name:VarChar<50>;
|
||||
public var email:VarChar<50>;
|
||||
public var password:VarChar<50>;
|
||||
public var services:Id<MService>;
|
||||
}
|
||||
@ -1,18 +1,17 @@
|
||||
package model.sites.drivebycool;
|
||||
|
||||
import tink.sql.Types;
|
||||
|
||||
|
||||
typedef MSubscription = {
|
||||
@:autoIncrement @:primary public var id(default, null):Id<MSubscription>;
|
||||
public var subscriber:VarChar<50>;
|
||||
public var project:Id<MUser>;
|
||||
public var subscribers:Id<Subscription>;
|
||||
}
|
||||
import model.MSubscription;
|
||||
|
||||
typedef MProject = {
|
||||
@:autoIncrement @:primary public var id(default, null):Id<MProject>;
|
||||
public var name:VarChar<50>;
|
||||
public var owner:Id<MUser>;
|
||||
public var subscribers:Id<Subscription>;
|
||||
public var description:VarChar<1024>;
|
||||
}
|
||||
|
||||
typedef MMembership = {
|
||||
@:autoIncrement @:primary public var id(default, null):Id<MMembership>;
|
||||
public var project:Id<MProject>;
|
||||
public var user:Id<MUser>;
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
package model.services;
|
||||
|
||||
import tink.sql.Types;
|
||||
|
||||
typedef MMembership = {
|
||||
@:autoIncrement @:primary public var id(default, null):Id<MMembership>;
|
||||
public var project:Id<MProject>;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user