Created project architecture
This commit is contained in:
commit
4c873d4d09
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.idea
|
26
PocketBaseDataRepository.cs
Normal file
26
PocketBaseDataRepository.cs
Normal file
@ -0,0 +1,26 @@
|
||||
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
|
||||
{
|
||||
|
||||
void Start()
|
||||
{
|
||||
Trash t = TrashService.GetTrash("gdnuxl0wlgurtj3");
|
||||
Debug.Log(t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
PocketBaseDataRepository.cs.meta
Normal file
11
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
models.meta
Normal file
3
models.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff3b95e251e446dcabc742a9dac256cd
|
||||
timeCreated: 1679384952
|
34
models/LoginDto.cs
Normal file
34
models/LoginDto.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
|
||||
namespace models
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class LoginRequest
|
||||
{
|
||||
public String username;
|
||||
public String password;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class LoginResponse
|
||||
{
|
||||
public Record record { get; set; }
|
||||
public string token { get; set; }
|
||||
|
||||
public class Record
|
||||
{
|
||||
public string avatar { get; set; }
|
||||
public string collectionId { get; set; }
|
||||
public string collectionName { get; set; }
|
||||
public string created { get; set; }
|
||||
public string email { get; set; }
|
||||
public bool emailVisibility { get; set; }
|
||||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string updated { get; set; }
|
||||
public string username { get; set; }
|
||||
public bool verified { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
3
models/LoginDto.cs.meta
Normal file
3
models/LoginDto.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb7db611010e4a4ea253408f8f639da1
|
||||
timeCreated: 1679384960
|
19
models/Trash.cs
Normal file
19
models/Trash.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace models
|
||||
{
|
||||
[Serializable]
|
||||
public class Trash
|
||||
{
|
||||
public String id;
|
||||
public String collectionId;
|
||||
public String collectionName;
|
||||
public DateTime created;
|
||||
public DateTime updated;
|
||||
public Int16 value;
|
||||
public String trash_id;
|
||||
public String unit;
|
||||
public Boolean status;
|
||||
public String field;
|
||||
}
|
||||
}
|
3
models/Trash.cs.meta
Normal file
3
models/Trash.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d491b601d266438383bff39599d5b2a1
|
||||
timeCreated: 1679385878
|
3
services.meta
Normal file
3
services.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c41af40269c84848a424cee12b7bfd14
|
||||
timeCreated: 1679386050
|
17
services/TrashService.cs
Normal file
17
services/TrashService.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using models;
|
||||
using UnityEngine;
|
||||
using utils;
|
||||
|
||||
namespace services
|
||||
{
|
||||
public class TrashService
|
||||
{
|
||||
public static Trash GetTrash(String id)
|
||||
{
|
||||
return Api<Trash>.get("/api/collections/trashs/records/"+id);
|
||||
}
|
||||
}
|
||||
}
|
3
services/TrashService.cs.meta
Normal file
3
services/TrashService.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a5bdf680ce94648aac43fe3f9a29e98
|
||||
timeCreated: 1679386057
|
3
utils.meta
Normal file
3
utils.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f953923e9fca40ea897097feb7aa9dc0
|
||||
timeCreated: 1679386094
|
65
utils/Api.cs
Normal file
65
utils/Api.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using models;
|
||||
using UnityEngine;
|
||||
|
||||
namespace utils
|
||||
{
|
||||
public class Api<T>
|
||||
{
|
||||
public static String API_URL = "https://iot.epi.cb85.software";
|
||||
|
||||
public static HttpWebRequest createClient(String suffix) {
|
||||
return (HttpWebRequest)WebRequest.Create(API_URL + suffix);
|
||||
}
|
||||
|
||||
public static T get(String suffix)
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(API_URL + suffix);
|
||||
request.Accept = "application/json";
|
||||
request.Method = "POST";
|
||||
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);
|
||||
return responseData;
|
||||
}
|
||||
|
||||
public static T post(String suffix, String body)
|
||||
{
|
||||
HttpWebRequest request = createClient(suffix);
|
||||
request.ContentType = "application/json";
|
||||
request.Method = "POST";
|
||||
request.Accept = "application/json";
|
||||
|
||||
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
|
||||
{
|
||||
streamWriter.Write(body);
|
||||
}
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
StreamReader reader = new StreamReader(response.GetResponseStream());
|
||||
string jsonResponse = reader.ReadToEnd();
|
||||
T responseData = JsonUtility.FromJson<T>(jsonResponse);
|
||||
return responseData;
|
||||
}
|
||||
|
||||
public T send(HttpWebRequest request)
|
||||
{
|
||||
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);
|
||||
return responseData;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
3
utils/Api.cs.meta
Normal file
3
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