Update queries and mutations with some more fields

This commit is contained in:
Ramon Wenger 2024-07-10 17:55:13 +02:00 committed by Christian Cueni
parent ce46f14c4c
commit 829f724ca9
6 changed files with 127 additions and 83 deletions

View File

@ -267,6 +267,7 @@ type CourseObjectType {
learning_path: LearningPathObjectType! learning_path: LearningPathObjectType!
action_competences: [ActionCompetenceObjectType!]! action_competences: [ActionCompetenceObjectType!]!
profiles: [String] profiles: [String]
course_session_users: [CourseSessionUserType]!
} }
type ActionCompetenceObjectType implements CoursePageInterface { type ActionCompetenceObjectType implements CoursePageInterface {
@ -332,46 +333,38 @@ type CircleLightObjectType {
slug: String! slug: String!
} }
type TopicObjectType implements CoursePageInterface { type CourseSessionUserType {
is_visible: Boolean! id: UUID!
id: ID! chosen_profile: String
title: String! course_session: CourseSessionObjectType!
slug: String!
content_type: String!
live: Boolean!
translation_key: String!
frontend_url: String!
course: CourseObjectType
circles: [CircleObjectType!]!
} }
type CircleObjectType implements CoursePageInterface { """
description: String! Leverages the internal Python implementation of UUID (uuid.UUID) to provide native UUID objects
goals: String! in fields, resolvers and input.
"""
scalar UUID
type CourseSessionObjectType {
id: ID! id: ID!
created_at: DateTime!
updated_at: DateTime!
course: CourseObjectType!
title: String! title: String!
slug: String! start_date: Date
content_type: String! end_date: Date
live: Boolean! attendance_courses: [CourseSessionAttendanceCourseObjectType!]!
translation_key: String! assignments: [CourseSessionAssignmentObjectType!]!
frontend_url: String! edoniq_tests: [CourseSessionEdoniqTestObjectType!]!
course: CourseObjectType users: [CourseSessionUserObjectsType!]!
learning_sequences: [LearningSequenceObjectType!]!
profiles: [String]!
} }
type LearningSequenceObjectType implements CoursePageInterface { """
icon: String! The `Date` scalar type represents a Date
id: ID! value as specified by
title: String! [iso8601](https://en.wikipedia.org/wiki/ISO_8601).
slug: String! """
content_type: String! scalar Date
live: Boolean!
translation_key: String!
frontend_url: String!
course: CourseObjectType
learning_units: [LearningUnitObjectType!]!
}
type CourseSessionAttendanceCourseObjectType { type CourseSessionAttendanceCourseObjectType {
id: ID! id: ID!
@ -433,26 +426,19 @@ type DueDateObjectType {
course_session: CourseSessionObjectType! course_session: CourseSessionObjectType!
} }
type CourseSessionObjectType { type AttendanceUserObjectType {
id: ID! user_id: UUID!
created_at: DateTime! status: AttendanceUserStatus!
updated_at: DateTime! first_name: String
course: CourseObjectType! last_name: String
title: String! email: String
start_date: Date
end_date: Date
attendance_courses: [CourseSessionAttendanceCourseObjectType!]!
assignments: [CourseSessionAssignmentObjectType!]!
edoniq_tests: [CourseSessionEdoniqTestObjectType!]!
users: [CourseSessionUserObjectsType!]!
} }
""" """An enumeration."""
The `Date` scalar type represents a Date enum AttendanceUserStatus {
value as specified by PRESENT
[iso8601](https://en.wikipedia.org/wiki/ISO_8601). ABSENT
""" }
scalar Date
type CourseSessionAssignmentObjectType { type CourseSessionAssignmentObjectType {
id: ID! id: ID!
@ -580,12 +566,6 @@ type AssignmentCompletionObjectType {
evaluation_max_points: Float evaluation_max_points: Float
} }
"""
Leverages the internal Python implementation of UUID (uuid.UUID) to provide native UUID objects
in fields, resolvers and input.
"""
scalar UUID
type UserObjectType { type UserObjectType {
""" """
Erforderlich. 150 Zeichen oder weniger. Nur Buchstaben, Ziffern und @/./+/-/_. Erforderlich. 150 Zeichen oder weniger. Nur Buchstaben, Ziffern und @/./+/-/_.
@ -724,18 +704,45 @@ type CourseSessionUserExpertCircleType {
slug: String! slug: String!
} }
type AttendanceUserObjectType { type TopicObjectType implements CoursePageInterface {
user_id: UUID! is_visible: Boolean!
status: AttendanceUserStatus! id: ID!
first_name: String title: String!
last_name: String slug: String!
email: String content_type: String!
live: Boolean!
translation_key: String!
frontend_url: String!
course: CourseObjectType
circles: [CircleObjectType!]!
} }
"""An enumeration.""" type CircleObjectType implements CoursePageInterface {
enum AttendanceUserStatus { description: String!
PRESENT goals: String!
ABSENT id: ID!
title: String!
slug: String!
content_type: String!
live: Boolean!
translation_key: String!
frontend_url: String!
course: CourseObjectType
learning_sequences: [LearningSequenceObjectType!]!
profiles: [String]!
}
type LearningSequenceObjectType implements CoursePageInterface {
icon: String!
id: ID!
title: String!
slug: String!
content_type: String!
live: Boolean!
translation_key: String!
frontend_url: String!
course: CourseObjectType
learning_units: [LearningUnitObjectType!]!
} }
type LearningContentMediaLibraryObjectType implements CoursePageInterface & LearningContentInterface { type LearningContentMediaLibraryObjectType implements CoursePageInterface & LearningContentInterface {
@ -934,16 +941,16 @@ type CourseSessionProfileMutationPayload {
clientMutationId: String clientMutationId: String
} }
union UpdateCourseProfileResult = UpdateCourseProfileSuccess | UpdateCourseProfileError union UpdateCourseProfileResult = UpdateCourseProfileError | UpdateCourseProfileSuccess
type UpdateCourseProfileSuccess {
message: String
}
type UpdateCourseProfileError { type UpdateCourseProfileError {
message: String message: String
} }
type UpdateCourseProfileSuccess {
user: CourseSessionUserType!
}
input CourseSessionProfileMutationInput { input CourseSessionProfileMutationInput {
course_profile: String! course_profile: String!
course_slug: String! course_slug: String!

View File

@ -38,6 +38,7 @@ export const CourseSessionProfileMutationInput = "CourseSessionProfileMutationIn
export const CourseSessionProfileMutationPayload = "CourseSessionProfileMutationPayload"; export const CourseSessionProfileMutationPayload = "CourseSessionProfileMutationPayload";
export const CourseSessionUserExpertCircleType = "CourseSessionUserExpertCircleType"; export const CourseSessionUserExpertCircleType = "CourseSessionUserExpertCircleType";
export const CourseSessionUserObjectsType = "CourseSessionUserObjectsType"; export const CourseSessionUserObjectsType = "CourseSessionUserObjectsType";
export const CourseSessionUserType = "CourseSessionUserType";
export const CourseStatisticsType = "CourseStatisticsType"; export const CourseStatisticsType = "CourseStatisticsType";
export const DashboardConfigType = "DashboardConfigType"; export const DashboardConfigType = "DashboardConfigType";
export const DashboardType = "DashboardType"; export const DashboardType = "DashboardType";

View File

@ -66,7 +66,10 @@ export const UPDATE_COURSE_PROFILE_MUTATION = graphql(`
result { result {
__typename __typename
... on UpdateCourseProfileSuccess { ... on UpdateCourseProfileSuccess {
message user {
id
chosen_profile
}
} }
... on UpdateCourseProfileError { ... on UpdateCourseProfileError {
message message

View File

@ -271,6 +271,14 @@ export const COURSE_QUERY = graphql(`
slug slug
category_name category_name
profiles profiles
course_session_users {
id
__typename
chosen_profile
course_session {
id
}
}
configuration { configuration {
id id
enable_circle_documents enable_circle_documents

View File

@ -107,6 +107,9 @@ class CourseObjectType(DjangoObjectType):
) )
configuration = graphene.Field(CourseConfigurationObjectType, required=True) configuration = graphene.Field(CourseConfigurationObjectType, required=True)
profiles = graphene.List(graphene.String) profiles = graphene.List(graphene.String)
course_session_users = graphene.List(
"course.graphql.types.CourseSessionUserType", required=True
)
class Meta: class Meta:
model = Course model = Course
@ -130,6 +133,12 @@ class CourseObjectType(DjangoObjectType):
def resolve_profiles(root: Course, info, **kwargs): def resolve_profiles(root: Course, info, **kwargs):
return CourseProfile.objects.all().values_list("code", flat=True) return CourseProfile.objects.all().values_list("code", flat=True)
@staticmethod
def resolve_course_session_users(root: Course, info, **kwargs):
user = info.context.user
users = CourseSessionUser.objects.filter(user=user, course_session__course=root)
return users
class CourseSessionUserExpertCircleType(ObjectType): class CourseSessionUserExpertCircleType(ObjectType):
id = graphene.ID(required=True) id = graphene.ID(required=True)
@ -137,6 +146,21 @@ class CourseSessionUserExpertCircleType(ObjectType):
slug = graphene.String(required=True) slug = graphene.String(required=True)
class CourseSessionUserType(DjangoObjectType):
chosen_profile = graphene.String()
course_session = graphene.Field(
"course.graphql.types.CourseSessionObjectType", required=True
)
class Meta:
model = CourseSessionUser
fields = ["chosen_profile", "id"]
@staticmethod
def resolve_chosen_profile(root: CourseSessionUser, info, **kwargs):
return root.chosen_profile.code
class CourseSessionUserObjectsType(ObjectType): class CourseSessionUserObjectsType(ObjectType):
""" """
WORKAROUND: WORKAROUND:

View File

@ -3,6 +3,7 @@ import structlog
from graphene import relay from graphene import relay
from rest_framework.exceptions import PermissionDenied from rest_framework.exceptions import PermissionDenied
from vbv_lernwelt.course.graphql.types import CourseSessionUserType
from vbv_lernwelt.course.models import CourseSessionUser from vbv_lernwelt.course.models import CourseSessionUser
from vbv_lernwelt.course_session.graphql.types import ( from vbv_lernwelt.course_session.graphql.types import (
CourseSessionAttendanceCourseObjectType, CourseSessionAttendanceCourseObjectType,
@ -19,10 +20,7 @@ logger = structlog.get_logger(__name__)
class UpdateCourseProfileSuccess(graphene.ObjectType): class UpdateCourseProfileSuccess(graphene.ObjectType):
message = graphene.String() user = graphene.Field(CourseSessionUserType(), required=True)
def resolve_message(cls, instance, **kwargs):
return "Update successful"
class UpdateCourseProfileError(graphene.ObjectType): class UpdateCourseProfileError(graphene.ObjectType):
@ -31,13 +29,16 @@ class UpdateCourseProfileError(graphene.ObjectType):
class UpdateCourseProfileResult(graphene.Union): class UpdateCourseProfileResult(graphene.Union):
class Meta: class Meta:
types = (UpdateCourseProfileSuccess, UpdateCourseProfileError) types = (
UpdateCourseProfileError,
UpdateCourseProfileSuccess,
)
@classmethod @classmethod
def resolve_type(cls, instance, info): def resolve_type(cls, instance, info):
if type(instance).__name__ == "UpdateCourseProfileError": if type(instance).__name__ == "UpdateCourseProfileSuccess":
return UpdateCourseProfileError return UpdateCourseProfileSuccess
return UpdateCourseProfileSuccess return UpdateCourseProfileError
class AttendanceUserInputType(graphene.InputObjectType): class AttendanceUserInputType(graphene.InputObjectType):
@ -104,7 +105,7 @@ class CourseSessionProfileMutation(relay.ClientIDMutation):
csu.chosen_profile = profile csu.chosen_profile = profile
csu.save() csu.save()
print(user) print(user)
return cls(result=True) return cls(result=UpdateCourseProfileSuccess(user=csu))
except CourseProfile.DoesNotExist: except CourseProfile.DoesNotExist:
return cls(result=UpdateCourseProfileError("Course Profile does not exist")) return cls(result=UpdateCourseProfileError("Course Profile does not exist"))
except CourseSessionUser.DoesNotExist: except CourseSessionUser.DoesNotExist: