class LearningObjectsController < ApplicationController before_action :set_learning_object, only: [:show, :edit, :update, :destroy] after_action :register_view, only: [:show] # GET /learning_objects # GET /learning_objects.json def index @learning_objects = learning_object_repository.all end # GET /learning_objects/1 # GET /learning_objects/1.json def show unless @learning_object.nil? @like_counts = repository.for(:edge).get_in_edges_count "Likes", @learning_object.id @view_counts = repository.for(:edge).get_in_edges_count "Views", @learning_object.id end end # GET /learning_objects/new def new @learning_object = LearningObject.new end # GET /learning_objects/1/edit def edit end # POST /learning_objects # POST /learning_objects.json def create @learning_object = LearningObject.new(learning_object_params) respond_to do |format| if learning_object_repository.save @learning_object format.html { redirect_to @learning_object, notice: 'Learning object was successfully created.' } else format.html { render :new } end end end # PATCH/PUT /learning_objects/1 # PATCH/PUT /learning_objects/1.json def update respond_to do |format| if learning_object_repository.update(learning_object_params) format.html { redirect_to @learning_object, notice: 'Learning object was successfully updated.' } else format.html { render :edit } end end end # DELETE /learning_objects/1 # DELETE /learning_objects/1.json def destroy learning_object_repository.destroy @learning_object respond_to do |format| format.html { redirect_to learning_objects_url, notice: 'Learning object was successfully destroyed.' } 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 = learning_object_repository.get_by_dspaceid params[:id] end # Never trust parameters from the scary internet, only allow the white list through. def learning_object_params params[:learning_object] end def register_view repository.for(:edge).create_edge('Views', '#14:0', @learning_object.first["@rid"]) end end