Created project architecture

This commit is contained in:
Nicolas SANS 2023-03-21 09:59:44 +01:00
commit 4c873d4d09
14 changed files with 194 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View 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()
{
}
}

View 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
View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ff3b95e251e446dcabc742a9dac256cd
timeCreated: 1679384952

34
models/LoginDto.cs Normal file
View 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
View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bb7db611010e4a4ea253408f8f639da1
timeCreated: 1679384960

19
models/Trash.cs Normal file
View 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
View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d491b601d266438383bff39599d5b2a1
timeCreated: 1679385878

3
services.meta Normal file
View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c41af40269c84848a424cee12b7bfd14
timeCreated: 1679386050

17
services/TrashService.cs Normal file
View 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);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5a5bdf680ce94648aac43fe3f9a29e98
timeCreated: 1679386057

3
utils.meta Normal file
View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f953923e9fca40ea897097feb7aa9dc0
timeCreated: 1679386094

65
utils/Api.cs Normal file
View 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
View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1294827371cd4417aaab68f1c6736e6d
timeCreated: 1679386098