Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DOJO exercise submissions to the backend #2370

Merged
merged 12 commits into from
Sep 30, 2022
Merged

Add DOJO exercise submissions to the backend #2370

merged 12 commits into from
Sep 30, 2022

Conversation

bryanjenningz
Copy link
Collaborator

@bryanjenningz bryanjenningz commented Sep 29, 2022

Changes:

  • Adds ability to get and mutate DOJO exercise submissions using GraphQL
  • Frontend now gets DOJO exercise submissions from the backend (but it doesn't mutate them on the backend yet, this will be handled in a subsequent pull request)

How to test:

  • Create a DOJO module at /admin/lessons/js0/modules or by using GraphQL mutations
  • Create DOJO exercises at /curriculum/js0/mentor or by using GraphQL mutations
  • Create a exercise submissions by using GraphQL mutations
  • Go to the DOJO exercises page at /exercises/js0 and check that the correct exercises are marked as "NOT ANSWERED" or "ANSWERED" depending on how you mutated the exercise submission data
  • Notice that if you answer a DOJO exercise at /exercises/js0, it will be marked as "ANSWERED" when you go to the exercise list view, but if you refresh the page, the state will go back to how it was because this pull request doesn't mutate the exercise submissions.

Here are some useful GraphQL queries and mutations for testing (you can run these at /api/graphql):

Add a new module

mutation AddModule(
  $lessonId: Int!
  $name: String!
  $content: String!
  $order: Int!
) {
  addModule(
    lessonId: $lessonId
    name: $name
    content: $content
    order: $order
  ) {
    id
  }
}
{
  "lessonId": 1,
  "name": "Numbers",
  "content": "We will learn how to use numbers in this lesson.",
  "order": 1
}

Add a new exercise to a module

mutation AddExercise(
  $moduleId: Int!
  $description: String!
  $answer: String!
  $explanation: String
) {
  addExercise(
    moduleId: $moduleId
    description: $description
    answer: $answer
    explanation: $explanation
  ) {
    id
  }
}
{
  "moduleId": 1,
  "description": "```\nlet a = 1\na += 2\n// What is a?\n```",
  "answer": "3",
  "explanation": "`a += 2` is shorthand for `a = a + 2`"
}

Add an exercise submission to an exercise

mutation AddExerciseSubmission($exerciseId: Int!, $userAnswer: String!) {
  addExerciseSubmission(exerciseId: $exerciseId, userAnswer: $userAnswer) {
    id
    exerciseId
    userId
    userAnswer
  }
}
{
  "exerciseId": 1,
  "userAnswer": "3"
}

Here is the query that gets run when you go to /exercises/js0

query GetExercises {
  lessons {
    title
    docUrl
    slug
  }
  alerts {
    id
    text
    type
    url
    urlCaption
  }
  exercises {
    id
    module {
      name
      lesson {
        slug
      }
    }
    description
    answer
    explanation
  }
  exerciseSubmissions {
    exerciseId
    userAnswer
  }
}

This pull request is a part of #2251 and #2253

@vercel
Copy link

vercel bot commented Sep 29, 2022

@bryanjenningz is attempting to deploy a commit to the c0d3-prod Team on Vercel.

A member of the Team first needs to authorize it.

@codecov
Copy link

codecov bot commented Sep 29, 2022

Codecov Report

❗ No coverage uploaded for pull request base (master@779e79e). Click here to learn what that means.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             master     #2370   +/-   ##
==========================================
  Coverage          ?   100.00%           
==========================================
  Files             ?       183           
  Lines             ?      3208           
  Branches          ?       848           
==========================================
  Hits              ?      3208           
  Misses            ?         0           
  Partials          ?         0           
Impacted Files Coverage Δ
__dummy__/getExercisesData.ts 100.00% <ø> (ø)
graphql/resolvers/exerciseSubmissionCrud.ts 100.00% <100.00%> (ø)
pages/exercises/[lessonSlug].tsx 100.00% <100.00%> (ø)

@vercel
Copy link

vercel bot commented Sep 29, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
c0d3-app ✅ Ready (Inspect) Visit Preview Sep 30, 2022 at 3:21AM (UTC)

@vercel
Copy link

vercel bot commented Sep 29, 2022

Deployment failed with the following error:

Invalid request: `target` should be string.

Copy link
Member

@flacial flacial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @updatedAt @db.Timestamptz(6)
id Int @id @default(autoincrement())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What caused the change in formatting? The IDE?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran yarn prisma format and yarn prisma migrate dev


@@map("exercises")
}

model ExerciseSubmission {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some benefits for submittedAt. But it's one of the things that is more suitable to be added once needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree, we can add fields when we need them

@bryanjenningz bryanjenningz merged commit 498f5f0 into garageScript:master Sep 30, 2022
@bryanjenningz bryanjenningz deleted the dojo-exercise-submissions branch September 30, 2022 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants