Add route for viewing a profile

This commit is contained in:
Justin Edmund 2020-09-25 14:59:50 -07:00
parent 10cca8e4b0
commit 71a0a090ba
3 changed files with 22 additions and 0 deletions

View file

@ -1,6 +1,8 @@
class Api::V1::UsersController < Api::V1::ApiController
class ForbiddenError < StandardError; end
before_action :set, except: ['create', 'check_email', 'check_username']
def create
@user = User.new(user_params)
@ -22,6 +24,11 @@ class Api::V1::UsersController < Api::V1::ApiController
end
end
def show
@parties = @user.parties
ap "Hello world"
end
def check_email
if params[:email].present?
@available = User.where("email = ?", params[:email]).count == 0
@ -43,6 +50,7 @@ class Api::V1::UsersController < Api::V1::ApiController
end
def show
@parties = @user.parties
end
def update
@ -54,6 +62,10 @@ class Api::V1::UsersController < Api::V1::ApiController
private
# Specify whitelisted properties that can be modified.
def set
@user = User.where("username = ?", params[:id]).first
end
def user_params
params.require(:user).permit(:username, :email, :password, :password_confirmation, :granblue_id)
end

View file

@ -1,6 +1,9 @@
class User < ApplicationRecord
before_save { self.email = email.downcase }
##### ActiveRecord Associations
has_many :parties
##### ActiveRecord Validations
validates :username,
presence: true,

View file

@ -0,0 +1,7 @@
object @user
extends 'api/v1/users/base'
node(:parties) {
partial('parties/base', object: @parties)
} unless @parties.empty?