27 lines
628 B
Ruby
27 lines
628 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Tasks
|
|
class Create < ApplicationService
|
|
attribute :project_id, :integer
|
|
attribute :title, :string
|
|
attribute :description, :string
|
|
attribute :status_id, :integer
|
|
attribute :workflow_id, :integer
|
|
|
|
validates :project_id, :title, :status_id, :workflow_id, presence: true
|
|
|
|
delegate :model_name, to: Task
|
|
|
|
attr_reader :task
|
|
|
|
def project
|
|
@project ||= Project.find(project_id)
|
|
end
|
|
|
|
def perform
|
|
@task = project.tasks.build(title:, description:, status_id:, workflow_id:, number: @project.next_task_number)
|
|
save @task
|
|
end
|
|
end
|
|
end
|