Skip to content

Commit 08e2c85

Browse files
committed
Returning ready to review count with classes
1 parent 0e0beb6 commit 08e2c85

8 files changed

Lines changed: 42 additions & 37 deletions

File tree

app/controllers/api/school_classes_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ def index
1010
school_classes = @school.classes.accessible_by(current_ability)
1111
school_classes = school_classes.joins(:teachers).where(teachers: { teacher_id: current_user.id }) if params[:my_classes] == 'true'
1212
@school_classes_with_teachers = school_classes.with_teachers
13-
render :index, formats: [:json], status: :ok
13+
if current_user&.school_teacher?(@school) || current_user&.school_owner?(@school)
14+
render :teacher_index, formats: [:json], status: :ok
15+
else
16+
render :index, formats: [:json], status: :ok
17+
end
1418
end
1519

1620
def show

app/models/lesson.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def unarchive!
5454

5555
def submitted_count
5656
return 0 unless project
57-
5857
project.remixes.count { |remix| remix.school_project&.submitted? }
5958
end
6059

app/models/school_class.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def assign_class_code
5858
errors.add(:code, 'could not be generated')
5959
end
6060

61+
def submitted_count
62+
return 0 if lessons.empty?
63+
64+
lessons.sum(&:submitted_count)
65+
end
66+
6167
private
6268

6369
def school_class_has_at_least_one_teacher
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
json.call(
4+
school_class,
5+
:id,
6+
:description,
7+
:school_id,
8+
:name,
9+
:code,
10+
:created_at,
11+
:updated_at,
12+
:import_origin,
13+
:import_id
14+
)
15+
16+
json.teachers(teachers) do |teacher|
17+
json.partial! '/api/school_teachers/school_teacher', teacher:, include_email: false
18+
end

app/views/api/school_classes/index.json.jbuilder

Lines changed: 0 additions & 19 deletions
This file was deleted.

app/views/api/school_classes/show.json.jbuilder

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,4 @@
22

33
school_class, teachers = @school_class_with_teachers
44

5-
json.call(
6-
school_class,
7-
:id,
8-
:description,
9-
:school_id,
10-
:name,
11-
:code,
12-
:created_at,
13-
:updated_at,
14-
:import_origin,
15-
:import_id
16-
)
17-
18-
json.teachers(teachers) do |teacher|
19-
json.partial! '/api/school_teachers/school_teacher', teacher:, include_email: false
20-
end
5+
json.partial! 'school_class', school_class: school_class, teachers: teachers
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
json.array!(@school_classes_with_teachers) do |school_class, teachers|
4+
json.partial! 'school_class', school_class: school_class, teachers: teachers
5+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
json.array!(@school_classes_with_teachers) do |school_class, teachers|
4+
json.partial! 'school_class', school_class: school_class, teachers: teachers
5+
6+
json.submitted_count(school_class.submitted_count)
7+
end

0 commit comments

Comments
 (0)