Sha256: 01ec7dedfbf3f14cea5bd79b8947910ac5ea83fd932ccec8e593619cdbd4366c

Contents?: true

Size: 1.71 KB

Versions: 69

Compression:

Stored size: 1.71 KB

Contents

require_dependency "educode_sales/application_controller"

module EducodeSales
  class TeacherFollowsController < ApplicationController
    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

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

    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

    private

    def load_teacher
      @teacher = Teacher.find(params[:teacher_id])
    end

    def follow_up_params
      params.permit(:attitude_id, :follow_id, :course_plan_id, :course_build_id, :description)
    end

  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
educode_sales-0.9.48 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.47 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.46 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.45 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.44 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.43 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.42 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.41 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.40 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.39 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.38 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.37 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.36 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.35 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.34 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.33 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.32 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.31 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.30 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.29 app/controllers/educode_sales/teacher_follows_controller.rb