...
 
Commits (53)
class V1::AchievementsController < ApplicationController
before_action :authorize, only: [:create]
def index
Achievement.all
end
def show
Achievement.find_by(id: params[:id])
end
def create
achievement = Achievement.new(params[:achievement])
authorize achievement
achievement.save
end
end
class V1::ActionCountersController < ApplicationController
def index
ActionCounter.all
end
def show
ActionCounter.find_by(id: params[:id])
end
end
class V1::ActionsController < ApplicationController
def index
Action.all
end
def show
Action.find_by(id: params[:id])
end
end
class V1::ItemsController < ApplicationController
before_action :authorize, only: [:create]
def index
items = Item.select { |i| i.state == "active" }
# filter by type
if params[:item_type]
items = items.select { |i| i.item_type == params[:item_type]}
end
# filter by price
if params[:op] == "lt" # less than
items = items.select { |item| item.price < params[:price] }
elif params[:op] == "gt" # greater than
items = items.select { |item| item.price > params[:price] }
elif params[:op] == "eq" # equals
items = items.select { |item| item.price == params[:price] }
end
# filter by the way it's unlocked
if params[:unlock_rule] == "achievement"
items = items.select { |item| item.achievable? }
elif params[:unlock_rule] == "purchase"
items = items.select { |item| !item.achievable? }
end
items
end
def show
Item.find_by(id: params[:id])
end
def create
item = Item.new(params[:item])
authorize item
item.save
end
end
class V1::ProgressesController < ApplicationController
def index
Progress.all
end
def show
Progress.find_by(id: params[:id])
end
end
class V1::RequirementsController < ApplicationController
def index
Requirement.all
end
def show
Requirement.find_by(id: params[:id])
end
end
class V1::UnlockedAchievementsController < ApplicationController
def index
UnlockedAchievement.all
end
def show
UnlockedAchievement.find_by(id: params[:id])
end
end
class V1::UserItemsController < ApplicationController
def index
items = Hash.new
for user_item in current_user.items.select { |i| i.item.state == "active"}
items.store(user_item, user_item.item)
if params[:item_type]
items = items.select { |u_i, i| i.item_type == params[:item_type] }
end
if params[:op] == "lt"
items = items.select { |u_i, i| i.price < params[:price] }
elif params[:op] == "gt"
items = items.select { |u_i, i| i.price > params[:price] }
elif params[:op] == "eq"
items = items.select { |u_i, i| i.price == params[:price] }
end
if params[:unlock_rule] == "achievement"
items = items.select { |u_i, i| i.achievable? }
elif params[:unlock_rule] == "purchase"
items = items.select { |u_i, i| !i.achievable? }
end
items
end
UserItem.all
end
def show
UserItem.find_by(id: params[:id])
end
end
......@@ -31,6 +31,144 @@ class V1::UsersController < ApplicationController
:teacher_requests, :add_teacher, :remove_teacher, :reactivate_user]
before_action :authorize_user, only: [:own_reviews, :received_reviews, :update, :destroy, :teacher_requests, :add_teacher, :remove_teacher]
# gamification
# PATCH /v1/users/complete_action
def complete_action
# current_user completes an action
# action counters and user progresses for achievements are updated,
# and if an achievement was conquered it's rewards are given
action_counters = current_user.action_counters.select \
{ |counter | counter.action.id == params[:id] }
for action_counter in action_counters
action_counter.counter += 1
end
for requirement_id in Action.find_by(id: action_id).requirements_id
requirement = Requirement.find_by(id: requirement_id)
progress = Progress.find_by(id: requirement.progress_id)
progress.counter += 1
if progress.counter >= requirement.goal
if requirement.repeatable
progress.counter = 0
else
requirement.destroy
end
achievement = Achievement.find_by(id: requirement.achievement_id)
incomplete = false
achievement_progresses = current_user.progresses.select {\
|progress| progress.achievement.id == achievement.id }
for progress in achievement_progresses
if progress.counter < progress.requirement.goal
incomplete = true
end
end
if !incomplete
current_user.get_achievement (achievement)
end
end
end
end
# PATCH /v1/users/purchase_item
def purchase_item
# purchases given item for current user
item = Item.find_by(id: params[:id])
if current_user.points <= item.price - item.discount
current_user.points -= item.price - item.discount
current_user.add_user_item(Item.find_by(id: params[:id]))
else
response.headers["status"] = 409 # conflict
end
end
# PATCH /v1/users/equip_item
def equip_item
current_user.equip_item(Item.find_by(id: params[:id]))
end
# PATCH /v1/users/remove_item
def remove_item
current_user.remove_item(Item.find_by(id: params[:id]))
end
# GET /v1/users/get_level
def get_level
User.find_by(id: params[:id]).update_level
end
# GET /v1/users/xp_to_next_level
def xp_to_next_lvl
# xp needed to proceed to next level
user = User.find_by(id: params[:id])
user.xp_to_next_level
end
def percent_to_next_level
# todo
user = User.find_by(id: params[:id])
user.xp_to_level(user.level)*100/user.xp_to_level(user.level+1)
end
# GET /v1/users/action_counters
def action_counters
# retorna action_counters e contagens correspondentes
counters = current_user.action_counters
pairs = Hash.new # pairs[actionName] = countForThatAction
for counter in counters do
pairs[counter.action.name] = counter.counter
end
pairs
end
# GET /v1/users/completed_achievements
def completed_achievements
user = User.find_by(id: params[:id])
achievements = Hash.new
for achievement in user.unlocked_achievements
achievements[achievement.id] = Hash[
"name" => achievement.name,
"description" => achievement.description,
"requirements" => achievement.requirements.map {
|r| Hash["description" => r.description,
"goal" => r.goal]
}
]
end
achievements
end
# GET /v1/users/xp
def xp
User.find_by(id: params[:id]).experience
end
# GET /v1/users/points
def points
User.find_by(id: params[:id]).points
end
# GET /v1/users/filter_user_items
def filter_user_items
if params[:filter] == "type"
current_user.items.select { |i| \
Items.find_by(id: i.item_id).type == params[:type] }
else
if params[:operation] == ">"
current_user.items.select { |i| \
Items.find_by(id: i.item_id).price > params[:price] }
elif params[:operation] == "<"
current_user.items.select { |i| \
Items.find_by(id: i.item_id).price < params[:price] }
else
current_user.items.select { |i| \
Items.find_by(id: i.item_id).price == params[:price] }
end
end
end
#
# end gamification
# GET /v1/users
# GET /v1/users.json
def index
......@@ -196,6 +334,10 @@ class V1::UsersController < ApplicationController
private
def xp_to_level(x)
(100 + Math.log([x, 900].min, 1.07)).floor
end
def deleted_resource
User
end
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: achievement
# t.string :name
# t.string :description
# t.integer :reward_experience
# t.integer :reward_points
# t.integer :state
# t.datetime :created_at
# t.datetime :updated_at
class Achievement < ApplicationRecord
has_many :items
has_many :requirements, dependent: :destroy
has_many :progresses, through: :requirements, dependent: :delete_all
belongs_to :unlocked_achievement
belongs_to :item
enum state:[:inactive, :active, :deleted]
enum repeatable: [:never, :daily, :weekly, :monthly, :yearly]
validates_presence_of :name, :description, :reward_experience, :reward_points, :state, :roles, :repeatable, :requirement
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: action
# t.integer "name"
# t.integer "description"
# t.datetime "created_at"
# t.datetime "updated_at"
# t.integer "reward_experience"
class Action < ApplicationRecord
belongs_to :requirement
belongs_to :action_counter
validates_presence_of :name, :description
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: action_counter
# t.belongs_to :action, index: true
# t.belongs_to :user, index:true
# t.integer :counter, default: 0
class ActionCounter < ApplicationRecord
has_one :action
belongs_to :user
validates_presence_of :user, :action
validates_uniqueness_of :user_id, :scope => :action_id
end
class ExperienceLevelMap < ApplicationRecord
def self.total_xp_to_level(lvl)
# xp to reach lvl from level 0
if lvl >= 900
lvl-899 * User.xp_to_level(900) + ExperienceLevelMap.find_by(level: 899).total_xp
else
ExperienceLevelMap.find_by(level: lvl).total_xp
end
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: items
# id: integer
# name: string
# price: integer
# discount: integer
# description: string
# state:
# item_type:
# achievable: boolean
# image_file_name: string
# image_content_type: string
# image_file_size: integer
# image_updated_at: datetime
# created_at: datetime
# updated_at: datetime
class Item < ApplicationRecord
has_one :achievement
belongs_to :achievement, optional: true
belongs_to :user_item
# belongs_to :user, through: :user_item
enum state: [:inactive, :active, :removed]
enum item_type: [:avatar_frame, :badge, :card_frame, :cover_frame]
validates_presence_of :name, :price, :description, :item_type
# Change to reasonable sizes after the decision by the designers.
# Use conditional size for each item_type accordingly to the design decision (https://github.com/thoughtbot/paperclip/wiki/Conditionally-resizing-images).
has_attached_file :image, styles: {:thumb => "100x100#", :small => "150x150>", :medium => "200x200"}
validates_attachment_content_type :image, content_type: ['image/png']
validates_attachment_presence :image
def achievable?
return achievement_id?
end
def corresponding_user_item
current_user.items.find { |item| item.item_id = self.id }
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: progress
# t.belongs_to :user
# t.belongs_to :achievement
# t.belongs_to :progress_type
# t.integer :counter, default: 0
class Progress < ApplicationRecord
has_one :requirement
belongs_to :user
has_one :achievement, through: :requirement
has_one :action, through: :requirement
validates_presence_of :requirement
scope :user_progresses, -> (id) { where(user_id: id) }
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: progress_type
# t.belongs_to "action"
# t.belnogs_to "achievement"
# t.string "description"
# t.integer "goal"
# t.datetime "created_at"
# t.datetime "updated_at"
class Requirement < ApplicationRecord
has_one :action
belongs_to :progress
belongs_to :achievement
accepts_nested_attributes_for :progress, allow_destroy: true
validates_presence_of :goal, :description, :action, :achievement
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: action_counter
# t.belongs_to :action, index: true
# t.belongs_to :user, index:true
class UnlockedAchievement < ApplicationRecord
has_one :achievement
belongs_to :user
validates_presence_of :achievement, :user
validates_uniqueness_of :achievement_id, :scope => :user_id
end
......@@ -95,6 +95,20 @@ class User < ApplicationRecord
has_many :curator_assignments
has_many :assignments, through: :curator_assignments, source: :submission
has_many :user_items
has_many :items, through: :user_items, source: :item
has_many :progresses
has_many :requirements, through: :progresses
has_many :unlocked_achievements
has_many :achievements, through: :unlocked_achievements
has_many :action_counters
has_many :actions, through: :action_counters
validates_presence_of :progresses, :action_counters
after_create :default_role
before_save :verify_teacher_id
after_save :verify_dspace_info
......@@ -125,6 +139,8 @@ class User < ApplicationRecord
# don't versionate frequently changed fields
has_paper_trail ignore: [:tokens, :sign_in_count, :current_sign_in_at, :last_sign_in_at]
before_validation :generate_gamification_relations, on: :create
def search_data
{
name: name,
......@@ -235,6 +251,96 @@ class User < ApplicationRecord
'reviews.reviewable_id = learning_objects.id')
end
def add_user_item (item)
self.items << UserItem.create(user_id: self.id, item_id: item.id)
end
def equip_item (item)
if ! self.items.find { |i| i.item_id == item.id }
self.add_user_item (item)
end
occupied_slots = self.items.count { |i| i.item.type == item.type }
if (item.type == :badge) && (occupied_slots == 3)
self.items.find { |i| i.item.type == :badge }.being_used = false
elsif occupied_slots
self.items.find { |i| i.item.type == item.type }.being_used = false
self.items.find { |i| i.item == item }.being_used = true
end
end
def remove_item (item)
self.items.find { |i| i.item.id == item.id }.being_used = false
end
def self.xp_to_level(lvl)
# necessary xp to reach level x from level x-1
(100 + Math.log([lvl, 900].min, 1.07)).floor
end
def self.calculate_level(xp)
# corresponding level to a determinate amount of experience
lvl = 1 # iterator
while xp > ExperienceLevelMap.total_xp_to_level(lvl)
lvl += 1
end
if xp < ExperienceLevelMap.total_xp_to_level(lvl)
lvl - 1
else
lvl
end
end
def xp_to_next_level
# necessary xp for the user to reach next level
self.update_level()
lvl_floor = ExperienceLevelMap.total_xp_to_level(self.level)
self.xp_to_level(self.level+1) - (self.experience - lvl_floor)
end
def update_level
while self.xp_to_next_level() <= 0
self.level += 1
end
end
def get_achievement(achievement)
self.unlocked_achievements << UnlockedAchievement.create(\
user_id: self.id, achievement_id: achievement.id)
for item in achievement.items
self.add_user_item (item)
end
self.experience += achievement.reward_experience
self.points += achievement.reward_points
for progress in self.progresses.select {|p| p.achievement == achievement }
if achievement.repeatable
progress.counter = 0
else
progress.destroy
end
end
end
def generate_gamification_relations
if !self.progresses
self.progresses = Array.new
for req in Requirement.all
self.progresses << Progress.create(requirement_id: req.id)
end
end
if !self.action_counters
self.action_counters = Array.new
for action in Action.all
self.action_counters << ActionCounter.create(action_id: action.id)
end
end
end
# ~~~~ followable actions ~~~~ #
# An user can follow anothers users and collections
# Examples:
......@@ -373,4 +479,12 @@ class User < ApplicationRecord
def complaint_reject(params)
end
def create_progresses
self.requirements |= ProgressType.all.includes(achievement: [:roles]).where(roles: {id: self.roles})
end
def create_action_counters
self.actions |= Action.all
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: inventory
# t.belongs_to :user, index: true
# t.belongs_to item, index: true
# t.boolean :being_used, default: false
# t.datetime "created_at"
# t.datetime "updated_at"
class UserItem < ApplicationRecord
belongs_to :user
has_one :item
validates_presence_of :item
validates_uniqueness_of :item_id, :scope => :user_id
def corresponding_item
self.item
end
def unlocked_by_achievement?
self.item.achievable?
end
def unlocked_by_purchase?
! self.item.achievable?
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class AchievementPolicy < ApplicationPolicy
class Scope < Scope
def resolve
if user_exists?
if user_can_edit?
scope.all
else
scope.includes(:roles).where(roles: {id: user.roles})
end
else
scope.none
end
end
end
def index?
record if user_exists?
end
def show?
record if user_exists?
end
def create?
record if user_exists? && user_can_edit?
end
def update?
record if user_exists? && user_can_edit?
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class ItemPolicy < ApplicationPolicy
def index?
record
end
def show?
record
end
def create?
record if user_can_edit?
end
def update?
record if user_can_edit?
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class AchievementSerializer < ActiveModel::Serializer
cache key: 'achievement', expires_in: 24.hours
has_many :progresses
def progresses
Progress.user_progresses(current_user.id).joins(:achievement, :progress_type).where(achievements: {id: self.object.id}).select("progresses.*, progress_types.goal")
end
attributes \
:id,
:name,
:description,
:reward_experience,
:reward_points,
:state,
:created_at,
:updated_at ,
:repeatable
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class ItemSerializer < ActiveModel::Serializer
cache key: 'item', expires_in: 24.hours
attributes \
:id,
:name,
:price,
:discount,
:description,
:state,
:item_type,
:achievement,
:image,
:created_at,
:updated_at
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class ProgressTypeSerializer < ActiveModel::Serializer
cache key: 'progress_type', expires_in: 24.hours
attributes :description, :goal, :created_at, :updated_at
end
\ No newline at end of file
......@@ -129,6 +129,24 @@ Rails.application.routes.draw do
end
namespace :v1 do
resources :unlocked_achievements, :user_items, :progresses, :actions, \
:action_counters, only: [:index, :show]
resources :achievements, :items, only: [:index, :show, :create]
scope controller: :users do
patch 'complete_action'
patch 'purchase_item'
patch 'equip_item'
patch 'remove_item'
get 'get_level'
get 'xp_to_next_level'
get 'action_counters'
get 'completed_achievements'
get 'xp'
get 'points'
get 'filter_user_items'
end
resources :activities, only: [:index, :show] do
collection do
get 'me'
......@@ -211,6 +229,8 @@ Rails.application.routes.draw do
resources :statistics, only: [:index]
resources :complaint_reasons, except: [:destroy]
resources :questions, except: [:destroy]
resources :items, except: [:destroy]
resources :achievements, except: [:create, :destroy]
post '/package', to: 'packages#link'
get '/subjects', to: 'subjects#index'
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateItem < ActiveRecord::Migration[5.0]
def change
create_table :items do |t|
t.string :name
t.integer :price
t.integer :discount, default: 0
t.string :description
t.integer :state, default: 0
t.integer :item_type
t.has_attached_file :image
t.timestamps
end
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateInventory < ActiveRecord::Migration[5.0]
def change
create_table :inventories do |t|
t.belongs_to :user, index: true
t.belongs_to :item, index: true
t.boolean :being_used, default: false
t.timestamps
end
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateAction < ActiveRecord::Migration[5.0]
def change
create_table :actions do |t|
t.string :name
t.string :description
t.timestamps
end
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateActionCounter < ActiveRecord::Migration[5.0]
def change
create_table :action_counters do |t|
t.belongs_to :action, index: true
t.belongs_to :user, index:true
t.integer :counter, default: 0
end
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateProgressType < ActiveRecord::Migration[5.0]
def change
create_table :progress_types do |t|
t.belongs_to :action
t.string :description
t.integer :goal
t.timestamps
end
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateAchievement < ActiveRecord::Migration[5.0]
def change
create_table :achievements do |t|
t.string :name
t.string :description
t.integer :reward_experience
t.integer :reward_points
t.integer :state
t.integer :repeatable
t.timestamps
end
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateProgress < ActiveRecord::Migration[5.0]
def change
create_table :progresses do |t|
t.references :user, index: true
t.belongs_to :progress_type, index: true
t.integer :counter, default: 0
end
end
end
class CreateJoinTableRoleAchievement < ActiveRecord::Migration[5.0]
def change
create_join_table :roles, :achievements do |t|
t.index :role_id
t.index :achievement_id
end
end
end
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class CreateUnlockedAchievement < ActiveRecord::Migration[5.0]
def change
create_table :unlocked_achievements do |t|
t.belongs_to :user, index: true
t.belongs_to :achievement, index: true
t.timestamps
end
end
end
class AddRelationItemAchiemvement < ActiveRecord::Migration[5.0]
def change
add_belongs_to :items, :achievement, optional: true
end
end
class AddExperienceLevelandPointsToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :experience, :integer, unsigned: true, default: 0
add_column :users, :level, :integer, unsigned: true, default: 1
add_column :users, :points, :integer, unsigned: true, default: 0
end
end
class AddRelationProgressTypeAchiemvement < ActiveRecord::Migration[5.0]
def change
add_belongs_to :progress_types, :achievement, index: true
end
end
class AddRewardExperienceToAction < ActiveRecord::Migration[5.0]
def change
add_column :actions, :reward_experience, :integer, unsigned: true
end
end
class RenameGamificationTables < ActiveRecord::Migration[5.0]
def change
rename_table :progress_types, :requirements
rename_table :inventories, :user_items
end
end
class AdjustRequirements < ActiveRecord::Migration[5.0]
def change
change_column :requirements, :description, :text
remove_timestamps(:requirements)
add_column :requirements, :repeatable, :integer
end
end
class AdjustActions < ActiveRecord::Migration[5.0]
def change
change_column :actions, :description, :text
end
end
class AdjustAchievements < ActiveRecord::Migration[5.0]
def change
change_column :achievements, :description, :text
remove_timestamps(:achievements)
add_column :achievements, :resettable, :boolean
end
end
class AdjustItems < ActiveRecord::Migration[5.0]
def change
change_column :items, :description, :text
remove_timestamps(:items)
end
end
class AdjustActionCounters < ActiveRecord::Migration[5.0]
def change
rename_column :action_counters, :counter, :action_counter
end
end
class RemoveAchievementsRoles < ActiveRecord::Migration[5.0]
def change
drop_table :achievements_roles
end
end
class AdjustUserItems < ActiveRecord::Migration[5.0]
def change
remove_timestamps(:user_items)
end
end
class AddGamificationRelations < ActiveRecord::Migration[5.0]
def change
add_belongs_to :actions, :requirements, foreign_key: true
add_belongs_to :actions, :action_counters, foreign_key: true
add_belongs_to :requirements, :achievements, foreign_key: true
add_belongs_to :requirements, :progresses, foreign_key: true
add_belongs_to :achievements, :unlocked_achievements, foreign_key: true
add_belongs_to :unlocked_achievements, :users, foreign_key: true
add_belongs_to :action_counters, :users, foreign_key: true
add_belongs_to :progresses, :users, foreign_key: true
add_belongs_to :user_items, :users, foreign_key: true
add_belongs_to :items, :user_items, foreign_key: true
create_join_table :items, :achievements do |t|
# t.index [:item_id, :achievement_id]
# t.index [:achievement_id, :item_id]
end
end
end