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

CP3108 Staff Dashboard - Backend Modifications for Playground Default Source Version Selector #585

Merged
merged 6 commits into from
May 19, 2020

Conversation

chrystalquek
Copy link
Contributor

@chrystalquek chrystalquek commented Apr 15, 2020

Context

This PR is for modifying the backend API to support the Playground Default Source Version Selector for the CP3018 Staff Dashboard project.

The Playground Default Source Version Selector is meant to allow staff to easily change the default source version for the playground.

Implementation

Added a new table, 'Chapter'. The table contains a single entry with the current default source version. Added GET and UPDATE routes.

Other Information

Corresponding PR to cadet: source-academy/frontend#1073

@sun-yitao
Copy link

I'm running into some issues setting up and running locally with this branch:
Upon running mix ecto.setup:

Compiling 112 files (.ex)
warning: unused alias Chapters
  lib/cadet/chapters/chapter.ex:8

warning: variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/cadet_web/controllers/chapters_controller.ex:21

Generated cadet app
The database for Cadet.Repo has already been created

13:26:59.306 [info]  Already up
[info] [Que] Booting Que
[info] [Que] Booting Server Supervisor for Workers
[info] [swarm on nonode@nohost] [tracker:init] started
warning: variable "admin" is unused (if the variable is not meant to be used, prefix it with an underscore)
  priv/repo/seeds.exs:24

[debug] QUERY OK db=1.1ms queue=0.8ms
INSERT INTO "chapters" ("chapterno") VALUES ($1) RETURNING "id" [1]
[debug] QUERY ERROR db=1.7ms queue=1.1ms
INSERT INTO "users" ("name","nusnet_id","role","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5) RETURNING "id" ["avenger", "E0000000", "staff", ~N[2020-04-20 05:27:00], ~N[2020-04-20 05:27:00]]
** (Ecto.ConstraintError) constraint error when attempting to insert struct:

    * users_nusnet_id_index (unique_constraint)

If you would like to stop this constraint violation from raising an
exception and instead add it as an error to your changeset, please
call `unique_constraint/3` on your changeset with the constraint
`:name` as an option.

The changeset has not defined any constraint.

    (ecto) lib/ecto/repo/schema.ex:687: anonymous fn/4 in Ecto.Repo.Schema.constraints_to_errors/3
    (elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2
    (ecto) lib/ecto/repo/schema.ex:672: Ecto.Repo.Schema.constraints_to_errors/3
    (ecto) lib/ecto/repo/schema.ex:274: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
    (ecto) lib/ecto/repo/schema.ex:164: Ecto.Repo.Schema.insert!/4
    priv/repo/seeds.exs:20: (file)
    (elixir) lib/code.ex:767: Code.require_file/2
    (mix) lib/mix/tasks/run.ex:147: Mix.Tasks.Run.run/5
    (mix) lib/mix/tasks/run.ex:86: Mix.Tasks.Run.run/1
    (mix) lib/mix/task.ex:331: Mix.Task.run_task/3
    (mix) lib/mix/task.ex:365: Mix.Task.run_alias/3
    (mix) lib/mix/task.ex:292: Mix.Task.run/2
    (mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2

The errror seems to be complaining that the users_nusnet_id_index is no longer unique upon reinserting the default groups of users in priv/repo/seeds.exs. I've tried dropping the database and rerunning ecto.setup which will not produce this error but it does not seem to affect the next error I hit when attempting to switch the chapter in the frontend:

Screenshot 2020-04-20 at 2 07 24 PM

Switching to any of the 4 chapters produces this error:

Screenshot 2020-04-20 at 2 07 44 PM

Here is what I am getting on the backend:

[info] POST /v1/chapter/update/1
[debug] Processing with CadetWeb.ChaptersController.update/2
  Parameters: %{"chapterno" => 4, "id" => "1"}
  Pipelines: [:api, :auth, :ensure_auth]
[debug] QUERY OK source="users" db=0.3ms
SELECT u0."id", u0."name", u0."role", u0."nusnet_id", u0."group_id", u0."inserted_at", u0."updated_at" FROM "users" AS u0 WHERE (u0."id" = $1) [10]
[debug] QUERY OK source="chapters" db=0.2ms
SELECT c0."id", c0."chapterno" FROM "chapters" AS c0 []
[info] Sent 500 in 13ms
[error] #PID<0.818.0> running CadetWeb.Endpoint (connection #PID<0.817.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /v1/chapter/update/1
** (exit) an exception was raised:
    ** (Ecto.MultipleResultsError) expected at most one result but got 2 in query:

from c0 in Cadet.Chapters.Chapter

        (ecto) lib/ecto/repo/queryable.ex:70: Ecto.Repo.Queryable.one/3
        (cadet) lib/cadet/chapters/chapters.ex:15: Cadet.Chapters.update_chapter/1
        (cadet) lib/cadet_web/controllers/chapters_controller.ex:22: CadetWeb.ChaptersController.update/2
        (cadet) lib/cadet_web/controllers/chapters_controller.ex:1: CadetWeb.ChaptersController.action/2
        (cadet) lib/cadet_web/controllers/chapters_controller.ex:1: CadetWeb.ChaptersController.phoenix_controller_pipeline/2
        (phoenix) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2
        (cadet) lib/plug/error_handler.ex:64: CadetWeb.Router.call/2
        (cadet) lib/cadet_web/endpoint.ex:1: CadetWeb.Endpoint.plug_builder_call/2
        (cadet) lib/plug/debugger.ex:122: CadetWeb.Endpoint."call (overridable 3)"/2
        (cadet) lib/cadet_web/endpoint.ex:1: CadetWeb.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy) /Users/sunyitao/Documents/School/Semesters/Y1S2/CP3108/SourceAcademy/cadet/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
        (cowboy) /Users/sunyitao/Documents/School/Semesters/Y1S2/CP3108/SourceAcademy/cadet/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3
        (cowboy) /Users/sunyitao/Documents/School/Semesters/Y1S2/CP3108/SourceAcademy/cadet/deps/cowboy/src/cowboy_stream_h.erl:302: :cowboy_stream_h.request_process/3
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

@coveralls
Copy link

Pull Request Test Coverage Report for Build 2900

  • 14 of 14 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 91.723%

Totals Coverage Status
Change from base Build 2898: 0.1%
Covered Lines: 1086
Relevant Lines: 1184

💛 - Coveralls

@angelsl angelsl merged commit fed439d into source-academy:sa_2021 May 19, 2020
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.

4 participants