From d399e26c7881f5ded4780c4e0550fe8062584e09 Mon Sep 17 00:00:00 2001 From: Daniel Heidemann Date: Sat, 21 Sep 2024 14:13:04 +0200 Subject: [PATCH] =?UTF-8?q?i=20am=20back=20babey=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - application submissions - missing: prompt for name and mail address --- frontend/app/layout.tsx | 2 + frontend/app/registration/page.tsx | 107 +- frontend/components/ui/sonner.tsx | 31 + frontend/lib/gql/generated/gql.ts | 9 +- frontend/lib/gql/generated/graphql.ts | 76 +- .../lib/gql/mutations/application.graphql | 5 + frontend/lib/gql/queries/forms.graphql | 1 + frontend/package-lock.json | 40 +- server/db/init.go | 2 + server/graph/generated.go | 1917 ++++++++++++++++- server/graph/model/models_gen.go | 22 + server/graph/schema.graphqls | 36 + server/graph/schema.resolvers.go | 173 +- server/models/answer.go | 2 +- server/models/application.go | 52 + server/models/user.go | 7 +- 16 files changed, 2340 insertions(+), 142 deletions(-) create mode 100644 frontend/components/ui/sonner.tsx create mode 100644 frontend/lib/gql/mutations/application.graphql create mode 100644 server/models/application.go diff --git a/frontend/app/layout.tsx b/frontend/app/layout.tsx index 8436098..b650ede 100644 --- a/frontend/app/layout.tsx +++ b/frontend/app/layout.tsx @@ -1,6 +1,7 @@ import type { Metadata } from "next"; import { Inter } from "next/font/google"; import "./globals.css"; +import {Toaster} from "@/components/ui/sonner"; const inter = Inter({ subsets: ["latin"] }); @@ -17,6 +18,7 @@ export default function RootLayout({ return ( {children} + ); } diff --git a/frontend/app/registration/page.tsx b/frontend/app/registration/page.tsx index 90c63d1..c8fedd2 100644 --- a/frontend/app/registration/page.tsx +++ b/frontend/app/registration/page.tsx @@ -2,6 +2,11 @@ import { useRouter } from "next/navigation"; import { + AddStudentApplicationForEventDocument, + AddStudentApplicationForEventMutation, + AddStudentApplicationForEventMutationVariables, + NewQuestionResponsePair, + NewUserToEventApplication, QuestionType, RegistrationFormDocument, RegistrationFormQuery, @@ -32,6 +37,7 @@ import { FormItem, FormMessage, } from "@/components/ui/form"; +import { Toaster, toast } from "sonner"; type Props = { searchParams: { @@ -66,11 +72,17 @@ const Home = ({ searchParams }: Props) => { const [index, setIndex] = useState(0); const [loading, setLoading] = useState(true); const router = useRouter(); + const [responses, setResponses] = useState([]); useEffect(() => { - const fetchData = async () => { - const eventID = searchParams.e; + if (responses.length > 0) { + onSubmit(); + } + }, [responses]); + const eventID = searchParams.e; + useEffect(() => { + const fetchData = async () => { const vars: RegistrationFormQueryVariables = { eventID: parseInt(eventID), }; @@ -92,7 +104,7 @@ const Home = ({ searchParams }: Props) => { }; fetchData(); - }, [searchParams.e, router]); + }, [router]); useEffect(() => { if (regForm) { @@ -101,14 +113,18 @@ const Home = ({ searchParams }: Props) => { }, [index, regForm]); const mcForm = useForm>>({ - resolver: zodResolver(MultipleChoiceFormSchema(regForm?.questions[index].required!)), + resolver: zodResolver( + MultipleChoiceFormSchema(regForm?.questions[index].required!) + ), defaultValues: { multipleChoice: [], }, }); const scForm = useForm>>({ - resolver: zodResolver(SingleChoiceFormSchema(regForm?.questions[index].required!)), + resolver: zodResolver( + SingleChoiceFormSchema(regForm?.questions[index].required!) + ), defaultValues: { singleChoice: undefined, }, @@ -118,36 +134,79 @@ const Home = ({ searchParams }: Props) => { router.push("/"); } - const FooterButtons = () => ( -
- - -
- ); - - function onSubmit() { + const onSubmit = async () => { if (regForm?.questions.length !== index + 1) { setIndex((prevIndex) => prevIndex + 1); + return; } - } + + await new Promise((resolve) => setTimeout(resolve, 250)); + + const application: NewUserToEventApplication = { + // TODO + userMail: "tutor1@example.de", + eventID: +eventID, + answers: responses, + }; + + const vars: AddStudentApplicationForEventMutationVariables = { + application: application, + }; + + try { + await client.request( + AddStudentApplicationForEventDocument, + vars + ); + toast("Anmeldung abgeschickt!"); + handleQuit(); + } catch (err) { + toast("Ein Fehler ist aufgetreten"); + console.error(err) + } + }; function onScaleSubmit() { - onSubmit(); + const res: NewQuestionResponsePair = { + questionID: regForm?.questions[index].ID || 0, + value: String(sliderValue), + }; + setResponses((prevResponses) => [...prevResponses, res]); + setSliderValue(0); } - function onMCSubmit(data: z.infer>) { - onSubmit(); + function onMCSubmit( + data: z.infer> + ) { + const newResponses = data.multipleChoice!.map((id) => ({ + questionID: regForm?.questions[index].ID || 0, + answerID: id, + })); + setResponses((prevResponses) => [...prevResponses, ...newResponses]); } - function onSCSubmit(data: z.infer>) { - onSubmit(); + function onSCSubmit( + data: z.infer> + ) { + const res: NewQuestionResponsePair = { + questionID: regForm?.questions[index].ID || 0, + answerID: data.singleChoice!, + }; + setResponses((prevResponses) => [...prevResponses, res]); } + const FooterButtons = () => ( +
+ + +
+ ); + if (loading) { return
Loading...
; } @@ -195,7 +254,7 @@ const Home = ({ searchParams }: Props) => { onCheckedChange={(checked) => { return checked ? field.onChange([ - ...field.value || [], + ...(field.value || []), answer.ID, ]) : field.onChange( diff --git a/frontend/components/ui/sonner.tsx b/frontend/components/ui/sonner.tsx new file mode 100644 index 0000000..452f4d9 --- /dev/null +++ b/frontend/components/ui/sonner.tsx @@ -0,0 +1,31 @@ +"use client" + +import { useTheme } from "next-themes" +import { Toaster as Sonner } from "sonner" + +type ToasterProps = React.ComponentProps + +const Toaster = ({ ...props }: ToasterProps) => { + const { theme = "system" } = useTheme() + + return ( + + ) +} + +export { Toaster } diff --git a/frontend/lib/gql/generated/gql.ts b/frontend/lib/gql/generated/gql.ts index 163e602..c2316b3 100644 --- a/frontend/lib/gql/generated/gql.ts +++ b/frontend/lib/gql/generated/gql.ts @@ -13,9 +13,10 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/ * Therefore it is highly recommended to use the babel or swc plugin for production. */ const documents = { + "mutation addStudentApplicationForEvent($application: NewUserToEventApplication!) {\n addStudentApplicationForEvent(application: $application) {\n fn\n }\n}": types.AddStudentApplicationForEventDocument, "mutation addTutor($firstName: String!, $lastName: String!, $email: String!, $eventsAvailable: [Int!]!) {\n addTutor(\n tutor: {fn: $firstName, sn: $lastName, mail: $email}\n availability: {userMail: $email, eventID: $eventsAvailable}\n ) {\n fn\n }\n}": types.AddTutorDocument, "query tutorFormEvents {\n events(needsTutors: true, onlyFuture: true) {\n ID\n title\n from\n to\n topic {\n name\n color\n }\n type {\n name\n color\n }\n }\n}": types.TutorFormEventsDocument, - "query registrationForm($eventID: Int!) {\n forms(id: [$eventID]) {\n title\n description\n questions {\n title\n type\n required\n answers {\n ID\n title\n points\n }\n }\n }\n}": types.RegistrationFormDocument, + "query registrationForm($eventID: Int!) {\n forms(id: [$eventID]) {\n title\n description\n questions {\n ID\n title\n type\n required\n answers {\n ID\n title\n points\n }\n }\n }\n}": types.RegistrationFormDocument, }; /** @@ -32,6 +33,10 @@ const documents = { */ export function graphql(source: string): unknown; +/** + * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. + */ +export function graphql(source: "mutation addStudentApplicationForEvent($application: NewUserToEventApplication!) {\n addStudentApplicationForEvent(application: $application) {\n fn\n }\n}"): (typeof documents)["mutation addStudentApplicationForEvent($application: NewUserToEventApplication!) {\n addStudentApplicationForEvent(application: $application) {\n fn\n }\n}"]; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ @@ -43,7 +48,7 @@ export function graphql(source: "query tutorFormEvents {\n events(needsTutors: /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function graphql(source: "query registrationForm($eventID: Int!) {\n forms(id: [$eventID]) {\n title\n description\n questions {\n title\n type\n required\n answers {\n ID\n title\n points\n }\n }\n }\n}"): (typeof documents)["query registrationForm($eventID: Int!) {\n forms(id: [$eventID]) {\n title\n description\n questions {\n title\n type\n required\n answers {\n ID\n title\n points\n }\n }\n }\n}"]; +export function graphql(source: "query registrationForm($eventID: Int!) {\n forms(id: [$eventID]) {\n title\n description\n questions {\n ID\n title\n type\n required\n answers {\n ID\n title\n points\n }\n }\n }\n}"): (typeof documents)["query registrationForm($eventID: Int!) {\n forms(id: [$eventID]) {\n title\n description\n questions {\n ID\n title\n type\n required\n answers {\n ID\n title\n points\n }\n }\n }\n}"]; export function graphql(source: string) { return (documents as any)[source] ?? {}; diff --git a/frontend/lib/gql/generated/graphql.ts b/frontend/lib/gql/generated/graphql.ts index d0cee9b..6f4a3b6 100644 --- a/frontend/lib/gql/generated/graphql.ts +++ b/frontend/lib/gql/generated/graphql.ts @@ -25,6 +25,22 @@ export type Answer = { title: Scalars['String']['output']; }; +export type AnswerValuePair = { + __typename?: 'AnswerValuePair'; + answer?: Maybe; + value?: Maybe; +}; + +export type Application = { + __typename?: 'Application'; + accepted?: Maybe; + event: Event; + form: Form; + responses?: Maybe>; + score: Scalars['Int']['output']; + student: User; +}; + export type Building = { __typename?: 'Building'; ID: Scalars['Int']['output']; @@ -96,6 +112,8 @@ export type Mutation = { addRoom: Room; addRoomAvailabilityForEvent: Room; addSetting: Setting; + addStudent: User; + addStudentApplicationForEvent: User; addStudentRegistrationForEvent: User; addTutor: User; addTutorAvailabilityForEvent: User; @@ -108,6 +126,7 @@ export type Mutation = { deleteRoom: Scalars['Int']['output']; deleteRoomAvailabilityForEvent: Room; deleteSetting: Scalars['Int']['output']; + deleteStudentApplicationForEvent: User; deleteStudentRegistrationForEvent: User; deleteTutorAvailabilityForEvent: User; deleteUser: Scalars['Int']['output']; @@ -161,6 +180,17 @@ export type MutationAddSettingArgs = { }; +export type MutationAddStudentArgs = { + application: NewUserToEventApplication; + student: NewUser; +}; + + +export type MutationAddStudentApplicationForEventArgs = { + application: NewUserToEventApplication; +}; + + export type MutationAddStudentRegistrationForEventArgs = { registration: UserToEventRegistration; }; @@ -223,6 +253,12 @@ export type MutationDeleteSettingArgs = { }; +export type MutationDeleteStudentApplicationForEventArgs = { + eventID: Scalars['Int']['input']; + mail: Scalars['String']['input']; +}; + + export type MutationDeleteStudentRegistrationForEventArgs = { registration: UserToEventRegistration; }; @@ -314,11 +350,17 @@ export type NewLabel = { export type NewQuestion = { answers: Array; - required?: InputMaybe; + required: Scalars['Boolean']['input']; title: Scalars['String']['input']; type: QuestionType; }; +export type NewQuestionResponsePair = { + answerID?: InputMaybe; + questionID: Scalars['Int']['input']; + value?: InputMaybe; +}; + export type NewRoom = { buildingID: Scalars['Int']['input']; capacity?: InputMaybe; @@ -340,6 +382,12 @@ export type NewUser = { sn?: InputMaybe; }; +export type NewUserToEventApplication = { + answers?: InputMaybe>; + eventID: Scalars['Int']['input']; + userMail: Scalars['String']['input']; +}; + export type NewUserToEventAvailability = { eventID: Array; userMail: Scalars['String']['input']; @@ -347,6 +395,7 @@ export type NewUserToEventAvailability = { export type Query = { __typename?: 'Query'; + applications: Array; buildings: Array; events: Array; forms: Array
; @@ -358,6 +407,12 @@ export type Query = { }; +export type QueryApplicationsArgs = { + eventID?: InputMaybe; + studentMail?: InputMaybe>; +}; + + export type QueryBuildingsArgs = { id?: InputMaybe>; }; @@ -415,6 +470,12 @@ export type Question = { type: QuestionType; }; +export type QuestionAnswersPair = { + __typename?: 'QuestionAnswersPair'; + answers: Array; + question: Question; +}; + export enum QuestionType { MultipleChoice = 'MULTIPLE_CHOICE', Scale = 'SCALE', @@ -455,6 +516,7 @@ export type Setting = { export type User = { __typename?: 'User'; + applications?: Maybe>; confirmed: Scalars['Boolean']['output']; eventsAssigned?: Maybe>; eventsAvailable?: Maybe>; @@ -471,6 +533,13 @@ export type UserToEventRegistration = { userMail: Scalars['String']['input']; }; +export type AddStudentApplicationForEventMutationVariables = Exact<{ + application: NewUserToEventApplication; +}>; + + +export type AddStudentApplicationForEventMutation = { __typename?: 'Mutation', addStudentApplicationForEvent: { __typename?: 'User', fn: string } }; + export type AddTutorMutationVariables = Exact<{ firstName: Scalars['String']['input']; lastName: Scalars['String']['input']; @@ -491,9 +560,10 @@ export type RegistrationFormQueryVariables = Exact<{ }>; -export type RegistrationFormQuery = { __typename?: 'Query', forms: Array<{ __typename?: 'Form', title: string, description?: string | null, questions: Array<{ __typename?: 'Question', title: string, type: QuestionType, required: boolean, answers: Array<{ __typename?: 'Answer', ID: number, title: string, points: number }> }> }> }; +export type RegistrationFormQuery = { __typename?: 'Query', forms: Array<{ __typename?: 'Form', title: string, description?: string | null, questions: Array<{ __typename?: 'Question', ID: number, title: string, type: QuestionType, required: boolean, answers: Array<{ __typename?: 'Answer', ID: number, title: string, points: number }> }> }> }; +export const AddStudentApplicationForEventDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"addStudentApplicationForEvent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"application"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"NewUserToEventApplication"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"addStudentApplicationForEvent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"application"},"value":{"kind":"Variable","name":{"kind":"Name","value":"application"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"fn"}}]}}]}}]} as unknown as DocumentNode; export const AddTutorDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"addTutor"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"firstName"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"lastName"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"email"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"eventsAvailable"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"addTutor"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"tutor"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fn"},"value":{"kind":"Variable","name":{"kind":"Name","value":"firstName"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"sn"},"value":{"kind":"Variable","name":{"kind":"Name","value":"lastName"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"mail"},"value":{"kind":"Variable","name":{"kind":"Name","value":"email"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"availability"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"userMail"},"value":{"kind":"Variable","name":{"kind":"Name","value":"email"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"eventID"},"value":{"kind":"Variable","name":{"kind":"Name","value":"eventsAvailable"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"fn"}}]}}]}}]} as unknown as DocumentNode; export const TutorFormEventsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"tutorFormEvents"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"events"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"needsTutors"},"value":{"kind":"BooleanValue","value":true}},{"kind":"Argument","name":{"kind":"Name","value":"onlyFuture"},"value":{"kind":"BooleanValue","value":true}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"from"}},{"kind":"Field","name":{"kind":"Name","value":"to"}},{"kind":"Field","name":{"kind":"Name","value":"topic"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"color"}}]}},{"kind":"Field","name":{"kind":"Name","value":"type"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"color"}}]}}]}}]}}]} as unknown as DocumentNode; -export const RegistrationFormDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"registrationForm"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"eventID"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"forms"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"ListValue","values":[{"kind":"Variable","name":{"kind":"Name","value":"eventID"}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"questions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"required"}},{"kind":"Field","name":{"kind":"Name","value":"answers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"points"}}]}}]}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file +export const RegistrationFormDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"registrationForm"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"eventID"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"forms"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"ListValue","values":[{"kind":"Variable","name":{"kind":"Name","value":"eventID"}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"questions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"required"}},{"kind":"Field","name":{"kind":"Name","value":"answers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"ID"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"points"}}]}}]}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file diff --git a/frontend/lib/gql/mutations/application.graphql b/frontend/lib/gql/mutations/application.graphql new file mode 100644 index 0000000..f770c3d --- /dev/null +++ b/frontend/lib/gql/mutations/application.graphql @@ -0,0 +1,5 @@ +mutation addStudentApplicationForEvent($application:NewUserToEventApplication!) { + addStudentApplicationForEvent(application: $application) { + fn + } +} diff --git a/frontend/lib/gql/queries/forms.graphql b/frontend/lib/gql/queries/forms.graphql index 090666b..42621e4 100644 --- a/frontend/lib/gql/queries/forms.graphql +++ b/frontend/lib/gql/queries/forms.graphql @@ -3,6 +3,7 @@ query registrationForm($eventID:Int!) { title description questions { + ID title type required diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 58a30d3..e4be366 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -31,7 +31,8 @@ "sonner": "^1.5.0", "tailwind-merge": "^2.3.0", "tailwindcss-animate": "^1.0.7", - "zod": "^3.23.8" + "zod": "^3.23.8", + "zustand": "^4.5.4" }, "devDependencies": { "@graphql-codegen/cli": "5.0.2", @@ -11166,6 +11167,15 @@ } } }, + "node_modules/use-sync-external-store": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz", + "integrity": "sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==", + "license": "MIT", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -11497,6 +11507,34 @@ "funding": { "url": "https://github.com/sponsors/colinhacks" } + }, + "node_modules/zustand": { + "version": "4.5.5", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.5.tgz", + "integrity": "sha512-+0PALYNJNgK6hldkgDq2vLrw5f6g/jCInz52n9RTpropGgeAf/ioFUCdtsjCqu4gNhW9D01rUQBROoRjdzyn2Q==", + "license": "MIT", + "dependencies": { + "use-sync-external-store": "1.2.2" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } } } } diff --git a/server/db/init.go b/server/db/init.go index 34caa1d..552d61d 100644 --- a/server/db/init.go +++ b/server/db/init.go @@ -31,6 +31,7 @@ func Init(ctx context.Context, tracer *trace.TracerProvider) (*bun.DB, *sql.DB, )) relations := []interface{}{ + (*models.ApplicationToQuestion)(nil), (*models.EventToUserAssignment)(nil), (*models.UserToEventAvailability)(nil), (*models.UserToEventRegistration)(nil), @@ -45,6 +46,7 @@ func Init(ctx context.Context, tracer *trace.TracerProvider) (*bun.DB, *sql.DB, (*models.Form)(nil), (*models.Question)(nil), (*models.Answer)(nil), + (*models.Application)(nil), (*models.Setting)(nil)} for _, relation := range relations { diff --git a/server/graph/generated.go b/server/graph/generated.go index e9e6132..5e5656e 100644 --- a/server/graph/generated.go +++ b/server/graph/generated.go @@ -41,6 +41,7 @@ type Config struct { type ResolverRoot interface { Answer() AnswerResolver + Application() ApplicationResolver Event() EventResolver Mutation() MutationResolver Query() QueryResolver @@ -65,6 +66,20 @@ type ComplexityRoot struct { Title func(childComplexity int) int } + AnswerValuePair struct { + Answer func(childComplexity int) int + Value func(childComplexity int) int + } + + Application struct { + Accepted func(childComplexity int) int + Event func(childComplexity int) int + Form func(childComplexity int) int + Responses func(childComplexity int) int + Score func(childComplexity int) int + Student func(childComplexity int) int + } + Building struct { City func(childComplexity int) int ID func(childComplexity int) int @@ -118,6 +133,8 @@ type ComplexityRoot struct { AddRoom func(childComplexity int, room models.Room) int AddRoomAvailabilityForEvent func(childComplexity int, availability models.RoomToEventAvailability) int AddSetting func(childComplexity int, setting models.Setting) int + AddStudent func(childComplexity int, student models.User, application model.NewUserToEventApplication) int + AddStudentApplicationForEvent func(childComplexity int, application model.NewUserToEventApplication) int AddStudentRegistrationForEvent func(childComplexity int, registration models.UserToEventRegistration) int AddTutor func(childComplexity int, tutor models.User, availability model.NewUserToEventAvailability) int AddTutorAvailabilityForEvent func(childComplexity int, availability model.NewUserToEventAvailability) int @@ -130,6 +147,7 @@ type ComplexityRoot struct { DeleteRoom func(childComplexity int, number []string, buildingID int) int DeleteRoomAvailabilityForEvent func(childComplexity int, availability models.RoomToEventAvailability) int DeleteSetting func(childComplexity int, key []string) int + DeleteStudentApplicationForEvent func(childComplexity int, mail string, eventID int) int DeleteStudentRegistrationForEvent func(childComplexity int, registration models.UserToEventRegistration) int DeleteTutorAvailabilityForEvent func(childComplexity int, availability model.NewUserToEventAvailability) int DeleteUser func(childComplexity int, mail []string) int @@ -143,14 +161,15 @@ type ComplexityRoot struct { } Query struct { - Buildings func(childComplexity int, id []int) int - Events func(childComplexity int, id []int, umbrellaID []int, label []string, needsTutors *bool, onlyFuture *bool, userMail []string) int - Forms func(childComplexity int, id []int) int - Labels func(childComplexity int, name []string, kind []model.LabelKind) int - Rooms func(childComplexity int, number []string, buildingID int) int - Settings func(childComplexity int, key []string, typeArg []model.ScalarType) int - Umbrellas func(childComplexity int, id []int, onlyFuture *bool) int - Users func(childComplexity int, mail []string) int + Applications func(childComplexity int, eventID *int, studentMail []string) int + Buildings func(childComplexity int, id []int) int + Events func(childComplexity int, id []int, umbrellaID []int, label []string, needsTutors *bool, onlyFuture *bool, userMail []string) int + Forms func(childComplexity int, id []int) int + Labels func(childComplexity int, name []string, kind []model.LabelKind) int + Rooms func(childComplexity int, number []string, buildingID int) int + Settings func(childComplexity int, key []string, typeArg []model.ScalarType) int + Umbrellas func(childComplexity int, id []int, onlyFuture *bool) int + Users func(childComplexity int, mail []string) int } Question struct { @@ -161,6 +180,11 @@ type ComplexityRoot struct { Type func(childComplexity int) int } + QuestionAnswersPair struct { + Answers func(childComplexity int) int + Question func(childComplexity int) int + } + Room struct { Building func(childComplexity int) int Capacity func(childComplexity int) int @@ -176,6 +200,7 @@ type ComplexityRoot struct { } User struct { + Applications func(childComplexity int) int Confirmed func(childComplexity int) int EventsAssigned func(childComplexity int) int EventsAvailable func(childComplexity int) int @@ -189,6 +214,11 @@ type ComplexityRoot struct { type AnswerResolver interface { Points(ctx context.Context, obj *models.Answer) (int, error) } +type ApplicationResolver interface { + Score(ctx context.Context, obj *models.Application) (int, error) + + Responses(ctx context.Context, obj *models.Application) ([]*model.QuestionAnswersPair, error) +} type EventResolver interface { TutorsAssigned(ctx context.Context, obj *models.Event) ([]*model.EventTutorRoomPair, error) @@ -200,6 +230,7 @@ type MutationResolver interface { UpdateUser(ctx context.Context, user models.User) (*models.User, error) DeleteUser(ctx context.Context, mail []string) (int, error) AddTutor(ctx context.Context, tutor models.User, availability model.NewUserToEventAvailability) (*models.User, error) + AddStudent(ctx context.Context, student models.User, application model.NewUserToEventApplication) (*models.User, error) AddEvent(ctx context.Context, event models.Event) (*models.Event, error) UpdateEvent(ctx context.Context, id int, event models.Event) (*models.Event, error) DeleteEvent(ctx context.Context, id []int) (int, error) @@ -226,6 +257,8 @@ type MutationResolver interface { DeleteRoomAvailabilityForEvent(ctx context.Context, availability models.RoomToEventAvailability) (*models.Room, error) AddStudentRegistrationForEvent(ctx context.Context, registration models.UserToEventRegistration) (*models.User, error) DeleteStudentRegistrationForEvent(ctx context.Context, registration models.UserToEventRegistration) (*models.User, error) + AddStudentApplicationForEvent(ctx context.Context, application model.NewUserToEventApplication) (*models.User, error) + DeleteStudentApplicationForEvent(ctx context.Context, mail string, eventID int) (*models.User, error) } type QueryResolver interface { Events(ctx context.Context, id []int, umbrellaID []int, label []string, needsTutors *bool, onlyFuture *bool, userMail []string) ([]*models.Event, error) @@ -236,6 +269,7 @@ type QueryResolver interface { Settings(ctx context.Context, key []string, typeArg []model.ScalarType) ([]*models.Setting, error) Users(ctx context.Context, mail []string) ([]*models.User, error) Forms(ctx context.Context, id []int) ([]*models.Form, error) + Applications(ctx context.Context, eventID *int, studentMail []string) ([]*models.Application, error) } type QuestionResolver interface { Type(ctx context.Context, obj *models.Question) (model.QuestionType, error) @@ -309,6 +343,62 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Answer.Title(childComplexity), true + case "AnswerValuePair.answer": + if e.complexity.AnswerValuePair.Answer == nil { + break + } + + return e.complexity.AnswerValuePair.Answer(childComplexity), true + + case "AnswerValuePair.value": + if e.complexity.AnswerValuePair.Value == nil { + break + } + + return e.complexity.AnswerValuePair.Value(childComplexity), true + + case "Application.accepted": + if e.complexity.Application.Accepted == nil { + break + } + + return e.complexity.Application.Accepted(childComplexity), true + + case "Application.event": + if e.complexity.Application.Event == nil { + break + } + + return e.complexity.Application.Event(childComplexity), true + + case "Application.form": + if e.complexity.Application.Form == nil { + break + } + + return e.complexity.Application.Form(childComplexity), true + + case "Application.responses": + if e.complexity.Application.Responses == nil { + break + } + + return e.complexity.Application.Responses(childComplexity), true + + case "Application.score": + if e.complexity.Application.Score == nil { + break + } + + return e.complexity.Application.Score(childComplexity), true + + case "Application.student": + if e.complexity.Application.Student == nil { + break + } + + return e.complexity.Application.Student(childComplexity), true + case "Building.city": if e.complexity.Building.City == nil { break @@ -608,6 +698,30 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.AddSetting(childComplexity, args["setting"].(models.Setting)), true + case "Mutation.addStudent": + if e.complexity.Mutation.AddStudent == nil { + break + } + + args, err := ec.field_Mutation_addStudent_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.AddStudent(childComplexity, args["student"].(models.User), args["application"].(model.NewUserToEventApplication)), true + + case "Mutation.addStudentApplicationForEvent": + if e.complexity.Mutation.AddStudentApplicationForEvent == nil { + break + } + + args, err := ec.field_Mutation_addStudentApplicationForEvent_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.AddStudentApplicationForEvent(childComplexity, args["application"].(model.NewUserToEventApplication)), true + case "Mutation.addStudentRegistrationForEvent": if e.complexity.Mutation.AddStudentRegistrationForEvent == nil { break @@ -752,6 +866,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.DeleteSetting(childComplexity, args["key"].([]string)), true + case "Mutation.deleteStudentApplicationForEvent": + if e.complexity.Mutation.DeleteStudentApplicationForEvent == nil { + break + } + + args, err := ec.field_Mutation_deleteStudentApplicationForEvent_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.DeleteStudentApplicationForEvent(childComplexity, args["mail"].(string), args["eventID"].(int)), true + case "Mutation.deleteStudentRegistrationForEvent": if e.complexity.Mutation.DeleteStudentRegistrationForEvent == nil { break @@ -872,6 +998,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.UpdateUser(childComplexity, args["user"].(models.User)), true + case "Query.applications": + if e.complexity.Query.Applications == nil { + break + } + + args, err := ec.field_Query_applications_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Applications(childComplexity, args["eventID"].(*int), args["studentMail"].([]string)), true + case "Query.buildings": if e.complexity.Query.Buildings == nil { break @@ -1003,6 +1141,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Question.Type(childComplexity), true + case "QuestionAnswersPair.answers": + if e.complexity.QuestionAnswersPair.Answers == nil { + break + } + + return e.complexity.QuestionAnswersPair.Answers(childComplexity), true + + case "QuestionAnswersPair.question": + if e.complexity.QuestionAnswersPair.Question == nil { + break + } + + return e.complexity.QuestionAnswersPair.Question(childComplexity), true + case "Room.building": if e.complexity.Room.Building == nil { break @@ -1059,6 +1211,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Setting.Value(childComplexity), true + case "User.applications": + if e.complexity.User.Applications == nil { + break + } + + return e.complexity.User.Applications(childComplexity), true + case "User.confirmed": if e.complexity.User.Confirmed == nil { break @@ -1123,9 +1282,11 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputNewForm, ec.unmarshalInputNewLabel, ec.unmarshalInputNewQuestion, + ec.unmarshalInputNewQuestionResponsePair, ec.unmarshalInputNewRoom, ec.unmarshalInputNewSetting, ec.unmarshalInputNewUser, + ec.unmarshalInputNewUserToEventApplication, ec.unmarshalInputNewUserToEventAvailability, ec.unmarshalInputRoomToEventAvailability, ec.unmarshalInputUserToEventRegistration, @@ -1365,6 +1526,21 @@ func (ec *executionContext) field_Mutation_addSetting_args(ctx context.Context, return args, nil } +func (ec *executionContext) field_Mutation_addStudentApplicationForEvent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 model.NewUserToEventApplication + if tmp, ok := rawArgs["application"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("application")) + arg0, err = ec.unmarshalNNewUserToEventApplication2githubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐNewUserToEventApplication(ctx, tmp) + if err != nil { + return nil, err + } + } + args["application"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_addStudentRegistrationForEvent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1380,6 +1556,30 @@ func (ec *executionContext) field_Mutation_addStudentRegistrationForEvent_args(c return args, nil } +func (ec *executionContext) field_Mutation_addStudent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 models.User + if tmp, ok := rawArgs["student"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("student")) + arg0, err = ec.unmarshalNNewUser2githubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐUser(ctx, tmp) + if err != nil { + return nil, err + } + } + args["student"] = arg0 + var arg1 model.NewUserToEventApplication + if tmp, ok := rawArgs["application"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("application")) + arg1, err = ec.unmarshalNNewUserToEventApplication2githubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐNewUserToEventApplication(ctx, tmp) + if err != nil { + return nil, err + } + } + args["application"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_addTutorAvailabilityForEvent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1563,6 +1763,30 @@ func (ec *executionContext) field_Mutation_deleteSetting_args(ctx context.Contex return args, nil } +func (ec *executionContext) field_Mutation_deleteStudentApplicationForEvent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["mail"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("mail")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["mail"] = arg0 + var arg1 int + if tmp, ok := rawArgs["eventID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("eventID")) + arg1, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["eventID"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_deleteStudentRegistrationForEvent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1755,6 +1979,30 @@ func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs return args, nil } +func (ec *executionContext) field_Query_applications_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *int + if tmp, ok := rawArgs["eventID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("eventID")) + arg0, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["eventID"] = arg0 + var arg1 []string + if tmp, ok := rawArgs["studentMail"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("studentMail")) + arg1, err = ec.unmarshalOString2ᚕstringᚄ(ctx, tmp) + if err != nil { + return nil, err + } + } + args["studentMail"] = arg1 + return args, nil +} + func (ec *executionContext) field_Query_buildings_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -2126,8 +2374,8 @@ func (ec *executionContext) fieldContext_Answer_points(_ context.Context, field return fc, nil } -func (ec *executionContext) _Building_ID(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Building_ID(ctx, field) +func (ec *executionContext) _AnswerValuePair_answer(ctx context.Context, field graphql.CollectedField, obj *model.AnswerValuePair) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnswerValuePair_answer(ctx, field) if err != nil { return graphql.Null } @@ -2140,38 +2388,43 @@ func (ec *executionContext) _Building_ID(ctx context.Context, field graphql.Coll }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.ID, nil + return obj.Answer, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(int32) + res := resTmp.(*models.Answer) fc.Result = res - return ec.marshalNInt2int32(ctx, field.Selections, res) + return ec.marshalOAnswer2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐAnswer(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Building_ID(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_AnswerValuePair_answer(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Building", + Object: "AnswerValuePair", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Int does not have child fields") + switch field.Name { + case "ID": + return ec.fieldContext_Answer_ID(ctx, field) + case "title": + return ec.fieldContext_Answer_title(ctx, field) + case "points": + return ec.fieldContext_Answer_points(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Answer", field.Name) }, } return fc, nil } -func (ec *executionContext) _Building_name(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Building_name(ctx, field) +func (ec *executionContext) _AnswerValuePair_value(ctx context.Context, field graphql.CollectedField, obj *model.AnswerValuePair) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AnswerValuePair_value(ctx, field) if err != nil { return graphql.Null } @@ -2184,26 +2437,23 @@ func (ec *executionContext) _Building_name(ctx context.Context, field graphql.Co }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Name, nil + return obj.Value, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(string) + res := resTmp.(*string) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Building_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_AnswerValuePair_value(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Building", + Object: "AnswerValuePair", Field: field, IsMethod: false, IsResolver: false, @@ -2214,8 +2464,8 @@ func (ec *executionContext) fieldContext_Building_name(_ context.Context, field return fc, nil } -func (ec *executionContext) _Building_street(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Building_street(ctx, field) +func (ec *executionContext) _Application_event(ctx context.Context, field graphql.CollectedField, obj *models.Application) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Application_event(ctx, field) if err != nil { return graphql.Null } @@ -2228,7 +2478,7 @@ func (ec *executionContext) _Building_street(ctx context.Context, field graphql. }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Street, nil + return obj.Event, nil }) if err != nil { ec.Error(ctx, err) @@ -2240,26 +2490,52 @@ func (ec *executionContext) _Building_street(ctx context.Context, field graphql. } return graphql.Null } - res := resTmp.(string) + res := resTmp.(*models.Event) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNEvent2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐEvent(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Building_street(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Application_event(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Building", + Object: "Application", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + switch field.Name { + case "ID": + return ec.fieldContext_Event_ID(ctx, field) + case "tutorsAssigned": + return ec.fieldContext_Event_tutorsAssigned(ctx, field) + case "tutorsAvailable": + return ec.fieldContext_Event_tutorsAvailable(ctx, field) + case "roomsAvailable": + return ec.fieldContext_Event_roomsAvailable(ctx, field) + case "umbrella": + return ec.fieldContext_Event_umbrella(ctx, field) + case "needsTutors": + return ec.fieldContext_Event_needsTutors(ctx, field) + case "title": + return ec.fieldContext_Event_title(ctx, field) + case "description": + return ec.fieldContext_Event_description(ctx, field) + case "topic": + return ec.fieldContext_Event_topic(ctx, field) + case "type": + return ec.fieldContext_Event_type(ctx, field) + case "from": + return ec.fieldContext_Event_from(ctx, field) + case "to": + return ec.fieldContext_Event_to(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Event", field.Name) }, } return fc, nil } -func (ec *executionContext) _Building_number(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Building_number(ctx, field) +func (ec *executionContext) _Application_student(ctx context.Context, field graphql.CollectedField, obj *models.Application) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Application_student(ctx, field) if err != nil { return graphql.Null } @@ -2272,7 +2548,7 @@ func (ec *executionContext) _Building_number(ctx context.Context, field graphql. }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Number, nil + return obj.Student, nil }) if err != nil { ec.Error(ctx, err) @@ -2284,26 +2560,44 @@ func (ec *executionContext) _Building_number(ctx context.Context, field graphql. } return graphql.Null } - res := resTmp.(string) + res := resTmp.(*models.User) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNUser2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐUser(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Building_number(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Application_student(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Building", + Object: "Application", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + switch field.Name { + case "fn": + return ec.fieldContext_User_fn(ctx, field) + case "sn": + return ec.fieldContext_User_sn(ctx, field) + case "mail": + return ec.fieldContext_User_mail(ctx, field) + case "confirmed": + return ec.fieldContext_User_confirmed(ctx, field) + case "eventsRegistered": + return ec.fieldContext_User_eventsRegistered(ctx, field) + case "eventsAvailable": + return ec.fieldContext_User_eventsAvailable(ctx, field) + case "eventsAssigned": + return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, } return fc, nil } -func (ec *executionContext) _Building_city(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Building_city(ctx, field) +func (ec *executionContext) _Application_score(ctx context.Context, field graphql.CollectedField, obj *models.Application) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Application_score(ctx, field) if err != nil { return graphql.Null } @@ -2316,7 +2610,7 @@ func (ec *executionContext) _Building_city(ctx context.Context, field graphql.Co }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.City, nil + return ec.resolvers.Application().Score(rctx, obj) }) if err != nil { ec.Error(ctx, err) @@ -2328,26 +2622,388 @@ func (ec *executionContext) _Building_city(ctx context.Context, field graphql.Co } return graphql.Null } - res := resTmp.(string) + res := resTmp.(int) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Building_city(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Application_score(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Building", + Object: "Application", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil } -func (ec *executionContext) _Building_zip(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Building_zip(ctx, field) +func (ec *executionContext) _Application_accepted(ctx context.Context, field graphql.CollectedField, obj *models.Application) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Application_accepted(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Accepted, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*bool) + fc.Result = res + return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Application_accepted(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Application", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Application_form(ctx context.Context, field graphql.CollectedField, obj *models.Application) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Application_form(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Form, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*models.Form) + fc.Result = res + return ec.marshalNForm2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐForm(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Application_form(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Application", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "eventID": + return ec.fieldContext_Form_eventID(ctx, field) + case "title": + return ec.fieldContext_Form_title(ctx, field) + case "description": + return ec.fieldContext_Form_description(ctx, field) + case "questions": + return ec.fieldContext_Form_questions(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Form", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _Application_responses(ctx context.Context, field graphql.CollectedField, obj *models.Application) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Application_responses(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Application().Responses(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]*model.QuestionAnswersPair) + fc.Result = res + return ec.marshalOQuestionAnswersPair2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐQuestionAnswersPairᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Application_responses(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Application", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "question": + return ec.fieldContext_QuestionAnswersPair_question(ctx, field) + case "answers": + return ec.fieldContext_QuestionAnswersPair_answers(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type QuestionAnswersPair", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _Building_ID(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Building_ID(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int32) + fc.Result = res + return ec.marshalNInt2int32(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Building_ID(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Building", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Building_name(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Building_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Building_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Building", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Building_street(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Building_street(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Street, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Building_street(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Building", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Building_number(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Building_number(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Number, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Building_number(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Building", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Building_city(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Building_city(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.City, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Building_city(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Building", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Building_zip(ctx context.Context, field graphql.CollectedField, obj *models.Building) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Building_zip(ctx, field) if err != nil { return graphql.Null } @@ -2630,6 +3286,8 @@ func (ec *executionContext) fieldContext_Event_tutorsAvailable(_ context.Context return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -3124,6 +3782,8 @@ func (ec *executionContext) fieldContext_EventTutorRoomPair_tutors(_ context.Con return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -3548,6 +4208,8 @@ func (ec *executionContext) fieldContext_Mutation_addUser(ctx context.Context, f return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -3619,6 +4281,8 @@ func (ec *executionContext) fieldContext_Mutation_updateUser(ctx context.Context return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -3745,6 +4409,8 @@ func (ec *executionContext) fieldContext_Mutation_addTutor(ctx context.Context, return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -3763,6 +4429,79 @@ func (ec *executionContext) fieldContext_Mutation_addTutor(ctx context.Context, return fc, nil } +func (ec *executionContext) _Mutation_addStudent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_addStudent(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().AddStudent(rctx, fc.Args["student"].(models.User), fc.Args["application"].(model.NewUserToEventApplication)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*models.User) + fc.Result = res + return ec.marshalNUser2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_addStudent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "fn": + return ec.fieldContext_User_fn(ctx, field) + case "sn": + return ec.fieldContext_User_sn(ctx, field) + case "mail": + return ec.fieldContext_User_mail(ctx, field) + case "confirmed": + return ec.fieldContext_User_confirmed(ctx, field) + case "eventsRegistered": + return ec.fieldContext_User_eventsRegistered(ctx, field) + case "eventsAvailable": + return ec.fieldContext_User_eventsAvailable(ctx, field) + case "eventsAssigned": + return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type User", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_addStudent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Mutation_addEvent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Mutation_addEvent(ctx, field) if err != nil { @@ -5128,6 +5867,8 @@ func (ec *executionContext) fieldContext_Mutation_addTutorAvailabilityForEvent(c return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -5199,6 +5940,8 @@ func (ec *executionContext) fieldContext_Mutation_deleteTutorAvailabilityForEven return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -5277,15 +6020,155 @@ func (ec *executionContext) fieldContext_Mutation_addRoomAvailabilityForEvent(ct } }() ctx = graphql.WithFieldContext(ctx, fc) - if fc.Args, err = ec.field_Mutation_addRoomAvailabilityForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + if fc.Args, err = ec.field_Mutation_addRoomAvailabilityForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteRoomAvailabilityForEvent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deleteRoomAvailabilityForEvent(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().DeleteRoomAvailabilityForEvent(rctx, fc.Args["availability"].(models.RoomToEventAvailability)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*models.Room) + fc.Result = res + return ec.marshalNRoom2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐRoom(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_deleteRoomAvailabilityForEvent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext_Room_name(ctx, field) + case "number": + return ec.fieldContext_Room_number(ctx, field) + case "capacity": + return ec.fieldContext_Room_capacity(ctx, field) + case "floor": + return ec.fieldContext_Room_floor(ctx, field) + case "building": + return ec.fieldContext_Room_building(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Room", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_deleteRoomAvailabilityForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_addStudentRegistrationForEvent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_addStudentRegistrationForEvent(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().AddStudentRegistrationForEvent(rctx, fc.Args["registration"].(models.UserToEventRegistration)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*models.User) + fc.Result = res + return ec.marshalNUser2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_addStudentRegistrationForEvent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "fn": + return ec.fieldContext_User_fn(ctx, field) + case "sn": + return ec.fieldContext_User_sn(ctx, field) + case "mail": + return ec.fieldContext_User_mail(ctx, field) + case "confirmed": + return ec.fieldContext_User_confirmed(ctx, field) + case "eventsRegistered": + return ec.fieldContext_User_eventsRegistered(ctx, field) + case "eventsAvailable": + return ec.fieldContext_User_eventsAvailable(ctx, field) + case "eventsAssigned": + return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type User", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_addStudentRegistrationForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { ec.Error(ctx, err) return fc, err } return fc, nil } -func (ec *executionContext) _Mutation_deleteRoomAvailabilityForEvent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_deleteRoomAvailabilityForEvent(ctx, field) +func (ec *executionContext) _Mutation_deleteStudentRegistrationForEvent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deleteStudentRegistrationForEvent(ctx, field) if err != nil { return graphql.Null } @@ -5298,7 +6181,7 @@ func (ec *executionContext) _Mutation_deleteRoomAvailabilityForEvent(ctx context }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().DeleteRoomAvailabilityForEvent(rctx, fc.Args["availability"].(models.RoomToEventAvailability)) + return ec.resolvers.Mutation().DeleteStudentRegistrationForEvent(rctx, fc.Args["registration"].(models.UserToEventRegistration)) }) if err != nil { ec.Error(ctx, err) @@ -5310,12 +6193,12 @@ func (ec *executionContext) _Mutation_deleteRoomAvailabilityForEvent(ctx context } return graphql.Null } - res := resTmp.(*models.Room) + res := resTmp.(*models.User) fc.Result = res - return ec.marshalNRoom2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐRoom(ctx, field.Selections, res) + return ec.marshalNUser2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐUser(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_deleteRoomAvailabilityForEvent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_deleteStudentRegistrationForEvent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Mutation", Field: field, @@ -5323,18 +6206,24 @@ func (ec *executionContext) fieldContext_Mutation_deleteRoomAvailabilityForEvent IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { - case "name": - return ec.fieldContext_Room_name(ctx, field) - case "number": - return ec.fieldContext_Room_number(ctx, field) - case "capacity": - return ec.fieldContext_Room_capacity(ctx, field) - case "floor": - return ec.fieldContext_Room_floor(ctx, field) - case "building": - return ec.fieldContext_Room_building(ctx, field) + case "fn": + return ec.fieldContext_User_fn(ctx, field) + case "sn": + return ec.fieldContext_User_sn(ctx, field) + case "mail": + return ec.fieldContext_User_mail(ctx, field) + case "confirmed": + return ec.fieldContext_User_confirmed(ctx, field) + case "eventsRegistered": + return ec.fieldContext_User_eventsRegistered(ctx, field) + case "eventsAvailable": + return ec.fieldContext_User_eventsAvailable(ctx, field) + case "eventsAssigned": + return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type Room", field.Name) + return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, } defer func() { @@ -5344,15 +6233,15 @@ func (ec *executionContext) fieldContext_Mutation_deleteRoomAvailabilityForEvent } }() ctx = graphql.WithFieldContext(ctx, fc) - if fc.Args, err = ec.field_Mutation_deleteRoomAvailabilityForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + if fc.Args, err = ec.field_Mutation_deleteStudentRegistrationForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { ec.Error(ctx, err) return fc, err } return fc, nil } -func (ec *executionContext) _Mutation_addStudentRegistrationForEvent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_addStudentRegistrationForEvent(ctx, field) +func (ec *executionContext) _Mutation_addStudentApplicationForEvent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_addStudentApplicationForEvent(ctx, field) if err != nil { return graphql.Null } @@ -5365,7 +6254,7 @@ func (ec *executionContext) _Mutation_addStudentRegistrationForEvent(ctx context }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().AddStudentRegistrationForEvent(rctx, fc.Args["registration"].(models.UserToEventRegistration)) + return ec.resolvers.Mutation().AddStudentApplicationForEvent(rctx, fc.Args["application"].(model.NewUserToEventApplication)) }) if err != nil { ec.Error(ctx, err) @@ -5382,7 +6271,7 @@ func (ec *executionContext) _Mutation_addStudentRegistrationForEvent(ctx context return ec.marshalNUser2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐUser(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_addStudentRegistrationForEvent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_addStudentApplicationForEvent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Mutation", Field: field, @@ -5404,6 +6293,8 @@ func (ec *executionContext) fieldContext_Mutation_addStudentRegistrationForEvent return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -5415,15 +6306,15 @@ func (ec *executionContext) fieldContext_Mutation_addStudentRegistrationForEvent } }() ctx = graphql.WithFieldContext(ctx, fc) - if fc.Args, err = ec.field_Mutation_addStudentRegistrationForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + if fc.Args, err = ec.field_Mutation_addStudentApplicationForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { ec.Error(ctx, err) return fc, err } return fc, nil } -func (ec *executionContext) _Mutation_deleteStudentRegistrationForEvent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_deleteStudentRegistrationForEvent(ctx, field) +func (ec *executionContext) _Mutation_deleteStudentApplicationForEvent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deleteStudentApplicationForEvent(ctx, field) if err != nil { return graphql.Null } @@ -5436,7 +6327,7 @@ func (ec *executionContext) _Mutation_deleteStudentRegistrationForEvent(ctx cont }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().DeleteStudentRegistrationForEvent(rctx, fc.Args["registration"].(models.UserToEventRegistration)) + return ec.resolvers.Mutation().DeleteStudentApplicationForEvent(rctx, fc.Args["mail"].(string), fc.Args["eventID"].(int)) }) if err != nil { ec.Error(ctx, err) @@ -5453,7 +6344,7 @@ func (ec *executionContext) _Mutation_deleteStudentRegistrationForEvent(ctx cont return ec.marshalNUser2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐUser(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_deleteStudentRegistrationForEvent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_deleteStudentApplicationForEvent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Mutation", Field: field, @@ -5475,6 +6366,8 @@ func (ec *executionContext) fieldContext_Mutation_deleteStudentRegistrationForEv return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -5486,7 +6379,7 @@ func (ec *executionContext) fieldContext_Mutation_deleteStudentRegistrationForEv } }() ctx = graphql.WithFieldContext(ctx, fc) - if fc.Args, err = ec.field_Mutation_deleteStudentRegistrationForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + if fc.Args, err = ec.field_Mutation_deleteStudentApplicationForEvent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { ec.Error(ctx, err) return fc, err } @@ -5972,6 +6865,8 @@ func (ec *executionContext) fieldContext_Query_users(ctx context.Context, field return ec.fieldContext_User_eventsAvailable(ctx, field) case "eventsAssigned": return ec.fieldContext_User_eventsAssigned(ctx, field) + case "applications": + return ec.fieldContext_User_applications(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -6055,6 +6950,75 @@ func (ec *executionContext) fieldContext_Query_forms(ctx context.Context, field return fc, nil } +func (ec *executionContext) _Query_applications(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_applications(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Applications(rctx, fc.Args["eventID"].(*int), fc.Args["studentMail"].([]string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*models.Application) + fc.Result = res + return ec.marshalNApplication2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐApplicationᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_applications(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "event": + return ec.fieldContext_Application_event(ctx, field) + case "student": + return ec.fieldContext_Application_student(ctx, field) + case "score": + return ec.fieldContext_Application_score(ctx, field) + case "accepted": + return ec.fieldContext_Application_accepted(ctx, field) + case "form": + return ec.fieldContext_Application_form(ctx, field) + case "responses": + return ec.fieldContext_Application_responses(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Application", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_applications_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Query___type(ctx, field) if err != nil { @@ -6412,6 +7376,112 @@ func (ec *executionContext) fieldContext_Question_answers(_ context.Context, fie return fc, nil } +func (ec *executionContext) _QuestionAnswersPair_question(ctx context.Context, field graphql.CollectedField, obj *model.QuestionAnswersPair) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_QuestionAnswersPair_question(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Question, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*models.Question) + fc.Result = res + return ec.marshalNQuestion2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐQuestion(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_QuestionAnswersPair_question(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "QuestionAnswersPair", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "ID": + return ec.fieldContext_Question_ID(ctx, field) + case "title": + return ec.fieldContext_Question_title(ctx, field) + case "type": + return ec.fieldContext_Question_type(ctx, field) + case "required": + return ec.fieldContext_Question_required(ctx, field) + case "answers": + return ec.fieldContext_Question_answers(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Question", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _QuestionAnswersPair_answers(ctx context.Context, field graphql.CollectedField, obj *model.QuestionAnswersPair) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_QuestionAnswersPair_answers(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Answers, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.AnswerValuePair) + fc.Result = res + return ec.marshalNAnswerValuePair2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐAnswerValuePairᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_QuestionAnswersPair_answers(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "QuestionAnswersPair", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "answer": + return ec.fieldContext_AnswerValuePair_answer(ctx, field) + case "value": + return ec.fieldContext_AnswerValuePair_value(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type AnswerValuePair", field.Name) + }, + } + return fc, nil +} + func (ec *executionContext) _Room_name(ctx context.Context, field graphql.CollectedField, obj *models.Room) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Room_name(ctx, field) if err != nil { @@ -7150,6 +8220,61 @@ func (ec *executionContext) fieldContext_User_eventsAssigned(_ context.Context, return fc, nil } +func (ec *executionContext) _User_applications(ctx context.Context, field graphql.CollectedField, obj *models.User) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_User_applications(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Applications, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]*models.Application) + fc.Result = res + return ec.marshalOApplication2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐApplicationᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_User_applications(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "User", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "event": + return ec.fieldContext_Application_event(ctx, field) + case "student": + return ec.fieldContext_Application_student(ctx, field) + case "score": + return ec.fieldContext_Application_score(ctx, field) + case "accepted": + return ec.fieldContext_Application_accepted(ctx, field) + case "form": + return ec.fieldContext_Application_form(ctx, field) + case "responses": + return ec.fieldContext_Application_responses(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Application", field.Name) + }, + } + return fc, nil +} + func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { fc, err := ec.fieldContext___Directive_name(ctx, field) if err != nil { @@ -9260,23 +10385,64 @@ func (ec *executionContext) unmarshalInputNewQuestion(ctx context.Context, obj i if err != nil { return it, err } - if err = ec.resolvers.NewQuestion().Type(ctx, &it, data); err != nil { - return it, err - } - case "answers": - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("answers")) - data, err := ec.unmarshalNNewAnswer2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐAnswerᚄ(ctx, v) + if err = ec.resolvers.NewQuestion().Type(ctx, &it, data); err != nil { + return it, err + } + case "answers": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("answers")) + data, err := ec.unmarshalNNewAnswer2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐAnswerᚄ(ctx, v) + if err != nil { + return it, err + } + it.Answers = data + case "required": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("required")) + data, err := ec.unmarshalNBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.Required = data + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputNewQuestionResponsePair(ctx context.Context, obj interface{}) (model.NewQuestionResponsePair, error) { + var it model.NewQuestionResponsePair + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"questionID", "answerID", "value"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "questionID": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("questionID")) + data, err := ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + it.QuestionID = data + case "answerID": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("answerID")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) if err != nil { return it, err } - it.Answers = data - case "required": - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("required")) - data, err := ec.unmarshalNBoolean2bool(ctx, v) + it.AnswerID = data + case "value": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - it.Required = data + it.Value = data } } @@ -9433,6 +10599,47 @@ func (ec *executionContext) unmarshalInputNewUser(ctx context.Context, obj inter return it, nil } +func (ec *executionContext) unmarshalInputNewUserToEventApplication(ctx context.Context, obj interface{}) (model.NewUserToEventApplication, error) { + var it model.NewUserToEventApplication + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"userMail", "eventID", "answers"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "userMail": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("userMail")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.UserMail = data + case "eventID": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("eventID")) + data, err := ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + it.EventID = data + case "answers": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("answers")) + data, err := ec.unmarshalONewQuestionResponsePair2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐNewQuestionResponsePairᚄ(ctx, v) + if err != nil { + return it, err + } + it.Answers = data + } + } + + return it, nil +} + func (ec *executionContext) unmarshalInputNewUserToEventAvailability(ctx context.Context, obj interface{}) (model.NewUserToEventAvailability, error) { var it model.NewUserToEventAvailability asMap := map[string]interface{}{} @@ -9644,6 +10851,164 @@ func (ec *executionContext) _Answer(ctx context.Context, sel ast.SelectionSet, o return out } +var answerValuePairImplementors = []string{"AnswerValuePair"} + +func (ec *executionContext) _AnswerValuePair(ctx context.Context, sel ast.SelectionSet, obj *model.AnswerValuePair) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, answerValuePairImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("AnswerValuePair") + case "answer": + out.Values[i] = ec._AnswerValuePair_answer(ctx, field, obj) + case "value": + out.Values[i] = ec._AnswerValuePair_value(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var applicationImplementors = []string{"Application"} + +func (ec *executionContext) _Application(ctx context.Context, sel ast.SelectionSet, obj *models.Application) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, applicationImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Application") + case "event": + out.Values[i] = ec._Application_event(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "student": + out.Values[i] = ec._Application_student(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "score": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Application_score(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "accepted": + out.Values[i] = ec._Application_accepted(ctx, field, obj) + case "form": + out.Values[i] = ec._Application_form(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "responses": + field := field + + innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Application_responses(ctx, field, obj) + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + var buildingImplementors = []string{"Building"} func (ec *executionContext) _Building(ctx context.Context, sel ast.SelectionSet, obj *models.Building) graphql.Marshaler { @@ -10066,6 +11431,13 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { out.Invalids++ } + case "addStudent": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_addStudent(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "addEvent": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_addEvent(ctx, field) @@ -10248,6 +11620,20 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { out.Invalids++ } + case "addStudentApplicationForEvent": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_addStudentApplicationForEvent(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deleteStudentApplicationForEvent": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteStudentApplicationForEvent(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -10465,6 +11851,28 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "applications": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_applications(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) case "__type": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { @@ -10548,21 +11956,65 @@ func (ec *executionContext) _Question(ctx context.Context, sel ast.SelectionSet, return innerFunc(ctx, dfs) }) - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue - } + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "required": + out.Values[i] = ec._Question_required(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "answers": + out.Values[i] = ec._Question_answers(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) - case "required": - out.Values[i] = ec._Question_required(ctx, field, obj) +var questionAnswersPairImplementors = []string{"QuestionAnswersPair"} + +func (ec *executionContext) _QuestionAnswersPair(ctx context.Context, sel ast.SelectionSet, obj *model.QuestionAnswersPair) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, questionAnswersPairImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("QuestionAnswersPair") + case "question": + out.Values[i] = ec._QuestionAnswersPair_question(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "answers": - out.Values[i] = ec._Question_answers(ctx, field, obj) + out.Values[i] = ec._QuestionAnswersPair_answers(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } default: panic("unknown field " + strconv.Quote(field.Name)) @@ -10816,6 +12268,8 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = ec._User_eventsAvailable(ctx, field, obj) case "eventsAssigned": out.Values[i] = ec._User_eventsAssigned(ctx, field, obj) + case "applications": + out.Values[i] = ec._User_applications(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -11219,6 +12673,114 @@ func (ec *executionContext) marshalNAnswer2ᚖgithubᚗcomᚋFachschaftMathPhysI return ec._Answer(ctx, sel, v) } +func (ec *executionContext) marshalNAnswerValuePair2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐAnswerValuePairᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.AnswerValuePair) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNAnswerValuePair2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐAnswerValuePair(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNAnswerValuePair2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐAnswerValuePair(ctx context.Context, sel ast.SelectionSet, v *model.AnswerValuePair) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._AnswerValuePair(ctx, sel, v) +} + +func (ec *executionContext) marshalNApplication2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐApplicationᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Application) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNApplication2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐApplication(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNApplication2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐApplication(ctx context.Context, sel ast.SelectionSet, v *models.Application) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._Application(ctx, sel, v) +} + func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { res, err := graphql.UnmarshalBoolean(v) return res, graphql.ErrorOnPath(ctx, err) @@ -11617,6 +13179,11 @@ func (ec *executionContext) unmarshalNNewQuestion2ᚖgithubᚗcomᚋFachschaftMa return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNNewQuestionResponsePair2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐNewQuestionResponsePair(ctx context.Context, v interface{}) (*model.NewQuestionResponsePair, error) { + res, err := ec.unmarshalInputNewQuestionResponsePair(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNNewRoom2githubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐRoom(ctx context.Context, v interface{}) (models.Room, error) { res, err := ec.unmarshalInputNewRoom(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -11632,6 +13199,11 @@ func (ec *executionContext) unmarshalNNewUser2githubᚗcomᚋFachschaftMathPhysI return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNNewUserToEventApplication2githubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐNewUserToEventApplication(ctx context.Context, v interface{}) (model.NewUserToEventApplication, error) { + res, err := ec.unmarshalInputNewUserToEventApplication(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNNewUserToEventAvailability2githubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐNewUserToEventAvailability(ctx context.Context, v interface{}) (model.NewUserToEventAvailability, error) { res, err := ec.unmarshalInputNewUserToEventAvailability(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -11691,6 +13263,16 @@ func (ec *executionContext) marshalNQuestion2ᚖgithubᚗcomᚋFachschaftMathPhy return ec._Question(ctx, sel, v) } +func (ec *executionContext) marshalNQuestionAnswersPair2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐQuestionAnswersPair(ctx context.Context, sel ast.SelectionSet, v *model.QuestionAnswersPair) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._QuestionAnswersPair(ctx, sel, v) +} + func (ec *executionContext) unmarshalNQuestionType2githubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐQuestionType(ctx context.Context, v interface{}) (model.QuestionType, error) { var res model.QuestionType err := res.UnmarshalGQL(v) @@ -12210,6 +13792,60 @@ func (ec *executionContext) marshalNtimestamptz2string(ctx context.Context, sel return res } +func (ec *executionContext) marshalOAnswer2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐAnswer(ctx context.Context, sel ast.SelectionSet, v *models.Answer) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Answer(ctx, sel, v) +} + +func (ec *executionContext) marshalOApplication2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐApplicationᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Application) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNApplication2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐApplication(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { res, err := graphql.UnmarshalBoolean(v) return res, graphql.ErrorOnPath(ctx, err) @@ -12484,6 +14120,73 @@ func (ec *executionContext) marshalOLabelKind2ᚕgithubᚗcomᚋFachschaftMathPh return ret } +func (ec *executionContext) unmarshalONewQuestionResponsePair2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐNewQuestionResponsePairᚄ(ctx context.Context, v interface{}) ([]*model.NewQuestionResponsePair, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]*model.NewQuestionResponsePair, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNNewQuestionResponsePair2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐNewQuestionResponsePair(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalOQuestionAnswersPair2ᚕᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐQuestionAnswersPairᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.QuestionAnswersPair) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNQuestionAnswersPair2ᚖgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋgraphᚋmodelᚐQuestionAnswersPair(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + func (ec *executionContext) marshalORoom2ᚕgithubᚗcomᚋFachschaftMathPhysInfoᚋpeppᚋserverᚋmodelsᚐRoomᚄ(ctx context.Context, sel ast.SelectionSet, v []models.Room) graphql.Marshaler { if v == nil { return graphql.Null diff --git a/server/graph/model/models_gen.go b/server/graph/model/models_gen.go index 7375cd4..51774e2 100644 --- a/server/graph/model/models_gen.go +++ b/server/graph/model/models_gen.go @@ -10,6 +10,11 @@ import ( "github.com/FachschaftMathPhysInfo/pepp/server/models" ) +type AnswerValuePair struct { + Answer *models.Answer `json:"answer,omitempty"` + Value *string `json:"value,omitempty"` +} + type EventTutorRoomPair struct { Tutors []*models.User `json:"tutors,omitempty"` Room *models.Room `json:"room,omitempty"` @@ -19,6 +24,18 @@ type EventTutorRoomPair struct { type Mutation struct { } +type NewQuestionResponsePair struct { + QuestionID int `json:"questionID"` + AnswerID *int `json:"answerID,omitempty"` + Value *string `json:"value,omitempty"` +} + +type NewUserToEventApplication struct { + UserMail string `json:"userMail"` + EventID int `json:"eventID"` + Answers []*NewQuestionResponsePair `json:"answers,omitempty"` +} + type NewUserToEventAvailability struct { UserMail string `json:"userMail"` EventID []int `json:"eventID"` @@ -27,6 +44,11 @@ type NewUserToEventAvailability struct { type Query struct { } +type QuestionAnswersPair struct { + Question *models.Question `json:"question"` + Answers []*AnswerValuePair `json:"answers"` +} + type LabelKind string const ( diff --git a/server/graph/schema.graphqls b/server/graph/schema.graphqls index 5c708dc..3d31f36 100644 --- a/server/graph/schema.graphqls +++ b/server/graph/schema.graphqls @@ -18,6 +18,7 @@ type User { eventsRegistered: [Event!] eventsAvailable: [Event!] eventsAssigned: [Event!] + applications: [Application!] } enum LabelKind { @@ -104,6 +105,25 @@ type Setting { type: ScalarType! } +type AnswerValuePair { + answer: Answer + value: String +} + +type QuestionAnswersPair { + question: Question! + answers: [AnswerValuePair!]! +} + +type Application { + event: Event! + student: User! + score: Int! + accepted: Boolean + form: Form! + responses: [QuestionAnswersPair!] +} + type Query { events(id: [Int!], umbrellaID: [Int!], label: [String!], needsTutors: Boolean, onlyFuture: Boolean, userMail: [String!]): [Event!]! umbrellas(id: [Int!], onlyFuture: Boolean): [Event!]! @@ -113,6 +133,7 @@ type Query { settings(key: [String!], type: [ScalarType!]): [Setting!]! users(mail: [String!]): [User!]! forms(id: [Int!]): [Form!]! + applications(eventID: Int, studentMail: [String!]): [Application!]! } input NewUser { @@ -205,11 +226,24 @@ input UserToEventRegistration { buildingID: Int! } +input NewQuestionResponsePair { + questionID: Int! + answerID: Int + value: String +} + +input NewUserToEventApplication { + userMail: String! + eventID: Int! + answers: [NewQuestionResponsePair!] +} + type Mutation { addUser(user: NewUser!): User! updateUser(user: NewUser!): User! deleteUser(mail: [String!]!): Int! addTutor(tutor: NewUser!, availability: NewUserToEventAvailability!): User! + addStudent(student: NewUser!, application: NewUserToEventApplication!): User! addEvent(event: NewEvent!): Event! updateEvent(id: Int!, event: NewEvent!): Event! deleteEvent(id: [Int!]!): Int! @@ -237,4 +271,6 @@ type Mutation { deleteRoomAvailabilityForEvent(availability: RoomToEventAvailability!): Room! addStudentRegistrationForEvent(registration: UserToEventRegistration!): User! deleteStudentRegistrationForEvent(registration: UserToEventRegistration!): User! + addStudentApplicationForEvent(application: NewUserToEventApplication!): User! + deleteStudentApplicationForEvent(mail: String!, eventID: Int!): User! } diff --git a/server/graph/schema.resolvers.go b/server/graph/schema.resolvers.go index e732a30..02dc3a7 100644 --- a/server/graph/schema.resolvers.go +++ b/server/graph/schema.resolvers.go @@ -25,6 +25,51 @@ func (r *answerResolver) Points(ctx context.Context, obj *models.Answer) (int, e return int(obj.Points), nil } +// Score is the resolver for the score field. +func (r *applicationResolver) Score(ctx context.Context, obj *models.Application) (int, error) { + return int(obj.Score), nil +} + +// Responses is the resolver for the responses field. +func (r *applicationResolver) Responses(ctx context.Context, obj *models.Application) ([]*model.QuestionAnswersPair, error) { + form, err := r.Query().Forms(ctx, []int{int(obj.EventID)}) + if err != nil { + return nil, err + } + + qas := []*model.QuestionAnswersPair{} + + for _, question := range form[0].Questions { + var aqs []*models.ApplicationToQuestion + if err := r.DB.NewSelect(). + Model(&aqs). + Relation("Answer"). + Where(`"aq"."question_id" = ?`, question.ID). + Scan(ctx); err != nil { + return nil, err + } + + avs := []*model.AnswerValuePair{} + for _, answer := range aqs { + av := &model.AnswerValuePair{ + Answer: answer.Answer, + Value: &answer.Value, + } + + avs = append(avs, av) + } + + qa := &model.QuestionAnswersPair{ + Question: question, + Answers: avs, + } + + qas = append(qas, qa) + } + + return qas, nil +} + // TutorsAssigned is the resolver for the tutorsAssigned field. func (r *eventResolver) TutorsAssigned(ctx context.Context, obj *models.Event) ([]*model.EventTutorRoomPair, error) { var eventToTutorRelations []*models.EventToUserAssignment @@ -143,6 +188,20 @@ func (r *mutationResolver) AddTutor(ctx context.Context, tutor models.User, avai return user, nil } +// AddStudent is the resolver for the addStudent field. +func (r *mutationResolver) AddStudent(ctx context.Context, student models.User, application model.NewUserToEventApplication) (*models.User, error) { + if _, err := r.Mutation().AddUser(ctx, student); err != nil { + return nil, err + } + + newUser, err := r.Mutation().AddStudentApplicationForEvent(ctx, application) + if err != nil { + return nil, err + } + + return newUser, nil +} + // AddEvent is the resolver for the addEvent field. func (r *mutationResolver) AddEvent(ctx context.Context, event models.Event) (*models.Event, error) { if _, err := r.DB.NewInsert(). @@ -637,6 +696,88 @@ func (r *mutationResolver) DeleteStudentRegistrationForEvent(ctx context.Context return user[0], nil } +// AddStudentApplicationForEvent is the resolver for the addStudentApplicationForEvent field. +func (r *mutationResolver) AddStudentApplicationForEvent(ctx context.Context, application model.NewUserToEventApplication) (*models.User, error) { + score := 0 + + aqs := []models.ApplicationToQuestion{} + for _, a := range application.Answers { + var points int + + aq := &models.ApplicationToQuestion{ + StudentMail: application.UserMail, + EventID: int32(application.EventID), + QuestionID: int32(a.QuestionID), + } + + if a.AnswerID != nil { + aq.AnswerID = int32(*a.AnswerID) + if err := r.DB.NewSelect(). + Model((*models.Answer)(nil)). + Column("points"). + Where("id = ?", *a.AnswerID). + Scan(ctx, &points); err != nil { + return nil, err + } + } else { + p, err := strconv.Atoi(*a.Value) + if err != nil { + return nil, fmt.Errorf("when no answer id provided, value must be a number") + } + + aq.Value = *a.Value + points = p + } + + aqs = append(aqs, *aq) + + score += points + } + + a := &models.Application{ + EventID: int32(application.EventID), + StudentMail: application.UserMail, + Score: int16(score), + } + + if _, err := r.DB.NewInsert(). + Model(a). + Exec(ctx); err != nil { + return nil, err + } + + if _, err := r.DB.NewInsert(). + Model(&aqs). + Exec(ctx); err != nil { + return nil, err + } + + user, err := r.Query().Users(ctx, []string{application.UserMail}) + if err != nil { + return nil, err + } + + return user[0], nil +} + +// DeleteStudentApplicationForEvent is the resolver for the deleteStudentApplicationForEvent field. +func (r *mutationResolver) DeleteStudentApplicationForEvent(ctx context.Context, mail string, eventID int) (*models.User, error) { + if _, err := r.DB.NewDelete(). + Model((*models.Application)(nil)). + Where("student_mail = ?", mail). + Where("event_id = ?", mail). + Exec(ctx); err != nil { + return nil, err + } + + user, err := r.Query().Users(ctx, []string{mail}) + if err != nil { + return nil, err + } + + return user[0], nil +} + // Events is the resolver for the events field. func (r *queryResolver) Events(ctx context.Context, id []int, umbrellaID []int, label []string, needsTutors *bool, onlyFuture *bool, userMail []string) ([]*models.Event, error) { var events []*models.Event @@ -802,7 +943,8 @@ func (r *queryResolver) Users(ctx context.Context, mail []string) ([]*models.Use Model(&users). Relation("EventsAssigned"). Relation("EventsAvailable"). - Relation("EventsRegistered") + Relation("EventsRegistered"). + Relation("Applications") if mail != nil { query = query.Where("mail IN (?)", bun.In(mail)) @@ -835,6 +977,31 @@ func (r *queryResolver) Forms(ctx context.Context, id []int) ([]*models.Form, er return forms, nil } +// Applications is the resolver for the applications field. +func (r *queryResolver) Applications(ctx context.Context, eventID *int, studentMail []string) ([]*models.Application, error) { + var applications []*models.Application + + query := r.DB.NewSelect(). + Model(&applications). + Relation("Event"). + Relation("Student"). + Relation("Form") + + if eventID != nil { + query = query.Where("event_id = ?", *eventID) + } + + if studentMail != nil { + query = query.Where("student_mail IN (?)", bun.In(studentMail)) + } + + if err := query.Scan(ctx); err != nil { + return nil, err + } + + return applications, nil +} + // Type is the resolver for the type field. func (r *questionResolver) Type(ctx context.Context, obj *models.Question) (model.QuestionType, error) { for _, t := range model.AllQuestionType { @@ -930,6 +1097,9 @@ func (r *newSettingResolver) Type(ctx context.Context, obj *models.Setting, data // Answer returns AnswerResolver implementation. func (r *Resolver) Answer() AnswerResolver { return &answerResolver{r} } +// Application returns ApplicationResolver implementation. +func (r *Resolver) Application() ApplicationResolver { return &applicationResolver{r} } + // Event returns EventResolver implementation. func (r *Resolver) Event() EventResolver { return &eventResolver{r} } @@ -967,6 +1137,7 @@ func (r *Resolver) NewRoom() NewRoomResolver { return &newRoomResolver{r} } func (r *Resolver) NewSetting() NewSettingResolver { return &newSettingResolver{r} } type answerResolver struct{ *Resolver } +type applicationResolver struct{ *Resolver } type eventResolver struct{ *Resolver } type mutationResolver struct{ *Resolver } type queryResolver struct{ *Resolver } diff --git a/server/models/answer.go b/server/models/answer.go index 4286a55..d0a9f83 100644 --- a/server/models/answer.go +++ b/server/models/answer.go @@ -10,9 +10,9 @@ type Answer struct { bun.BaseModel `bun:",alias:a"` ID int32 `bun:",pk,autoincrement"` + QuestionID int32 `bun:",notnull"` Title string `bun:",notnull,type:varchar(255)"` Points int8 `bun:",notnull"` - QuestionID int32 } var _ bun.BeforeCreateTableHook = (*Answer)(nil) diff --git a/server/models/application.go b/server/models/application.go new file mode 100644 index 0000000..1d2504f --- /dev/null +++ b/server/models/application.go @@ -0,0 +1,52 @@ +package models + +import ( + "context" + + "github.com/uptrace/bun" +) + +type Application struct { + bun.BaseModel `bun:",alias:ap"` + + EventID int32 `bun:",pk"` + StudentMail string `bun:",notnull,type:varchar(255)"` + Score int16 `bun:",notnull,default:0"` + Accepted *bool + + Event *Event `bun:"rel:belongs-to,join:event_id=id"` + Student *User `bun:"rel:belongs-to,join:student_mail=mail"` + Form *Form `bun:"rel:belongs-to,join:event_id=event_id"` +} + +var _ bun.BeforeCreateTableHook = (*Application)(nil) + +func (*Application) BeforeCreateTable(ctx context.Context, query *bun.CreateTableQuery) error { + query.ForeignKey(`("event_id") REFERENCES "forms" ("event_id") ON DELETE CASCADE`) + query.ForeignKey(`("student_mail") REFERENCES "users" ("mail") ON DELETE CASCADE`) + return nil +} + +type ApplicationToQuestion struct { + bun.BaseModel `bun:",alias:aq"` + + ID int32 `bun:",pk,autoincrement"` + EventID int32 + StudentMail string + Application *Application `bun:"rel:belongs-to,join:event_id=event_id,join:student_mail=student_mail"` + QuestionID int32 + Question *Question `bun:"rel:belongs-to,join:question_id=id"` + + AnswerID int32 + Answer *Answer `bun:"rel:belongs-to,join:answer_id=id"` + Value string +} + +var _ bun.BeforeCreateTableHook = (*ApplicationToQuestion)(nil) + +func (*ApplicationToQuestion) BeforeCreateTable(ctx context.Context, query *bun.CreateTableQuery) error { + query.ForeignKey(`("event_id") REFERENCES "forms" ("event_id") ON DELETE CASCADE`) + query.ForeignKey(`("student_mail") REFERENCES "users" ("mail") ON DELETE CASCADE`) + query.ForeignKey(`("question_id") REFERENCES "questions" ("id") ON DELETE CASCADE`) + return nil +} diff --git a/server/models/user.go b/server/models/user.go index 10cf031..d9e551b 100644 --- a/server/models/user.go +++ b/server/models/user.go @@ -19,9 +19,10 @@ type User struct { Password string `bun:"type:varchar(64)"` CreatedAt time.Time `bun:",default:current_timestamp"` - EventsAvailable []Event `bun:"m2m:user_to_event_availabilitys,join:User=Event"` - EventsAssigned []Event `bun:"m2m:event_to_user_assignments,join:User=Event"` - EventsRegistered []Event `bun:"m2m:user_to_event_registrations,join:User=Event"` + EventsAvailable []Event `bun:"m2m:user_to_event_availabilitys,join:User=Event"` + EventsAssigned []Event `bun:"m2m:event_to_user_assignments,join:User=Event"` + EventsRegistered []Event `bun:"m2m:user_to_event_registrations,join:User=Event"` + Applications []*Application `bun:"rel:has-many,join:mail=student_mail"` } type UserToEventAvailability struct {