Class: EducodeSales::TeacherFollowsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/educode_sales/teacher_follows_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin, #authenticate_request, #current_user, #render_failure, #render_success

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/educode_sales/teacher_follows_controller.rb', line 5

def create
  load_teacher
  follow_up = @teacher.teacher_follows.build(follow_up_params)
  follow_up.staff = @current_admin
  if @teacher.user_id.present?
    course_ids = CourseMember.joins(:course).where(user_id: @teacher.user_id, courses:{is_delete: 0}).where.not(role: 4).pluck(:course_id)
    follow_up.course_shixuns_count = CourseMember.joins(course: :practice_homework_shixuns).where(course_id: course_ids).pluck(:shixun_id).uniq.count
    follow_up.shixuns_count = ShixunMember.where(user_id: @teacher.user_id).count
    follow_up.students_count = CourseMember.where(course_id: course_ids, role: 4).count
    follow_up.evaluates_count = Course.where(id: course_ids).inject(0) { |i, d| i += d.evaluate_count }
    follow_up.courses_count = course_ids.size
  end
  if follow_up.save
    @teacher.update(follow_up_id: follow_up.id)
    render_success
  else
    render_failure follow_up
  end
end

#destroyObject



25
26
27
28
29
30
31
32
# File 'app/controllers/educode_sales/teacher_follows_controller.rb', line 25

def destroy
  follow_up = TeacherFollow.find(params[:id])
  if follow_up.destroy
    render_success
  else
    render_failure follow_up
  end
end

#updateObject



34
35
36
37
38
39
40
41
42
# File 'app/controllers/educode_sales/teacher_follows_controller.rb', line 34

def update
  follow_up = TeacherFollow.find(params[:id])
  follow_up.assign_attributes(follow_up_params)
  if follow_up.save
    render_success
  else
    render_failure follow_up
  end
end