extract shared pace controller logic
refs LS-3459 flag=course_paces_redesign test plan: - specs pass qa risk: low Change-Id: I08fc7aacbb13e612bebbb7f7188338db903c5267 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/301950 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Luis Oliveira <luis.oliveira@instructure.com> QA-Review: Luis Oliveira <luis.oliveira@instructure.com> Product-Review: Davis Hyer <dhyer@instructure.com>
This commit is contained in:
parent
12dbc7e04e
commit
edf31bea16
|
@ -17,41 +17,41 @@
|
|||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class SectionPacesApiController < ApplicationController
|
||||
class CoursePacing::PacesApiController < ApplicationController
|
||||
before_action :load_contexts
|
||||
before_action :require_feature_flag
|
||||
# TODO: permissions
|
||||
|
||||
def index
|
||||
render json: {
|
||||
paces: CoursePacing::SectionPaceService.paces_in_course(@course).map do |p|
|
||||
CoursePacing::SectionPacePresenter.new(p).as_json
|
||||
paces: pacing_service.paces_in_course(course).map do |p|
|
||||
pacing_presenter.new(p).as_json
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def show
|
||||
render json: {
|
||||
pace: CoursePacing::SectionPacePresenter.new(
|
||||
CoursePacing::SectionPaceService.pace_in_context(@section)
|
||||
pace: pacing_presenter.new(
|
||||
pacing_service.pace_in_context(context)
|
||||
).as_json
|
||||
}
|
||||
end
|
||||
|
||||
def create
|
||||
render json: {
|
||||
pace: CoursePacing::SectionPacePresenter.new(
|
||||
CoursePacing::SectionPaceService.create_in_context(@section)
|
||||
pace: pacing_presenter.new(
|
||||
pacing_service.create_in_context(context)
|
||||
).as_json,
|
||||
progress: nil # TODO: update when progress taken into account
|
||||
}, status: :created
|
||||
end
|
||||
|
||||
def update
|
||||
pace = CoursePacing::SectionPaceService.pace_in_context(@section)
|
||||
if CoursePacing::SectionPaceService.update_pace(pace, update_params)
|
||||
pace = pacing_service.pace_in_context(context)
|
||||
if pacing_service.update_pace(pace, update_params)
|
||||
render json: {
|
||||
pace: CoursePacing::SectionPacePresenter.new(pace).as_json,
|
||||
pace: pacing_presenter.new(pace).as_json,
|
||||
progress: nil # TODO: update when progress taken into account
|
||||
}
|
||||
else
|
||||
|
@ -60,7 +60,7 @@ class SectionPacesApiController < ApplicationController
|
|||
end
|
||||
|
||||
def delete
|
||||
CoursePacing::SectionPaceService.delete_in_context(@section)
|
||||
pacing_service.delete_in_context(context)
|
||||
head :no_content
|
||||
end
|
||||
|
||||
|
@ -76,13 +76,27 @@ class SectionPacesApiController < ApplicationController
|
|||
)
|
||||
end
|
||||
|
||||
def require_feature_flag
|
||||
not_found unless Account.site_admin.feature_enabled?(:course_paces_redesign)
|
||||
def pacing_service
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def pacing_presenter
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def course
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def context
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def load_contexts
|
||||
@course = api_find(Course.active, params[:course_id]) if params[:course_id]
|
||||
@section = api_find(CourseSection, params[:course_section_id]) if params[:course_section_id]
|
||||
# TODO: confirm section is associated with the course if course_id is provided
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def require_feature_flag
|
||||
not_found unless Account.site_admin.feature_enabled?(:course_paces_redesign)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2022 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class CoursePacing::SectionPacesApiController < CoursePacing::PacesApiController
|
||||
private
|
||||
|
||||
def pacing_service
|
||||
CoursePacing::SectionPaceService
|
||||
end
|
||||
|
||||
def pacing_presenter
|
||||
CoursePacing::SectionPacePresenter
|
||||
end
|
||||
|
||||
attr_reader :course
|
||||
|
||||
def context
|
||||
@section
|
||||
end
|
||||
|
||||
def load_contexts
|
||||
@course = api_find(Course.active, params[:course_id]) if params[:course_id]
|
||||
@section = api_find(CourseSection, params[:course_section_id]) if params[:course_section_id]
|
||||
# TODO: confirm section is associated with the course if course_id is provided
|
||||
end
|
||||
end
|
|
@ -2440,7 +2440,7 @@ CanvasRails::Application.routes.draw do
|
|||
put "eportfolios/:eportfolio_id/restore", action: :restore
|
||||
end
|
||||
|
||||
scope(controller: :section_paces_api) do
|
||||
scope(controller: "course_pacing/section_paces_api") do
|
||||
get "courses/:course_id/section_paces", action: :index, as: :section_paces
|
||||
get "courses/:course_id/sections/:course_section_id/pace", action: :show, as: :section_pace
|
||||
post "courses/:course_id/sections/:course_section_id/paces", action: :create, as: :new_section_pace
|
||||
|
|
Loading…
Reference in New Issue