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

E2442 Reimplement student task controller - backend #102

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
69ea146
Added instructions for creating test objects in SQL server and starti…
Mar 5, 2024
1b87238
add student_task model and its tests
Apr 14, 2024
7c8348d
improve student_task test
Apr 14, 2024
ea65e67
Merge pull request #21 from ychen-207523/ychen267_student_task_model
david12white Apr 15, 2024
19d0777
Re-scaffolded student task controller, generated db migrations, imple…
Apr 15, 2024
6dd75ee
Merge remote-tracking branch 'origin/main' into dev_henry
Apr 15, 2024
1b916f5
Merge remote-tracking branch 'origin/controller_list_function' into d…
Apr 15, 2024
ddf507a
Reverted creation of student task table
Apr 15, 2024
90acd0d
Merge remote-tracking branch 'origin/controller_list_function' into d…
Apr 15, 2024
74a92e1
Un-commented seed file to properly seed database
Apr 15, 2024
ccba042
Added view function in student_tasks_controller.rb and cleaned up the…
Apr 15, 2024
bd95de4
Updated view function
Apr 16, 2024
39597bb
Merge pull request #25 from ychen-207523/dev_henry
ychen-207523 Apr 16, 2024
27876bc
Merge pull request #26 from ychen-207523/controller_list_function
ychen-207523 Apr 16, 2024
0f50030
add course seed
Apr 18, 2024
7011080
Added permission granted flag to participants
Apr 18, 2024
52f2f3a
Removed comments and simplified code for student task controller and …
Apr 18, 2024
5dd6ee1
Added permission granted to student task model rspec test, reformatte…
Apr 18, 2024
aa17d55
Got initial authenticated/unauthenticated rspec tests working for stu…
Apr 18, 2024
57a6ad1
add course to seeds.rb
Apr 19, 2024
2b40822
Merge branch 'main' into controller_list_function
david12white Apr 19, 2024
08a5dc1
Removed set student method throwing errors
Apr 19, 2024
4fddda1
Merge pull request #28 from ychen-207523/controller_list_function
david12white Apr 19, 2024
ef71394
Added view function route for student_task_controller
Apr 19, 2024
b73927d
add Student_task list in SwaggerUI
Apr 20, 2024
a405176
Bolstered test suite for controller list function and improved readab…
Apr 20, 2024
8bc9443
Merge pull request #29 from ychen-207523/enhance_tests
ychen-207523 Apr 21, 2024
0d29046
add swaggerUI
Apr 21, 2024
9032f2d
update student_task model
Apr 21, 2024
194eefb
add view function
Apr 22, 2024
493caf6
delete view in SwaggerUI as it is out of scope
Apr 22, 2024
3ecb010
Merge pull request #31 from ychen-207523/ychen267_SwaggerUI
ychen-207523 Apr 22, 2024
fc82ebd
Merge pull request #32 from ychen-207523/ychen267_dev
ychen-207523 Apr 22, 2024
8a0e1e7
add commits to student_task.rb
Apr 22, 2024
0e80b3f
Added comments for student task controller
Apr 23, 2024
01c12f6
add SwaggerUI view
Apr 23, 2024
62b612f
Merge branch 'main' of github.com:ychen-207523/reimplementation-back-end
Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-3.2.1
3.2.1
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ GEM
nio4r (2.5.9)
nokogiri (1.15.2-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.2-x64-mingw-ucrt)
racc (~> 1.4)
nokogiri (1.15.2-x86_64-linux)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
Expand Down Expand Up @@ -241,7 +245,9 @@ GEM

PLATFORMS
aarch64-linux
arm64-darwin-22
x64-mingw-ucrt
x86_64-linux

DEPENDENCIES
bcrypt (~> 3.1.7)
Expand Down
25 changes: 25 additions & 0 deletions app/controllers/api/v1/student_tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Api::V1::StudentTasksController < ApplicationController

# List retrieves all student tasks associated with the current logged-in user.
def list
# Retrieves all tasks that belong to the current user.
@student_tasks = StudentTask.from_user(current_user)
# Render the list of student tasks as JSON.
render json: @student_tasks
end

def show
render json: @student_task
end

# The view function retrieves a student task based on a participant's ID.
# It is meant to provide an endpoint where tasks can be queried based on participant ID.
def view
# Retrieves the student task where the participant's ID matches the provided parameter.
# This function will be used for clicking on a specific student task to "view" its details.
@student_task = StudentTask.from_participant_id(params[:id])
# Render the found student task as JSON.
render json: @student_task
end

end
48 changes: 48 additions & 0 deletions app/models/student_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class StudentTask
attr_accessor :assignment, :current_stage, :participant, :stage_deadline, :topic, :permission_granted

# Initializes a new instance of the StudentTask class
def initialize(args)
@assignment = args[:assignment]
@current_stage = args[:current_stage]
@participant = args[:participant]
@stage_deadline = args[:stage_deadline]
@topic = args[:topic]
@permission_granted = args[:permission_granted]
end

# create a new StudentTask instance from a Participant object.cccccccc
def self.create_from_participant(participant)
new(
assignment: participant.assignment.name, # Name of the assignment associated with the student task
topic: participant.topic, # Current stage of the assignment process
current_stage: participant.current_stage, # Participant object
stage_deadline: parse_stage_deadline(participant.stage_deadline), # Deadline for the current stage of the assignment
permission_granted: participant.permission_granted, # Topic of the assignment
participant: participant # Boolean indicating if Publishing Rights is enabled
)
end


# create an array of StudentTask instances for all participants linked to a user, sorted by deadline.
def self.from_user(user)
Participant.where(user_id: user.id)
.map { |participant| StudentTask.create_from_participant(participant) }
.sort_by(&:stage_deadline)
end

# create a StudentTask instance from a participant of the provided id
def self.from_participant_id(id)
create_from_participant(Participant.find_by(id: id))
end

private

# Parses a date string to a Time object, if parsing fails, set the time to be one year after current
def self.parse_stage_deadline(date_string)
Time.parse(date_string)
rescue StandardError
Time.now + 1.year
end

end
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# Enable server timing
config.server_timing = true

# Enable host requests for testing.
config.hosts << "www.example.com"

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp/caching-dev.txt').exist?
Expand Down
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
end
end
resources :assignments
resources :student_tasks do
collection do
get :list, action: :list
get :view
end
end

resources :courses do
collection do
Expand Down
89 changes: 89 additions & 0 deletions db/addTestObjects.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@



-- to start up app and SQL services on backedn

rails terminal:
docker compose up


-- Not too sure what this is exactly for
bundle install
rake db:create
rake db:migrate



-- app service
rails s -p 4000 -b '0.0.0.0'

-- SQL service
mysql -u dev -pexpertiza
use reimplementation_development;


-- Creating test objects in SQL



-- Create roles
INSERT INTO roles (name, created_at, updated_at) VALUES ('Student', NOW(), NOW());
INSERT INTO roles (name, created_at, updated_at) VALUES ('Instructor', NOW(), NOW());


-- Insert a user
INSERT INTO users (
name,
password_digest,
full_name,
email,
role_id,
institution_id,
created_at,
updated_at
) VALUES (
'testuser',
'password',
'Test User',
'testuser@example.com',
5, -- Assuming 1 is the ID for the role
1, -- Assuming 1 is the ID for the institution
NOW(),
NOW()
);



-- Insert an assignment
INSERT INTO assignments (
name,
directory_path,
course_id,
instructor_id,
created_at,
updated_at
) VALUES (
'Test Assignment',
'/path/to/assignment',
1, -- Assuming 1 is a valid course_id
(SELECT id FROM users WHERE name = 'testuser'), -- This selects the ID of the user you just inserted
NOW(),
NOW()
);


-- Created a new instructor, pretty sure the name field is full_name and there is also an password
-- field and institution_id.
-- Edited necesarry fields manually in RubyMine IDE

INSERT INTO users (name, email, password_digest, created_at, updated_at, role_id)
VALUES ('instructor_name', 'instructor_email', 'password_digest_here', NOW(), NOW(), (SELECT id FROM roles WHERE name = 'Instructor'));



SELECT * FROM users WHERE full_name = 'Test Instructor';


-- Inserting new test course
INSERT INTO courses (name, instructor_id, institution_id, created_at, updated_at)
VALUES ('Test Course', 3, 1, NOW(), NOW());
13 changes: 13 additions & 0 deletions db/migrate/20240415155554_create_student_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateStudentTasks < ActiveRecord::Migration[7.0]
def change
create_table :student_tasks do |t|
t.references :assignment, null: false, foreign_key: true
t.string :current_stage
t.references :participant, null: false, foreign_key: true
t.datetime :stage_deadline
t.string :topic

t.timestamps
end
end
end
7 changes: 7 additions & 0 deletions db/migrate/20240415163413_add_columns_to_participants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddColumnsToParticipants < ActiveRecord::Migration[7.0]
def change
add_column :participants, :topic, :string
add_column :participants, :current_stage, :string
add_column :participants, :stage_deadline, :datetime
end
end
5 changes: 5 additions & 0 deletions db/migrate/20240415192048_drop_student_task_tabkle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DropStudentTaskTabkle < ActiveRecord::Migration[7.0]
def change
drop_table :student_tasks
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPermissionGrantedToParticipants < ActiveRecord::Migration[7.0]
def change
add_column :participants, :permission_granted, :boolean, default: false
end
end
10 changes: 8 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.