From dc03d9202dae2a44af2410d68b2e35d500a8a5ac Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 1 Apr 2016 21:47:36 -0400 Subject: add get_users --- src/guff/models/user.cr | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/guff/models') diff --git a/src/guff/models/user.cr b/src/guff/models/user.cr index a76fc61..bdbb0de 100644 --- a/src/guff/models/user.cr +++ b/src/guff/models/user.cr @@ -2,6 +2,23 @@ require "crypto/bcrypt" class Guff::UserModel < Guff::Model SQL = TemplateCache.new({ + get_users: " + SELECT a.user_id, + a.created_at, + a.is_active, + a.user_name, + b.role_name, + c.email + + FROM users a + JOIN roles b + ON (b.role_id = a.role_id) + JOIN user_logins c + ON (c.user_id = a.user_id) + + ORDER BY LOWER(a.user_name) + ", + add_user: " INSERT INTO users(user_name) VALUES (:user_name) ", @@ -39,10 +56,17 @@ class Guff::UserModel < Guff::Model end def get_users - r = [] of Hash(String, String) - - all(:get_users) do |row| - r << row + r = [] of Hash(String, Int64 | String | Bool) + + all(:get_users, nil, nil) do |row| + r << { + "user_id": row["user_id"] as Int64, + "created_at": row["created_at"] as String, + "is_active": ((row["is_active"] as Int64) == 1), + "user_name": row["user_name"] as String, + "role_name": row["role_name"] as String, + "email": row["email"] as String, + } end r -- cgit v1.2.3