44 lines
827 B
Crystal
44 lines
827 B
Crystal
require "graphql"
|
|
|
|
module MW
|
|
module Schema
|
|
@[GraphQL::Object]
|
|
class Teacher < GraphQL::BaseObject
|
|
include Helpers::DbObject
|
|
|
|
db_object Db::Teacher
|
|
|
|
@[GraphQL::Field]
|
|
def user : User
|
|
User.new(find!.user)
|
|
end
|
|
|
|
@[GraphQL::Field]
|
|
def max_students(context : Context) : Int32
|
|
context.admin!
|
|
|
|
find!.max_students
|
|
end
|
|
end
|
|
|
|
@[GraphQL::InputObject]
|
|
class TeacherInput < GraphQL::BaseInputObject
|
|
getter max_students
|
|
|
|
@[GraphQL::Field]
|
|
def initialize(@max_students : Int32)
|
|
end
|
|
end
|
|
|
|
@[GraphQL::InputObject]
|
|
class TeacherCreateInput < TeacherInput
|
|
getter user_id
|
|
|
|
@[GraphQL::Field]
|
|
def initialize(@user_id : Int32, max_students : Int32)
|
|
super(max_students)
|
|
end
|
|
end
|
|
end
|
|
end
|