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

65 lines
1.8 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
# Teacher vote model
2022-01-23 08:12:57 +00:00
class TeacherVote < 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::TeacherVote, Int32
2022-01-23 08:12:57 +00:00
@[GraphQL::Field]
2022-02-09 13:35:35 +00:00
# Voted teacher
2022-01-23 08:12:57 +00:00
def teacher : Teacher
Teacher.new(@model.teacher.not_nil!)
2022-01-23 08:12:57 +00:00
end
@[GraphQL::Field]
2022-02-09 13:35:35 +00:00
# Teacher vote's priority
2022-01-23 08:12:57 +00:00
def priority : Int32
@model.priority
2022-01-23 08:12:57 +00:00
end
2022-07-28 12:05:10 +00:00
@[GraphQL::Field]
# Student's vote
def vote : Vote
Vote.new(@model.vote)
end
2022-01-23 08:12:57 +00:00
end
@[GraphQL::InputObject]
2022-02-09 13:35:35 +00:00
# Teacher vote creation input
2022-01-23 08:12:57 +00:00
class TeacherVoteCreateInput < GraphQL::BaseInputObject
2022-02-09 13:35:35 +00:00
# Teacher vote's vote ID
2022-01-23 08:12:57 +00:00
getter vote_id
2022-02-09 13:35:35 +00:00
# Teacher vote's teacher ID
2022-01-23 08:12:57 +00:00
getter teacher_id
2022-02-09 13:35:35 +00:00
# Teacher vote's priority
2022-01-23 08:12:57 +00:00
getter priority
@[GraphQL::Field]
def initialize(@vote_id : Int32, @teacher_id : Int32, @priority : Int32)
end
end
end
end
end