Task create and update
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Tasks
|
||||
class Create < ApplicationService
|
||||
attribute :project_id, :integer
|
||||
attribute :title, :string
|
||||
attribute :description, :string
|
||||
|
||||
validates :project_id, :title, presence: true
|
||||
|
||||
delegate :model_name, to: Task
|
||||
|
||||
attr_reader :project, :task
|
||||
|
||||
def perform
|
||||
@project = Project.find(project_id)
|
||||
|
||||
@task = @project.tasks.build(title:, description:, number: @project.next_task_number)
|
||||
@task.save.tap { @errors = @task.errors }
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user