-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #773 from bounswe/mobile/user-controller-endpoints
Created UserActions & Modified UserController & DeleteAccount
- Loading branch information
Showing
4 changed files
with
95 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Collections; | ||
using System.Text; | ||
using UnityEngine; | ||
using UnityEngine.Networking; | ||
using Newtonsoft.Json; | ||
|
||
public class UserActions : MonoBehaviour | ||
{ | ||
|
||
public void ChangeUserRole(UserChangeRoleRequest request) | ||
{ | ||
string url = AppVariables.HttpServerUrl + "/user/change-role"; | ||
string bodyJsonString = JsonConvert.SerializeObject(request); | ||
StartCoroutine(Post(url, bodyJsonString)); | ||
} | ||
|
||
public void GetAllUsers(UserGetAllRequest request) | ||
{ | ||
string url = AppVariables.HttpServerUrl + "/user/get-all" + | ||
ListToQueryParameters.ListToQueryParams(new[] {"id", "username", "isDeleted"}, | ||
new[] {request.id, request.username, request.isDeleted.ToString()}); | ||
StartCoroutine(Get(url)); | ||
} | ||
|
||
public void DeleteUser(UserDeleteRequest request) | ||
{ | ||
string url = AppVariables.HttpServerUrl + "/user/delete?id=" + request.id; | ||
StartCoroutine(Delete(url)); | ||
} | ||
|
||
IEnumerator Get(string url) | ||
{ | ||
var request = new UnityWebRequest(url, "GET"); | ||
request.downloadHandler = new DownloadHandlerBuffer(); | ||
request.SetRequestHeader("Content-Type", "application/json"); | ||
yield return request.SendWebRequest(); | ||
} | ||
|
||
IEnumerator Post(string url, string bodyJsonString) | ||
{ | ||
var request = new UnityWebRequest(url, "POST"); | ||
byte[] bodyRaw = Encoding.UTF8.GetBytes(bodyJsonString); | ||
request.uploadHandler = new UploadHandlerRaw(bodyRaw); | ||
request.downloadHandler = new DownloadHandlerBuffer(); | ||
request.SetRequestHeader("Content-Type", "application/json"); | ||
yield return request.SendWebRequest(); | ||
// Handle the response | ||
} | ||
|
||
IEnumerator Delete(string url) | ||
{ | ||
var request = new UnityWebRequest(url, "DELETE"); | ||
request.downloadHandler = new DownloadHandlerBuffer(); | ||
request.SetRequestHeader("Content-Type", "application/json"); | ||
yield return request.SendWebRequest(); | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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