Environment variable option for minimum teacher vote selection count #95
|
@ -22,6 +22,7 @@ POSTGRES_USER="mw"
|
||||||
POSTGRES_PASSWORD=
|
POSTGRES_PASSWORD=
|
||||||
|
|
||||||
# Backend
|
# Backend
|
||||||
|
BACKEND_MINIMUM_TEACHER_SELECTION_COUNT=
|
||||||
BACKEND_URL=URL
|
BACKEND_URL=URL
|
||||||
# Backend - API
|
# Backend - API
|
||||||
BACKEND_API_GRAPHQL_PLAYGROUND=false
|
BACKEND_API_GRAPHQL_PLAYGROUND=false
|
||||||
|
|
|
@ -77,6 +77,7 @@ services:
|
||||||
- redis
|
- redis
|
||||||
environment:
|
environment:
|
||||||
BACKEND_URL: ${URL}
|
BACKEND_URL: ${URL}
|
||||||
|
BACKEND_MINIMUM_TEACHER_SELECTION_COUNT: ${BACKEND_MINIMUM_TEACHER_SELECTION_COUNT}
|
||||||
BACKEND_API_GRAPHQL_PLAYGROUND: ${BACKEND_API_GRAPHQL_PLAYGROUND}
|
BACKEND_API_GRAPHQL_PLAYGROUND: ${BACKEND_API_GRAPHQL_PLAYGROUND}
|
||||||
BACKEND_API_JWT_SECRET: ${BACKEND_API_JWT_SECRET}
|
BACKEND_API_JWT_SECRET: ${BACKEND_API_JWT_SECRET}
|
||||||
BACKEND_API_JWT_EXPIRATION: ${BACKEND_API_JWT_EXPIRATION}
|
BACKEND_API_JWT_EXPIRATION: ${BACKEND_API_JWT_EXPIRATION}
|
||||||
|
|
|
@ -30,7 +30,7 @@ shards:
|
||||||
|
|
||||||
graphql:
|
graphql:
|
||||||
git: https://github.com/graphql-crystal/graphql.git
|
git: https://github.com/graphql-crystal/graphql.git
|
||||||
version: 0.3.2+git.commit.8c6dc73c0c898ca511d9d12efefca7c837c25946
|
version: 0.3.2+git.commit.75325d512bfa2f57a14b306aa9f7465fc0998fa5
|
||||||
|
|
||||||
habitat:
|
habitat:
|
||||||
git: https://github.com/luckyframework/habitat.git
|
git: https://github.com/luckyframework/habitat.git
|
||||||
|
|
|
@ -37,7 +37,7 @@ dependencies:
|
||||||
github: will/crystal-pg
|
github: will/crystal-pg
|
||||||
graphql:
|
graphql:
|
||||||
github: graphql-crystal/graphql
|
github: graphql-crystal/graphql
|
||||||
branch: master
|
branch: main
|
||||||
jwt:
|
jwt:
|
||||||
github: crystal-community/jwt
|
github: crystal-community/jwt
|
||||||
commander:
|
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
|
def create_vote(context : Context, input : VoteCreateInput) : Vote
|
||||||
context.student!
|
context.student!
|
||||||
|
|
||||||
raise "Not enough teachers" if input.teacher_ids.empty?
|
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)
|
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 ||
|
raise "Teachers not registered" if teacher_role_count != Db::Teacher.count ||
|
||||||
teacher_role_count.zero?
|
teacher_role_count.zero?
|
||||||
|
|
|
@ -25,6 +25,12 @@ module Backend
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@[GraphQL::Field]
|
||||||
|
# Public configuration of the API for frontend pre-validation
|
||||||
|
def config : Config
|
||||||
|
Config.new
|
||||||
|
end
|
||||||
|
|
||||||
@[GraphQL::Field]
|
@[GraphQL::Field]
|
||||||
# Current authenticated user
|
# Current authenticated user
|
||||||
def me(context : Context) : User
|
def me(context : Context) : User
|
||||||
|
|
|
@ -58,6 +58,9 @@ module Backend
|
||||||
# Base URL of application
|
# Base URL of application
|
||||||
getter url : String
|
getter url : String
|
||||||
|
|
||||||
|
# Minimum teacher selection count
|
||||||
|
getter minimum_teacher_selection_count : Int32
|
||||||
|
|
||||||
@[EnvConfig::Setting(key: "api")]
|
@[EnvConfig::Setting(key: "api")]
|
||||||
# Configuration for `Api`
|
# Configuration for `Api`
|
||||||
getter api : ApiConfig
|
getter api : ApiConfig
|
||||||
|
|
Loading…
Reference in a new issue