Merge pull request 'Environment variable option for minimum teacher vote selection count' (#95) from minimum-teacher-selection-amount into main
continuous-integration/drone/push Build is passing Details

Reviewed-on: mentorenwahl/mentorenwahl#95
This commit is contained in:
Dominic Grimm 2022-03-13 11:03:19 +00:00
commit 21c2856b51
8 changed files with 44 additions and 3 deletions

View File

@ -22,6 +22,7 @@ POSTGRES_USER="mw"
POSTGRES_PASSWORD=
# Backend
BACKEND_MINIMUM_TEACHER_SELECTION_COUNT=
BACKEND_URL=URL
# Backend - API
BACKEND_API_GRAPHQL_PLAYGROUND=false

View File

@ -77,6 +77,7 @@ services:
- redis
environment:
BACKEND_URL: ${URL}
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}

View File

@ -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

View File

@ -37,7 +37,7 @@ dependencies:
github: will/crystal-pg
graphql:
github: graphql-crystal/graphql
branch: master
branch: main
jwt:
github: crystal-community/jwt
commander:

View 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

View File

@ -143,7 +143,7 @@ module Backend
def create_vote(context : Context, input : VoteCreateInput) : Vote
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)
raise "Teachers not registered" if teacher_role_count != Db::Teacher.count ||
teacher_role_count.zero?

View File

@ -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

View File

@ -58,6 +58,9 @@ module Backend
# Base URL of application
getter url : String
# Minimum teacher selection count
getter minimum_teacher_selection_count : Int32
@[EnvConfig::Setting(key: "api")]
# Configuration for `Api`
getter api : ApiConfig