Adding AR folder
This commit is contained in:
parent
e56b92aa7b
commit
781c1b4097
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.idea
|
3
AR.meta
Normal file
3
AR.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19cf999df50c445ba3c964510468fb8d
|
||||
timeCreated: 1679395580
|
36
AR/PocketBaseDataRepository.cs
Normal file
36
AR/PocketBaseDataRepository.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using models;
|
||||
using services;
|
||||
using UnityEngine;
|
||||
|
||||
public class PocketBaseDataRepository : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] public String userToken;
|
||||
[SerializeField] public Trash[] trashes;
|
||||
|
||||
void Start()
|
||||
{
|
||||
LoginResponse res = UserService.Login(new LoginRequest("************", "**********"));
|
||||
this.userToken = res.token;
|
||||
|
||||
TrashList list = TrashService.ListTrash(this.userToken);
|
||||
foreach (Trash trash in list.items)
|
||||
{
|
||||
Debug.Log(trash.id);
|
||||
DataList trashData = TrashService.ListTrashData(userToken, trash.id);
|
||||
trash.data = trashData.items;
|
||||
}
|
||||
this.trashes = list.items;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
AR/PocketBaseDataRepository.cs.meta
Normal file
11
AR/PocketBaseDataRepository.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a652d58e66666249a20951649c4ddcd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3
AR/models.meta
Normal file
3
AR/models.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff3b95e251e446dcabc742a9dac256cd
|
||||
timeCreated: 1679384952
|
29
AR/models/Data.cs
Normal file
29
AR/models/Data.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace models
|
||||
{
|
||||
[Serializable]
|
||||
public class Data
|
||||
{
|
||||
public String id;
|
||||
public String collectionId;
|
||||
public String collectionName;
|
||||
public DateTime created;
|
||||
public DateTime updated;
|
||||
public int value;
|
||||
public String trash_id;
|
||||
public String unit;
|
||||
public Boolean status;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class DataList
|
||||
{
|
||||
public int page;
|
||||
public int perPage;
|
||||
public int totalPages;
|
||||
public int totalItems;
|
||||
public List<Data> items;
|
||||
}
|
||||
}
|
3
AR/models/Data.cs.meta
Normal file
3
AR/models/Data.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9c778b8c2f64792bbbb0aac4cbe431c
|
||||
timeCreated: 1679392634
|
41
AR/models/LoginDto.cs
Normal file
41
AR/models/LoginDto.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace models
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class LoginRequest
|
||||
{
|
||||
public String identity;
|
||||
public String password;
|
||||
|
||||
public LoginRequest(string identity, string password)
|
||||
{
|
||||
this.identity = identity;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LoginResponse
|
||||
{
|
||||
public Record record;
|
||||
public string token;
|
||||
|
||||
[Serializable]
|
||||
public class Record
|
||||
{
|
||||
public string avatar;
|
||||
public string collectionId;
|
||||
public string collectionName;
|
||||
public string created;
|
||||
public string email;
|
||||
public bool emailVisibility;
|
||||
public string id;
|
||||
public string name;
|
||||
public string updated;
|
||||
public string username;
|
||||
public bool verified;
|
||||
}
|
||||
}
|
||||
}
|
3
AR/models/LoginDto.cs.meta
Normal file
3
AR/models/LoginDto.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb7db611010e4a4ea253408f8f639da1
|
||||
timeCreated: 1679384960
|
27
AR/models/Trash.cs
Normal file
27
AR/models/Trash.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace models
|
||||
{
|
||||
[Serializable]
|
||||
public class Trash
|
||||
{
|
||||
public string collectionId;
|
||||
public string collectionName;
|
||||
public string created;
|
||||
public string id;
|
||||
public string owner;
|
||||
public string updated;
|
||||
public List<Data> data;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class TrashList
|
||||
{
|
||||
public int page;
|
||||
public int perPage;
|
||||
public int totalItems;
|
||||
public int totalPages;
|
||||
public Trash[] items;
|
||||
}
|
||||
}
|
3
AR/models/Trash.cs.meta
Normal file
3
AR/models/Trash.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d491b601d266438383bff39599d5b2a1
|
||||
timeCreated: 1679385878
|
3
AR/services.meta
Normal file
3
AR/services.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c41af40269c84848a424cee12b7bfd14
|
||||
timeCreated: 1679386050
|
27
AR/services/TrashService.cs
Normal file
27
AR/services/TrashService.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using models;
|
||||
using UnityEngine;
|
||||
using utils;
|
||||
|
||||
namespace services
|
||||
{
|
||||
public class TrashService
|
||||
{
|
||||
public static Trash GetTrash(String token, String id)
|
||||
{
|
||||
return Api<Trash>.get("/api/collections/trashs/records/"+id, token);
|
||||
}
|
||||
|
||||
public static TrashList ListTrash(String token)
|
||||
{
|
||||
return Api<TrashList>.get("/api/collections/trashs/records/", token);
|
||||
}
|
||||
|
||||
public static DataList ListTrashData(String token, String trashId)
|
||||
{
|
||||
return Api<DataList>.get("/api/collections/data/records/?trash_id="+trashId, token);
|
||||
}
|
||||
}
|
||||
}
|
3
AR/services/TrashService.cs.meta
Normal file
3
AR/services/TrashService.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a5bdf680ce94648aac43fe3f9a29e98
|
||||
timeCreated: 1679386057
|
15
AR/services/UserService.cs
Normal file
15
AR/services/UserService.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using models;
|
||||
using UnityEngine;
|
||||
using utils;
|
||||
|
||||
namespace services
|
||||
{
|
||||
public class UserService
|
||||
{
|
||||
public static LoginResponse Login(LoginRequest request)
|
||||
{
|
||||
var response = Api<LoginResponse>.post("/api/collections/users/auth-with-password", JsonUtility.ToJson(request));
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
3
AR/services/UserService.cs.meta
Normal file
3
AR/services/UserService.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fe63392645946c48c112658ebbf75c5
|
||||
timeCreated: 1679389336
|
3
AR/utils.meta
Normal file
3
AR/utils.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f953923e9fca40ea897097feb7aa9dc0
|
||||
timeCreated: 1679386094
|
58
AR/utils/Api.cs
Normal file
58
AR/utils/Api.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using models;
|
||||
using UnityEngine;
|
||||
|
||||
namespace utils
|
||||
{
|
||||
public class Api<T>
|
||||
{
|
||||
public static String API_URL = "https://iot.epi.cb85.software";
|
||||
public static int API_TIMEOUT = 10000;
|
||||
|
||||
public static HttpWebRequest createClient(String suffix) {
|
||||
return (HttpWebRequest)WebRequest.Create(API_URL + suffix);
|
||||
}
|
||||
|
||||
public static T get(String suffix, String token)
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(API_URL + suffix);
|
||||
request.Accept = "application/json";
|
||||
request.Method = "GET";
|
||||
request.Headers.Add("Authorization", token);
|
||||
request.Timeout=API_TIMEOUT;
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
if (response == null)
|
||||
{
|
||||
throw new Exception("Response is null");
|
||||
}
|
||||
StreamReader reader = new StreamReader(response.GetResponseStream());
|
||||
string jsonResponse = reader.ReadToEnd();
|
||||
T responseData = JsonUtility.FromJson<T>(jsonResponse);
|
||||
response.Close();
|
||||
return responseData;
|
||||
}
|
||||
|
||||
public static T post(String suffix, String body)
|
||||
{
|
||||
HttpWebRequest request = createClient(suffix);
|
||||
request.ContentType = "application/json";
|
||||
request.Method = "POST";
|
||||
request.Timeout=API_TIMEOUT;
|
||||
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
|
||||
{
|
||||
streamWriter.Write(body);
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
}
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
StreamReader reader = new StreamReader(response.GetResponseStream());
|
||||
string jsonResponse = reader.ReadToEnd();
|
||||
T responseData = JsonUtility.FromJson<T>(jsonResponse);
|
||||
response.Close();
|
||||
return responseData;
|
||||
}
|
||||
}
|
||||
}
|
3
AR/utils/Api.cs.meta
Normal file
3
AR/utils/Api.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1294827371cd4417aaab68f1c6736e6d
|
||||
timeCreated: 1679386098
|
Loading…
x
Reference in New Issue
Block a user