Compare commits

..

No commits in common. "edc1ea081f74802d9d1428ebe4145724b62ffb9d" and "5e0768263ff5aa6bde4c27f4828f7589f5ee7a78" have entirely different histories.

15 changed files with 79 additions and 96045 deletions

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
api2/
**/build/
out.js
api/node_modules/
out.js

2081
api/package-lock.json generated

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,16 +2,22 @@ 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() {
@ -34,34 +40,29 @@ 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.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();
@: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';
}
@:sub('/projects')
@:produces('application/json')
@ -76,9 +77,30 @@ class Root {
return strout;
}
@:sub('/idgen')
@:produces('application/json')
public function idGen()
return new IDGen();
}
class Projects {
public function new() {}
public var path:String = "./res/json/projects.json";
@:get('/')
@: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;
}
}

View File

@ -21,28 +21,4 @@ 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;
}
}

View File

@ -1,67 +0,0 @@
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;
}
}

View File

@ -1,60 +0,0 @@
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;
});
}
}

View File

@ -10,7 +10,7 @@ import model.MUser;
typedef Db = tink.sql.Database<Def>;
@:tables(MUser)
@:tables(User)
interface Def extends tink.sql.DatabaseDefinition {
//@:procedure var func:Int->{x:Int, point:tink.s2d.Point};
//@:table('user') var UserAlias:User;

View File

@ -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>;
}

View File

@ -5,5 +5,4 @@ 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>;
}

View File

@ -1,10 +0,0 @@
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>;
}

View File

@ -8,4 +8,5 @@ typedef MUser = {
public var name:VarChar<50>;
public var email:VarChar<50>;
public var password:VarChar<50>;
public var services:Id<MService>;
}

View File

@ -1,17 +1,18 @@
package model.sites.drivebycool;
import tink.sql.Types;
import model.MSubscription;
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>;
}
typedef MProject = {
@:autoIncrement @:primary public var id(default, null):Id<MProject>;
public var name:VarChar<50>;
public var owner:Id<MUser>;
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>;
public var subscribers:Id<Subscription>;
}

View File

@ -1,7 +1,5 @@
package model.services;
import tink.sql.Types;
typedef MMembership = {
@:autoIncrement @:primary public var id(default, null):Id<MMembership>;
public var project:Id<MProject>;