Skip to content

Commit

Permalink
Run mix format
Browse files Browse the repository at this point in the history
  • Loading branch information
CheongYeeMing committed Jan 20, 2024
1 parent 4219869 commit 4fb8b25
Show file tree
Hide file tree
Showing 28 changed files with 232 additions and 232 deletions.
2 changes: 1 addition & 1 deletion lib/cadet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Cadet do
@moduledoc """
Cadet keeps the contexts that define your domain
and business logic.
Contexts are also responsible for managing your data, regardless
if it comes from the database, an external API or others.
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/accounts/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Cadet.Accounts do

@doc """
Register new User entity using Cadet.Accounts.Form.Registration
Returns {:ok, user} on success, otherwise {:error, changeset}
"""
def register(attrs = %{username: username, provider: _provider}) when is_binary(username) do
Expand Down
92 changes: 46 additions & 46 deletions lib/cadet/accounts/teams.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ defmodule Cadet.Accounts.Teams do

@doc """
Creates a new team and assigns an assessment and team members to it.
## Parameters
* `attrs` - A map containing the attributes for assessment id and creating the team and its members.
## Returns
Returns a tuple `{:ok, team}` on success; otherwise, an error tuple.
"""
def create_team(attrs) do
assessment_id = attrs["assessment_id"]
Expand Down Expand Up @@ -69,16 +69,16 @@ defmodule Cadet.Accounts.Teams do

@doc """
Validates whether there are student(s) who are already assigned to another group.
## Parameters
* `team_attrs` - A list of all the teams and their members.
* `assessment_id` - Id of the target assessment.
## Returns
Returns `true` on success; otherwise, `false`.
"""
defp student_already_assigned?(team_attrs, assessment_id) do
Enum.all?(team_attrs, fn team ->
Expand All @@ -93,15 +93,15 @@ defmodule Cadet.Accounts.Teams do

@doc """
Checks there is no duplicated student during team creation.
## Parameters
* `team_attrs` - IDs of the team members being created
## Returns
Returns `true` if all students in the list are distinct; otherwise, returns `false`.
"""
defp all_students_distinct?(team_attrs) do
all_ids =
Expand All @@ -118,16 +118,16 @@ defmodule Cadet.Accounts.Teams do

@doc """
Checks if all the teams satisfy the max team size constraint.
## Parameters
* `teams` - IDs of the team members being created
* `max_team_size` - max team size of the team
## Returns
Returns `true` if all the teams have size less or equal to the max team size; otherwise, returns `false`.
"""
defp all_team_within_max_size?(teams, max_team_size) do
Enum.all?(teams, fn team ->
Expand All @@ -138,16 +138,16 @@ defmodule Cadet.Accounts.Teams do

@doc """
Checks if one or more students are enrolled in the course.
## Parameters
* `teams` - ID of the team being created
* `course_id` - ID of the course
## Returns
Returns `true` if all students in the list enroll in the course; otherwise, returns `false`.
"""
defp all_student_enrolled_in_course?(teams, course_id) do
all_ids =
Expand All @@ -168,17 +168,17 @@ defmodule Cadet.Accounts.Teams do

@doc """
Checks if one or more students are already in another team for the same assessment.
## Parameters
* `team_id` - ID of the team being updated (use -1 for team creation)
* `student_ids` - List of student IDs
* `assessment_id` - ID of the assessment
## Returns
Returns `true` if any student in the list is already a member of another team for the same assessment; otherwise, returns `false`.
"""
defp student_already_in_team?(team_id, student_ids, assessment_id) do
query =
Expand All @@ -196,17 +196,17 @@ defmodule Cadet.Accounts.Teams do

@doc """
Updates an existing team, the corresponding assessment, and its members.
## Parameters
* `team` - The existing team to be updated
* `new_assessment_id` - The ID of the updated assessment
* `student_ids` - List of student ids for team members
## Returns
Returns a tuple `{:ok, updated_team}` on success, containing the updated team details; otherwise, an error tuple.
"""
def update_team(team = %Team{}, new_assessment_id, student_ids) do
old_assessment_id = team.assessment_id
Expand Down Expand Up @@ -235,13 +235,13 @@ defmodule Cadet.Accounts.Teams do

@doc """
Updates team members based on the new list of student IDs.
## Parameters
* `team` - The team being updated
* `student_ids` - List of student ids for team members
* `team_id` - ID of the team
"""
defp update_team_members(team, student_ids, team_id) do
current_student_ids = team.team_members |> Enum.map(& &1.student_id)
Expand Down Expand Up @@ -269,11 +269,11 @@ defmodule Cadet.Accounts.Teams do

@doc """
Deletes a team along with its associated submissions and answers.
## Parameters
* `team` - The team to be deleted
"""
def delete_team(team = %Team{}) do
if has_submitted_answer?(team.id) do
Expand Down Expand Up @@ -306,15 +306,15 @@ defmodule Cadet.Accounts.Teams do

@doc """
Check whether a team has subnitted submissions and answers.
## Parameters
* `team_id` - The team id of the team to be checked
## Returns
Returns `true` if any one of the submission has the status of "submitted", `false` otherwise
"""
defp has_submitted_answer?(team_id) do
submission =
Expand Down
10 changes: 5 additions & 5 deletions lib/cadet/assessments/assessments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -799,10 +799,10 @@ defmodule Cadet.Assessments do
Public internal api to submit new answers for a question. Possible return values are:
`{:ok, nil}` -> success
`{:error, error}` -> failed. `error` is in the format of `{http_response_code, error message}`
Note: In the event of `find_or_create_submission` failing due to a race condition, error will be:
`{:bad_request, "Missing or invalid parameter(s)"}`
"""
def answer_question(
question = %Question{},
Expand Down Expand Up @@ -1198,7 +1198,7 @@ defmodule Cadet.Assessments do

@doc """
Fetches top answers for the given question, based on the contest relative_score
Used for contest leaderboard fetching
"""
def fetch_top_relative_score_answers(question_id, number_of_answers) do
Expand Down Expand Up @@ -1363,11 +1363,11 @@ defmodule Cadet.Assessments do
fields that are exposed in the /grading endpoint. The reason we select only
those fields is to reduce the memory usage especially when the number of
submissions is large i.e. > 25000 submissions.
The input parameters are the user and group_only. group_only is used to check
whether only the groups under the grader should be returned. The parameter is
a boolean which is false by default.
The return value is {:ok, submissions} if no errors, else it is {:error,
{:unauthorized, "Forbidden."}}
"""
Expand Down
6 changes: 3 additions & 3 deletions lib/cadet/auth/providers/config.ex
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule Cadet.Auth.Providers.Config do
@moduledoc """
Provides identity using configuration.
The configuration should be a list of users in the following format:
```
[%{code: "code1", token: "token1", username: "Username", name: "Name", role: :student}]
```
This is mainly meant for test and development use.
"""

Expand Down
4 changes: 2 additions & 2 deletions lib/cadet/courses/courses.ex
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ defmodule Cadet.Courses do

@doc """
Upload a sourcecast file.
Note that there are no checks for whether the user belongs to the course,
as this has been checked inside a plug in the router.
"""
Expand Down Expand Up @@ -384,7 +384,7 @@ defmodule Cadet.Courses do

@doc """
Delete a sourcecast file
Note that there are no checks for whether the user belongs to the course, as this has been checked
inside a plug in the router.
"""
Expand Down
6 changes: 3 additions & 3 deletions lib/cadet/helpers/model_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ defmodule Cadet.ModelHelper do

@doc """
Given a changeset for a model that has some `belongs_to` associations, this function will attach multiple ids to the changeset if the models are provided in the parameters.
example:
```
defmodule MyTest do
schema "my_test" do
belongs_to(:bossman, User)
belongs_to(:item, Box)
end
def changeset(my_test, params) do
# params = %{bossman: %User{}, item: %Box{}}
my_test
|> cast(params, [])
|> add_belongs_to_id_from_model([:bossman, :item], params)
Expand Down
8 changes: 4 additions & 4 deletions lib/cadet/helpers/shared_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Cadet.SharedHelper do

@doc """
Snake-casifies string keys.
Meant for use when accepting a JSON map from the frontend, where keys are
usually camel-case.
"""
Expand All @@ -40,7 +40,7 @@ defmodule Cadet.SharedHelper do

@doc """
Snake-casifies string keys, recursively.
Meant for use when accepting a JSON map from the frontend, where keys are
usually camel-case.
"""
Expand All @@ -60,7 +60,7 @@ defmodule Cadet.SharedHelper do

@doc """
Camel-casifies atom keys and converts them to strings.
Meant for use when sending an Elixir map, which usually has snake-case keys,
to the frontend.
"""
Expand All @@ -73,7 +73,7 @@ defmodule Cadet.SharedHelper do
@doc """
Converts a map like `%{"a" => 123}` into a keyword list like [a: 123]. Returns
nil if any keys are not existing atoms.
Meant for use for GET endpoints that filter based on the query string.
"""
def try_keywordise_string_keys(map) do
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/incentives/achievements.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Cadet.Incentives.Achievements do

@doc """
Returns all achievements.
This returns Achievement structs with prerequisites and goal association maps pre-loaded.
"""
@spec get(integer()) :: [Achievement.t()]
Expand Down
4 changes: 2 additions & 2 deletions lib/cadet/jobs/autograder/grading_job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ defmodule Cadet.Autograder.GradingJob do
Exposed as public function in case future mix tasks are needed to regrade
certain submissions. Manual grading can also be triggered from iex with this
function.
Takes in submission to be graded. Submission will be graded regardless of its
assessment's close_by date or submission status.
Every answer will be regraded regardless of its current autograding status.
"""
def force_grade_individual_submission(submission = %Submission{}, overwrite \\ false) do
Expand Down
Loading

0 comments on commit 4fb8b25

Please sign in to comment.