Skip to content
Snippets Groups Projects
Commit 2e708e2f authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

Refactor code: Use correct code pattern

parent e4f0b6b0
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ class LearningObjectsController < ApplicationController
# GET /learning_objects
# GET /learning_objects.json
def index
@learning_objects = repository.for(:learning_object).all
@learning_objects = learning_object_repository.all
end
# GET /learning_objects/1
......@@ -17,7 +17,7 @@ class LearningObjectsController < ApplicationController
# GET /learning_objects/new
def new
@learning_object = repository.for(:learning_object).new
@learning_object = LearningObject.new
end
# GET /learning_objects/1/edit
......@@ -27,15 +27,13 @@ class LearningObjectsController < ApplicationController
# POST /learning_objects
# POST /learning_objects.json
def create
@learning_object = repository.for(:learning_object).new(learning_object_params)
@learning_object = LearningObject.new(learning_object_params)
respond_to do |format|
if @learning_object.save
if learning_object_repository.save @learning_object
format.html { redirect_to @learning_object, notice: 'Learning object was successfully created.' }
format.json { render :show, status: :created, location: @learning_object }
else
format.html { render :new }
format.json { render json: @learning_object.errors, status: :unprocessable_entity }
end
end
end
......@@ -44,12 +42,10 @@ class LearningObjectsController < ApplicationController
# PATCH/PUT /learning_objects/1.json
def update
respond_to do |format|
if @learning_object.update(learning_object_params)
if learning_object_repository.update(learning_object_params)
format.html { redirect_to @learning_object, notice: 'Learning object was successfully updated.' }
format.json { render :show, status: :ok, location: @learning_object }
else
format.html { render :edit }
format.json { render json: @learning_object.errors, status: :unprocessable_entity }
end
end
end
......@@ -57,17 +53,22 @@ class LearningObjectsController < ApplicationController
# DELETE /learning_objects/1
# DELETE /learning_objects/1.json
def destroy
@learning_object.destroy
learning_object_repository.destroy @learning_object
respond_to do |format|
format.html { redirect_to learning_objects_url, notice: 'Learning object was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def learning_object_repository
repository.for(:learning_object)
end
# Use callbacks to share common setup or constraints between actions.
def set_learning_object
@learning_object = repository.for(:learning_object).get_by_dspaceid params[:id]
@learning_object = learning_object_repository.get_by_dspaceid params[:id]
end
# Never trust parameters from the scary internet, only allow the white list through.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment