T-DEV-811/AR/Assets/PocketBaseDataProvider.cs

47 lines
1.3 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using models;
using UnityEngine;
using CandyCoded.env;
using services;
public class PocketBaseDataProvider : MonoBehaviour
{
[SerializeField] public String userToken = null;
[SerializeField] public static List<Trash> trashes = new List<Trash>();
[SerializeField] public float timeBetweenUpdate = 10f;
private float currentCountdown;
private void Start()
{
this.currentCountdown = this.timeBetweenUpdate;
env.TryParseEnvironmentVariable("API_USER", out string user);
env.TryParseEnvironmentVariable("API_PASSWORD", out string password);
LoginResponse res = UserService.Login(new LoginRequest(user, password));
userToken = res.token;
this.UpdateData();
}
void Update()
{
this.currentCountdown -= Time.deltaTime;
if (this.currentCountdown <= 0)
{
this.currentCountdown = this.timeBetweenUpdate;
this.UpdateData();
}
}
void UpdateData()
{
TrashList list = TrashService.ListTrash(userToken);
foreach (Trash trash in list.items)
{
DataList trashData = TrashService.ListTrashData(userToken, trash.id);
trash.data = trashData.items;
}
trashes = list.items.ToList();
}
}