2017-08-30 15:29:45 +08:00
|
|
|
module ClientApi
|
|
|
|
module Teams
|
|
|
|
class TeamsController < ApplicationController
|
|
|
|
include ClientApi::Users::UserTeamsHelper
|
|
|
|
|
|
|
|
def index
|
|
|
|
success_response('/client_api/teams/index',
|
|
|
|
teams: current_user.teams_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def details
|
2017-08-30 22:18:21 +08:00
|
|
|
team_service = ClientApi::TeamsService.new(team_id: params[:team_id],
|
2017-08-30 15:29:45 +08:00
|
|
|
current_user: current_user)
|
|
|
|
success_response('/client_api/teams/details',
|
|
|
|
team_service.team_page_details_data)
|
2017-08-30 22:18:21 +08:00
|
|
|
rescue ClientApi::CustomTeamError
|
2017-08-30 15:29:45 +08:00
|
|
|
error_response
|
|
|
|
end
|
|
|
|
|
|
|
|
def change_team
|
2017-08-30 22:18:21 +08:00
|
|
|
team_service = ClientApi::TeamsService.new(team_id: params[:team_id],
|
2017-08-30 15:29:45 +08:00
|
|
|
current_user: current_user)
|
|
|
|
team_service.change_current_team!
|
|
|
|
success_response('/client_api/teams/index', team_service.teams_data)
|
2017-08-30 22:18:21 +08:00
|
|
|
rescue ClientApi::CustomTeamError
|
2017-08-30 15:29:45 +08:00
|
|
|
error_response
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def success_response(template, locals)
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render template: template,
|
|
|
|
status: :ok,
|
|
|
|
locals: locals
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def error_response
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2017-08-30 22:18:21 +08:00
|
|
|
render json: { message: 'Bad boy!' }, status: :unprocessable_entity
|
2017-08-30 15:29:45 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|