This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
torresed
committed
Feb 18, 2021
1 parent
35388e9
commit bcca1f4
Showing
11 changed files
with
94 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
class PartiesController < ApplicationController | ||
before_action :check_token, :users | ||
skip_before_action :users, only: %i[show] | ||
|
||
def show | ||
@user = current_user | ||
end | ||
|
||
def create | ||
@member = Friends.find_by(sent_by: current_user, sent_to: @friend, status: :confirmed) | ||
if @member.nil? || @member.invited? || current_user.party_members.count >= 2 | ||
render status: :bad_request, json: { error: 'Friend could not be invited.' } | ||
else | ||
@member.invited! | ||
render status: :ok, json: { success: 'Friend has been invited.' } | ||
end | ||
end | ||
|
||
def update | ||
@member = Friends.find_by(sent_by: @friend, sent_to: current_user, status: :confirmed) | ||
if @member.nil? || !@member.invited? || @member.party_members.count >= 2 | ||
render status: :bad_request, json: { error: 'Invitation could not be accepted.' } | ||
else | ||
@member.accepted! | ||
render status: :ok, json: { success: 'Invitation accepted.' } | ||
end | ||
end | ||
|
||
def kick | ||
@member = Friends.find_by(sent_by: current_user, sent_to: @friend, status: :confirmed) | ||
if @member.nil? || !@member.accepted? | ||
render status: :bad_request, json: { error: 'Friend could not be kicked.' } | ||
else | ||
@member.unsolicited! | ||
render status: :ok, json: { success: 'Friend has been kicked.' } | ||
end | ||
end | ||
|
||
def destroy | ||
current_user.party_members.destroy | ||
current_user.invitations.destroy | ||
render status: :ok, json: { success: 'Party has been disbanded.' } | ||
end | ||
|
||
private | ||
|
||
def members | ||
@user = current_user | ||
head :bad_request unless (@friend = User.find_by(id: params[:id])) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
json.id @user.id.to_s | ||
json.extract! @user, :username | ||
|
||
json.invitations_pending do | ||
json.array! @user.invitations_pending, :username | ||
end | ||
|
||
json.invitations_received do | ||
json.array! @user.invitations_received, :username | ||
end | ||
|
||
json.party do | ||
json.array! @user.party_members, :username | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.