Merge pull request 'Update API DB oriented models' init functions' (#92) from better-db-inits into main
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: mentorenwahl/mentorenwahl#92
This commit is contained in:
commit
4bf65a4d87
|
@ -36,8 +36,8 @@ module Backend
|
||||||
def initialize(@model : {{ type }})
|
def initialize(@model : {{ type }})
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(id : Int32)
|
def self.from_id(id : Int32) : self
|
||||||
@model = {{ type }}.find!(id)
|
new({{ type }}.find!(id))
|
||||||
end
|
end
|
||||||
|
|
||||||
{% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %}
|
{% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %}
|
||||||
|
|
|
@ -38,7 +38,7 @@ module Backend
|
||||||
def user(context : Context, id : Int32) : User
|
def user(context : Context, id : Int32) : User
|
||||||
context.admin!
|
context.admin!
|
||||||
|
|
||||||
User.new(id)
|
User.from_id(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
@[GraphQL::Field]
|
@[GraphQL::Field]
|
||||||
|
|
|
@ -76,7 +76,7 @@ module Backend
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates user data from DB entry index
|
# Creates user data from DB entry index
|
||||||
def self.from_index(id : Int32) : self
|
def self.from_id(id : Int32) : self
|
||||||
from_db(Db::User.find!(id))
|
from_db(Db::User.find!(id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue