Created
August 21, 2020 09:54
-
-
Save equivalent/5697f58cc1dd50f94ff094d8949d0c50 to your computer and use it in GitHub Desktop.
Ruby on Rails - Bounded contexts via interface objects - Controllers example 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a GIST for Medium mirror article Ruby on Rails - Bounded contexts via interface object
https://medium.com/@tomas.valent/ruby-on-rails-bounded-contexts-via-interface-objects-4fd61738acaa
Original article: https://blog.eq8.eu/article/rails-bounded-contexts.html
Full list of Article GISTs: