Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 032 well arranged tables #33

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
language: d

d:
- dmd-2.080.0
- dmd-2.078.1
- dmd-2.077.1
- ldc-1.7.0
- ldc-1.9.0
os:
- linux
env:
Expand Down
17 changes: 10 additions & 7 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
],
"dependencies": {
"dauth": "~>0.6.3",
"mysql-native": "~>1.1.4",
"vibe-d": "~>0.8.2",
"vibe-d:tls": "~>0.8.2",
"poodinis": "~>8.0.1"
"mysql-native": "~>2.2.2",
"vibe-d": "~>0.8.3",
"vibe-d:tls": "~>0.8.3",
"diet-ng": "~>1.4.5",
"poodinis": "~>8.0.2"
},
"subConfigurations": {
"vibe-d:tls": "openssl-1.1"
Expand All @@ -19,6 +20,9 @@
"license": "MIT",
"targetType": "executable",
"targetPath": "generated",
"versions": [
"DietUseCache"
],
"configurations": [
{
"name": "executable"
Expand All @@ -31,9 +35,8 @@
"excludedSourceFiles": ["source/fsicalmanagement/app.d"],
"sourcePaths": ["test"],
"dependencies": {
"unit-threaded": "~>0.7.38"
},
"versions": ["unitUnthreaded"]
"unit-threaded": "~>0.7.45"
}
}
]
}
17 changes: 9 additions & 8 deletions dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
"botan": "1.12.9",
"botan-math": "1.0.3",
"dauth": "0.6.3",
"diet-ng": "1.4.4",
"eventcore": "0.8.27",
"diet-ng": "1.4.5",
"eventcore": "0.8.34",
"libasync": "0.8.3",
"libevent": "2.0.2+2.0.16",
"memutils": "0.4.10",
"mysql-native": "1.1.4",
"mysql-native": "2.2.2",
"openssl": "1.1.6+1.0.1g",
"poodinis": "8.0.1",
"taggedalgebraic": "0.10.9",
"unit-threaded": "0.7.38",
"vibe-core": "1.3.0",
"vibe-d": "0.8.2"
"poodinis": "8.0.2",
"stdx-allocator": "2.77.1",
"taggedalgebraic": "0.10.11",
"unit-threaded": "0.7.45",
"vibe-core": "1.4.0",
"vibe-d": "0.8.3"
}
}
21 changes: 12 additions & 9 deletions source/fsicalmanagement/authenticator.d
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public:
InputRange!AuthInfo getAllUsers() @safe
{
import std.algorithm : map;
import std.range : inputRangeObject;
import std.range.interfaces : inputRangeObject;

return users.find().map!(deserializeBson!AuthInfo).inputRangeObject;
}
Expand All @@ -87,7 +87,7 @@ enum Privilege
class MySQLAuthenticator : Authenticator
{
private:
import mysql : MySQLPool, Row, prepare;
import mysql : MySQLPool, Row, prepare, exec, query;

@Autowire MySQLPool pool;
@Autowire PasswordHasher passwordHasher;
Expand All @@ -105,7 +105,7 @@ public:
"SELECT id, username, passwordHash, privilege FROM "
~ usersTableName ~ " WHERE username = ?");
prepared.setArg(0, username);
auto result = prepared.query();
auto result = cn.query(prepared);
if (!result.empty)
{
auto authInfo = toAuthInfo(result.front);
Expand All @@ -123,21 +123,24 @@ public:
scope (exit)
cn.close;
auto prepared = cn.prepare(
"INSERT INTO " ~ usersTableName ~ " (username, passwordHash, privilege) VALUES(?, ?, ?)");
"INSERT INTO " ~ usersTableName
~ " (username, passwordHash, privilege) VALUES(?, ?, ?)");
prepared.setArgs(authInfo.username, authInfo.passwordHash, authInfo.privilege.to!uint);
prepared.exec();
cn.exec(prepared);
}

InputRange!AuthInfo getAllUsers()
{
import std.algorithm : map;
import std.range : inputRangeObject;
import std.array : array;
import std.range.interfaces : inputRangeObject;

auto cn = pool.lockConnection();
scope (exit)
cn.close;
auto prepared = cn.prepare("SELECT id, username, passwordHash, privilege FROM " ~ usersTableName ~ "");
return prepared.querySet.map!(r => toAuthInfo(r)).inputRangeObject;
auto prepared = cn.prepare(
"SELECT id, username, passwordHash, privilege FROM " ~ usersTableName);
return cn.query(prepared).array.map!(r => toAuthInfo(r)).inputRangeObject;
}

void removeUser(string id)
Expand All @@ -147,7 +150,7 @@ public:
cn.close;
auto prepared = cn.prepare("DELETE FROM " ~ usersTableName ~ " WHERE id = ?");
prepared.setArg(0, id.to!uint);
prepared.exec();
cn.exec(prepared);
}

