Skip to content
Snippets Groups Projects
Commit b0049334 authored by Richard Fernando Heise Ferreira's avatar Richard Fernando Heise Ferreira
Browse files

Merge branch 'issue/12-show-all-unlocked-achievements-user' into 'develop'

Issue #12: ADD route to show unlocked achievements

See merge request rfhf19/cleanning-portalmec!13
parents ae64f4ba 20248989
No related branches found
No related tags found
2 merge requests!17Curatorship and Gamification done,!13Issue #12: ADD route to show unlocked achievements
Pipeline #30324 failed
class V1::LearningObjectsComplaintsController < ApplicationController
include ::DeletedObjectsController
include ::Paginator
before_action :set_complaint, only: [:show, :show_related , :reject, :accept]
# GET v1/learning_objects_complaints
def index
complaints_curator = paginate Complaint
base_date = Date.new(2022, 1, 1)
complaints_priority = ComplaintReason.joins(:complaints).select("complainable_id, SUM(complaint_reasons.priority)")
.where("complaints.created_at >= ?", base_date).group("complainable_id").order("sum DESC")
complaints_curator = []
complaints_priority.each do |complainable|
# Select all complaints related to the complainable_id (attributes that have been sumed)
complaints_curator << ComplaintReason.joins(:complaints).select("*")
.where("complaints.complainable_id = ? AND complaints.created_at >=?", complainable.complainable_id, base_date).order("complaint_reasons.priority DESC")
end
render json: complaints_curator
end
end
\ No newline at end of file
......@@ -32,6 +32,15 @@ class V1::UnlockedAchievementsController < ApplicationController
render json: @achievement
end
# GET /v1/unlocked_achievements/user/:id
def show_specific
# search for a all unlocked_achievements of a specific user
un_achievement = paginate User.find_by_id(params[:user_id]).unlocked_achievements
render json: un_achievement
end
private
def set_achievement
......
......@@ -6,15 +6,15 @@ development:
adapter: postgresql
encoding: unicode
database: portalmec_dev
username: arthur
password: senhadopostgres
username: luan
password: luanmatheus
test:
adapter: postgresql
encoding: unicode
database: portalmec_test
username: arthur
password: senhadopostgres
username: luan
password: luanmatheus
# host: postgres
production:
......
......@@ -142,6 +142,8 @@ Rails.application.routes.draw do
end
end
get 'unlocked_achievements/user/:user_id', to: 'unlocked_achievements#show_specific'
resources :activities, only: [:index, :show] do
collection do
get 'me'
......
namespace :achievement_dependency do
desc "Run the priority queue"
base_date = Date.new(2022, 1, 1)
task :link_achievements => :environment do
#create a queue of achievements that need to be linked
unlocked_achievements = UnlockedAchievement.joins(:achievement).select("achievements.id, achievements.name,
unlocked_achievements.id, unlocked_achievements.user_id").where("unlocked_achievements.id = achievements.id")
puts ("----------------------------------------------------")
unlocked_achievements.each do |un_achievement|
puts "unlocked_achievement: #{un_achievement.name}"
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment