2018-08-24 17:26:49 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-31 19:40:27 +08:00
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class TeamsController < BaseController
|
|
|
|
before_action :load_team, only: :show
|
|
|
|
|
|
|
|
def index
|
2018-08-24 17:26:49 +08:00
|
|
|
teams = current_user.teams
|
|
|
|
.page(params.dig(:page, :number))
|
|
|
|
.per(params.dig(:page, :size))
|
2018-08-23 22:48:27 +08:00
|
|
|
render jsonapi: teams, each_serializer: TeamSerializer
|
2018-07-31 19:40:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2018-10-06 18:18:57 +08:00
|
|
|
render jsonapi: @team,
|
|
|
|
serializer: TeamSerializer,
|
|
|
|
include: :created_by
|
2018-07-31 19:40:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_team
|
|
|
|
@team = Team.find(params.require(:id))
|
2018-08-24 17:26:49 +08:00
|
|
|
render jsonapi: {}, status: :forbidden unless can_read_team?(@team)
|
2018-07-31 19:40:27 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|