BigW Consortium Gitlab

Extract method to serialize board lists as JSON

parent cd98ff17
...@@ -5,14 +5,14 @@ module Projects ...@@ -5,14 +5,14 @@ module Projects
before_action :authorize_read_list!, only: [:index] before_action :authorize_read_list!, only: [:index]
def index def index
render json: project.board.lists.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :description, :color, :priority] } }) render json: serialize_as_json(project.board.lists)
end end
def create def create
list = ::Boards::Lists::CreateService.new(project, current_user, list_params).execute list = ::Boards::Lists::CreateService.new(project, current_user, list_params).execute
if list.valid? if list.valid?
render json: list.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :description, :color, :priority] } }) render json: serialize_as_json(list)
else else
render json: list.errors, status: :unprocessable_entity render json: list.errors, status: :unprocessable_entity
end end
...@@ -42,7 +42,7 @@ module Projects ...@@ -42,7 +42,7 @@ module Projects
service = ::Boards::Lists::GenerateService.new(project, current_user) service = ::Boards::Lists::GenerateService.new(project, current_user)
if service.execute if service.execute
render json: project.board.lists.label.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :description, :color, :priority] } }) render json: serialize_as_json(project.board.lists.label)
else else
head :unprocessable_entity head :unprocessable_entity
end end
...@@ -65,6 +65,15 @@ module Projects ...@@ -65,6 +65,15 @@ module Projects
def move_params def move_params
params.require(:list).permit(:position).merge(id: params[:id]) params.require(:list).permit(:position).merge(id: params[:id])
end end
def serialize_as_json(resource)
resource.as_json(
only: [:id, :list_type, :position],
methods: [:title],
include: {
label: { only: [:id, :title, :description, :color, :priority] }
})
end
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment