Task create and update

This commit is contained in:
2025-07-12 18:00:56 +03:00
parent 4f5b9dcf89
commit 586f2cf3ee
7 changed files with 132 additions and 8 deletions
+22
View File
@@ -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
+22
View File
@@ -0,0 +1,22 @@
# frozen_string_literal: true
module Tasks
class Update < ApplicationService
attribute :id, :integer
attribute :title, :string
attribute :description, :string
validates :title, presence: true
delegate :model_name, to: Task
def persisted? = true
def perform(task)
@task = task
@id = task.id
@task.assign_attributes(title:, description:)
save @task
end
end
end