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.8 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.7 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.6 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.5 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.4 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.3 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.2 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.9.1 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.8.9 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.8.7 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.8.6 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.8.5 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.8.4 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.8.3 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.8.2 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.8.1 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.7.9 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.7.8 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.7.7 app/controllers/educode_sales/teacher_follows_controller.rb
educode_sales-0.7.6 app/controllers/educode_sales/teacher_follows_controller.rb