Skip to content

Instantly share code, notes, and snippets.

@equivalent
Created August 21, 2020 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save equivalent/5697f58cc1dd50f94ff094d8949d0c50 to your computer and use it in GitHub Desktop.
Save equivalent/5697f58cc1dd50f94ff094d8949d0c50 to your computer and use it in GitHub Desktop.
Ruby on Rails - Bounded contexts via interface objects - Controllers example 1
class CommentsController < ApplicationController
# POST /works/123/comments
def create
work = Work.find(params[:work_id])
current_user_student = Student.find(session[:id])
if work.public_board.can_post_comment?(current_user: current_user_student)
work.work_interaction.post_comment(student: current_user_student, content: params[:content])
# ...
end
end
end
class LessonsController < ApplicationController
# POST /lessons
def create
teacher = Teacher.find(session[:teacher_id])
students = Student.where(id: params[:student_ids])
lesson = teacher.classroom.create_lesson(students: students, title: params[:title])
# ...
end
# POST /lessons/345/publish
def publish
lesson = Lesson.find(params[:lesson_id])
lesson.classroom.publish
# ...
end
# POST /lessons/345/mark_as_favorite
def mark_as_favorite
lesson = Lesson.find(params[:lesson_id])
current_user_student = Student.find(session[:id])
lesson.public_board.mark_as_favorite(current_user: current_user_student)
# ...
end
end
class WorksController < ApplicationController
# POST /lesson/123/works
def create
lesson = Lesson.find(params[:lesson_id])
current_user_student = Student.find(session[:id])
lesson.classroom.upload_work(student: current_user_student, file: params[:file])
# ...
end
end