Refactor db models

master
E. Almqvist 3 years ago
parent 2e3c992e23
commit 98e080bc2c
  1. 2
      src/app.rb
  2. 36
      src/db_models.rb

@ -119,7 +119,7 @@ post "/login" do
end end
end end
get "/logout" do get "/logout" do # TODO: make me post
session.clear session.clear
redirect "/" redirect "/"
end end

@ -2,15 +2,15 @@
class User < EntityModel class User < EntityModel
attr_reader :email, :name, :bio_text, :balance, :avatar_url, :pw_hash, :reputation attr_reader :email, :name, :bio_text, :balance, :avatar_url, :pw_hash, :reputation
def initialize(user_info) def initialize(data)
super user_info super data
@email = user_info["email"] @email = data["email"]
@name = user_info["name"] @name = data["name"]
@bio_text = user_info["bio_text"] @bio_text = data["bio_text"]
@balance = user_info["balance"] @balance = data["balance"]
@avatar_url = user_info["avatar_url"] @avatar_url = data["avatar_url"]
@reputation = user_info["reputation"] @reputation = data["reputation"]
@pw_hash = user_info["pw_hash"] @pw_hash = data["pw_hash"]
end end
def avatar def avatar
@ -130,11 +130,11 @@ end
class Role < EntityModel class Role < EntityModel
attr_reader :name, :color, :flags attr_reader :name, :color, :flags
def initialize(role_info) def initialize(data)
super role_info super data
@name = role_info["name"] @name = data["name"]
@color = role_info["color"] @color = data["color"]
@flags = role_info["flags"] @flags = data["flags"]
end end
def self.find_by_id(id) def self.find_by_id(id)
@ -170,3 +170,11 @@ class User_Role_relation < EntityModel
end end
end end
end end
class Auction < EntityModel
def initialize(data)
super data
@title = data["title"]
end
end

Loading…
Cancel
Save