Add config query
This commit is contained in:
parent
3938486cd2
commit
3c5547f0d4
|
@ -22,7 +22,7 @@ POSTGRES_USER="mw"
|
|||
POSTGRES_PASSWORD=
|
||||
|
||||
# Backend
|
||||
BACKEND_MIN_TEACHER_SELECTION_COUNT=
|
||||
BACKEND_MINIMUM_TEACHER_SELECTION_COUNT=
|
||||
BACKEND_URL=URL
|
||||
# Backend - API
|
||||
BACKEND_API_GRAPHQL_PLAYGROUND=false
|
||||
|
|
|
@ -77,7 +77,7 @@ services:
|
|||
- redis
|
||||
environment:
|
||||
BACKEND_URL: ${URL}
|
||||
BACKEND_MIN_TEACHER_SELECTION_COUNT: ${BACKEND_MIN_TEACHER_SELECTION_COUNT}
|
||||
BACKEND_MINIMUM_TEACHER_SELECTION_COUNT: ${BACKEND_MINIMUM_TEACHER_SELECTION_COUNT}
|
||||
BACKEND_API_GRAPHQL_PLAYGROUND: ${BACKEND_API_GRAPHQL_PLAYGROUND}
|
||||
BACKEND_API_JWT_SECRET: ${BACKEND_API_JWT_SECRET}
|
||||
BACKEND_API_JWT_EXPIRATION: ${BACKEND_API_JWT_EXPIRATION}
|
||||
|
|
|
@ -30,7 +30,7 @@ shards:
|
|||
|
||||
graphql:
|
||||
git: https://github.com/graphql-crystal/graphql.git
|
||||
version: 0.3.2+git.commit.8c6dc73c0c898ca511d9d12efefca7c837c25946
|
||||
version: 0.3.2+git.commit.75325d512bfa2f57a14b306aa9f7465fc0998fa5
|
||||
|
||||
habitat:
|
||||
git: https://github.com/luckyframework/habitat.git
|
||||
|
|
|
@ -37,7 +37,7 @@ dependencies:
|
|||
github: will/crystal-pg
|
||||
graphql:
|
||||
github: graphql-crystal/graphql
|
||||
branch: master
|
||||
branch: main
|
||||
jwt:
|
||||
github: crystal-community/jwt
|
||||
commander:
|
||||
|
|
30
docker/backend/src/backend/api/schema/config.cr
Normal file
30
docker/backend/src/backend/api/schema/config.cr
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
|
||||
# Copyright (C) 2022 Dominic Grimm
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
module Backend
|
||||
module Api
|
||||
module Schema
|
||||
@[GraphQL::Object]
|
||||
# Public configuration of the API for frontend pre-validation
|
||||
class Config < GraphQL::BaseObject
|
||||
@[GraphQL::Field]
|
||||
def minimum_teacher_selection_count : Int32
|
||||
Backend.config.minimum_teacher_selection_count
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -143,7 +143,7 @@ module Backend
|
|||
def create_vote(context : Context, input : VoteCreateInput) : Vote
|
||||
context.student!
|
||||
|
||||
raise "Not enough teachers" if input.teacher_ids.size < Backend.config.min_teacher_selection_count
|
||||
raise "Not enough teachers" if input.teacher_ids.size < Backend.config.minimum_teacher_selection_count
|
||||
teacher_role_count = Db::User.where(role: Db::UserRole::Teacher.to_s).count.run.as(Int64)
|
||||
raise "Teachers not registered" if teacher_role_count != Db::Teacher.count ||
|
||||
teacher_role_count.zero?
|
||||
|
|
|
@ -25,6 +25,12 @@ module Backend
|
|||
true
|
||||
end
|
||||
|
||||
@[GraphQL::Field]
|
||||
# Public configuration of the API for frontend pre-validation
|
||||
def config : Config
|
||||
Config.new
|
||||
end
|
||||
|
||||
@[GraphQL::Field]
|
||||
# Current authenticated user
|
||||
def me(context : Context) : User
|
||||
|
|
|
@ -59,7 +59,7 @@ module Backend
|
|||
getter url : String
|
||||
|
||||
# Minimum teacher selection count
|
||||
getter min_teacher_selection_count : Int32
|
||||
getter minimum_teacher_selection_count : Int32
|
||||
|
||||
@[EnvConfig::Setting(key: "api")]
|
||||
# Configuration for `Api`
|
||||
|
|
Loading…
Reference in a new issue