mentorenwahl/backend/src/backend/api/schema/student.cr

61 lines
1.7 KiB
Crystal
Raw Normal View History

2022-02-10 07:43:47 +00:00
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
# Copyright (C) 2022 Dominic Grimm
2022-03-07 13:06:02 +00:00
#
2022-02-10 07:43:47 +00:00
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
2022-03-07 13:06:02 +00:00
#
2022-02-10 07:43:47 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
2022-03-07 13:06:02 +00:00
#
2022-02-10 07:43:47 +00:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2022-01-23 08:12:57 +00:00
module Backend
module Api
2022-01-23 08:12:57 +00:00
module Schema
@[GraphQL::Object]
2022-02-09 13:35:35 +00:00
# Student model
2022-01-23 08:12:57 +00:00
class Student < GraphQL::BaseObject
2022-03-07 17:10:55 +00:00
include Helpers
2022-01-23 08:12:57 +00:00
2022-11-21 18:48:53 +00:00
db_object Db::Student, Int32
2022-01-23 08:12:57 +00:00
@[GraphQL::Field]
2022-02-09 13:35:35 +00:00
# Student's user
2022-01-23 08:12:57 +00:00
def user : User
User.new(@model.user)
2022-01-23 08:12:57 +00:00
end
@[GraphQL::Field]
2022-02-09 13:35:35 +00:00
# Student's vote
2022-01-23 08:12:57 +00:00
def vote : Vote?
@model.vote.try { |v| Vote.new(v) }
2022-01-23 08:12:57 +00:00
end
end
# @[GraphQL::InputObject]
# # Student base input
# class StudentInput < GraphQL::BaseInputObject
# @[GraphQL::Field]
# def initialize
# end
# end
2022-01-23 08:12:57 +00:00
@[GraphQL::InputObject]
2022-02-09 13:35:35 +00:00
# Student creation input
class StudentCreateInput < GraphQL::BaseInputObject
2022-02-09 13:35:35 +00:00
# Student's user ID
2022-01-23 08:12:57 +00:00
getter user_id
@[GraphQL::Field]
def initialize(@user_id : Int32)
2022-01-23 08:12:57 +00:00
end
end
end
end
end