private:
Expand Down
53 changes: 29 additions & 24 deletions source/fsicalmanagement/event.d
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private:
class MySQLEventStore : EventStore
{
private:
import mysql : MySQLPool, prepare, Row;
import mysql : MySQLPool, prepare, Row, query, exec;

@Value("mysql.table.events") string eventsTableName;

Expand All @@ -81,32 +81,34 @@ public:
scope (exit)
cn.close;
auto prepared = cn.prepare(
"SELECT id begin end name description type shout FROM " ~ eventsTableName ~ " WHERE id = ?");
"SELECT id begin end name description type shout FROM "
~ eventsTableName ~ " WHERE id = ?");
prepared.setArg(0, id.to!uint);
return toEvent(prepared.query.front);
return cn.query(prepared).front.toEvent;
}

InputRange!Event getAllEvents()
{
import std.array : array;

auto cn = pool.lockConnection();
scope (exit)
cn.close;
auto prepared = cn.prepare(
"SELECT id, begin, end, name, description, type, shout FROM " ~ eventsTableName ~ "");
return prepared.querySet.map!(r => toEvent(r)).inputRangeObject;
"SELECT id, begin, end, name, description, type, shout FROM " ~ eventsTableName);
return cn.query(prepared).array.map!(r => toEvent(r)).inputRangeObject;
}

void addEvent(Event event)
{
auto cn = pool.lockConnection();
scope (exit)
cn.close;
auto prepared = cn.prepare(
"INSERT INTO " ~ eventsTableName ~ " (begin, end, name, description, type, shout)"
~ " VALUES(?, ?, ?, ?, ?, ?)");
auto prepared = cn.prepare("INSERT INTO " ~ eventsTableName
~ " (begin, end, name, description, type, shout)" ~ " VALUES(?, ?, ?, ?, ?, ?)");
prepared.setArgs(event.begin, event.end, event.name, event.description,
event.type.to!uint, event.shout);
prepared.exec();
cn.exec(prepared);
}

/* InputRange!Event getEventsBeginningBetween(Date begin, Date end) @safe
Expand All @@ -123,25 +125,27 @@ public:
cn.close;
auto prepared = cn.prepare("DELETE FROM " ~ eventsTableName ~ " WHERE id = ?");
prepared.setArg(0, id.to!uint);
prepared.exec();
cn.exec(prepared);
}

private:
@Autowire MySQLPool pool;
}

Event toEvent(Row r)
{
Event event;
event.id = r[0].get!uint.to!string;
event.begin = r[1].get!Date;
if (r[2].hasValue)
event.end = r[2].get!Date;
event.name = r[3].get!string;
event.description = r[4].get!string;
event.type = r[5].get!uint.to!EventType;
event.shout = r[6].get!byte.to!bool;
return event;
}
import mysql : Row;

Event toEvent(Row r)
{
Event event;
event.id = r[0].get!uint.to!string;
event.begin = r[1].get!Date;
if (r[2].type != typeid(typeof(null)))
event.end = r[2].get!Date;
event.name = r[3].get!string;
event.description = r[4].get!string;
event.type = r[5].get!uint.to!EventType;
event.shout = r[6].get!byte.to!bool;
return event;
}

enum EventType
Expand All @@ -155,7 +159,8 @@ enum EventType

struct Event
{
import std.typecons: Nullable;
import std.typecons : Nullable;

@serializationName("_id") string id;
@serializationName("date") Date begin;
@serializationName("end_date") Nullable!Date end;
Expand Down
1 change: 1 addition & 0 deletions source/fsicalmanagement/fsicalmanagement.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import vibe.web.web;
@requiresAuth class FsicalManagement
{
import vibe.http.server : HTTPServerRequest;

@noRoute AuthInfo authenticate(scope HTTPServerRequest, scope HTTPServerResponse) @safe
{
if (authInfo.value.isNone)
Expand Down
33 changes: 14 additions & 19 deletions views/showevents.dt
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
extends layout.dt
block content
h1 Events
- foreach (event; events)
table
table
tr
th begin
th end
th _id
th name
th desc
th etype
th shout
- foreach (event; events)
tr
td begin
td #{event.begin}
tr
td end
td #{event.end}
tr
td _id
td #{event.id}
tr
td name
td #{event.name}
tr
td desc
td.pre #{event.description}
tr
td etype
td #{event.type}
tr
td shout
td #{event.shout}
form(action="/removeevent", method="post")
input#id(value="#{event.id}", name="id", type="hidden")
input#submitButton(type="submit", value="Entfernen")
hr
td
form(action="/removeevent", method="post")
input#id(value="#{event.id}", name="id", type="hidden")
input#submitButton(type="submit", value="Entfernen")
21 changes: 10 additions & 11 deletions views/showusers.dt
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
extends layout.dt
block content
h1 Users
- foreach (user; users)
table
table
tr
th id
th username
th privilege
- foreach (user; users)
tr
td id
td #{user.id}
tr
td username
td #{user.username}
tr
td privilege
td #{user.privilege}
form(action="/removeuser", method="post")
input#id(value="#{user.id}", name="id", type="hidden")
input#submitButton(type="submit", value="Entfernen")
hr
td
form(action="/removeuser", method="post")
input#id(value="#{user.id}", name="id", type="hidden")
input#submitButton(type="submit", value="Entfernen")
- if (_error)
p.error= _error