change app directory
This commit is contained in:
19
FlowerApp/Data/Constants.cs
Normal file
19
FlowerApp/Data/Constants.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using SQLite;
|
||||
|
||||
namespace Blahblah.FlowerApp.Data;
|
||||
|
||||
public sealed class Constants
|
||||
{
|
||||
public const string CategoryOther = "other";
|
||||
public const string EventUnknown = "unknown";
|
||||
|
||||
public const string BaseUrl = "https://flower.tsanie.org";
|
||||
|
||||
public const SQLiteOpenFlags SQLiteFlags =
|
||||
SQLiteOpenFlags.ReadWrite |
|
||||
SQLiteOpenFlags.Create |
|
||||
SQLiteOpenFlags.SharedCache;
|
||||
|
||||
private const string dbFilename = "flowerstory.db3";
|
||||
public static string DatabasePath => Path.Combine(FileSystem.AppDataDirectory, dbFilename);
|
||||
}
|
45
FlowerApp/Data/FlowerDatabase.cs
Normal file
45
FlowerApp/Data/FlowerDatabase.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Blahblah.FlowerApp.Data.Model;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SQLite;
|
||||
|
||||
namespace Blahblah.FlowerApp.Data;
|
||||
|
||||
public class FlowerDatabase
|
||||
{
|
||||
private SQLiteAsyncConnection database = null!;
|
||||
|
||||
private readonly ILogger logger;
|
||||
|
||||
public FlowerDatabase(ILogger<FlowerDatabase> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
private async Task Init()
|
||||
{
|
||||
if (database is not null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
database = new SQLiteAsyncConnection(Constants.DatabasePath, Constants.SQLiteFlags);
|
||||
|
||||
#if DEBUG
|
||||
var result =
|
||||
#endif
|
||||
await database.CreateTablesAsync<FlowerItem, RecordItem, PhotoItem, UserItem>();
|
||||
|
||||
#if DEBUG
|
||||
foreach (var item in result.Results)
|
||||
{
|
||||
logger.LogInformation("create table {table}, result: {result}", item.Key, item.Value);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public async Task<FlowerItem[]> GetFlowers()
|
||||
{
|
||||
await Init();
|
||||
return await database.Table<FlowerItem>().ToArrayAsync();
|
||||
}
|
||||
}
|
41
FlowerApp/Data/Model/FlowerItem.cs
Normal file
41
FlowerApp/Data/Model/FlowerItem.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using SQLite;
|
||||
|
||||
namespace Blahblah.FlowerApp.Data.Model;
|
||||
|
||||
[Table("flowers")]
|
||||
public class FlowerItem
|
||||
{
|
||||
[Column("fid"), PrimaryKey, NotNull]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("uid"), NotNull]
|
||||
public int OwnerId { get; set; }
|
||||
|
||||
[Column("category"), NotNull]
|
||||
public int Category { get; set; }
|
||||
|
||||
[Column("Name"), NotNull]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[Column("datebuy"), NotNull]
|
||||
public long DateBuyUnixTime { get; set; }
|
||||
|
||||
public DateTimeOffset DateBuy => DateTimeOffset.FromUnixTimeMilliseconds(DateBuyUnixTime);
|
||||
|
||||
[Column("cost")]
|
||||
public decimal? Cost { get; set; }
|
||||
|
||||
[Column("purchase")]
|
||||
public string? PurchaseFrom { get; set; }
|
||||
|
||||
[Column("memo")]
|
||||
public string? Memo { get; set; }
|
||||
|
||||
[Column("latitude")]
|
||||
public double? Latitude { get; set; }
|
||||
|
||||
[Column("longitude")]
|
||||
public double? Longitude { get; set; }
|
||||
|
||||
public int? Distance { get; set; }
|
||||
}
|
36
FlowerApp/Data/Model/PhotoItem.cs
Normal file
36
FlowerApp/Data/Model/PhotoItem.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using SQLite;
|
||||
|
||||
namespace Blahblah.FlowerApp.Data.Model;
|
||||
|
||||
[Table("photos")]
|
||||
public class PhotoItem
|
||||
{
|
||||
[Column("pid"), PrimaryKey, NotNull]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("uid"), NotNull]
|
||||
public int OwnerId { get; set; }
|
||||
|
||||
[Column("fid"), NotNull]
|
||||
public int FlowerId { get; set; }
|
||||
|
||||
[Column("rid"), NotNull]
|
||||
public int RecordId { get; set; }
|
||||
|
||||
[Column("filetype"), NotNull]
|
||||
public string FileType { get; set; } = null!;
|
||||
|
||||
[Column("filename"), NotNull]
|
||||
public string FileName { get; set; } = null!;
|
||||
|
||||
[Column("path"), NotNull]
|
||||
public string Path { get; set; } = null!;
|
||||
|
||||
[Column("dateupload"), NotNull]
|
||||
public long DateUploadUnixTime { get; set; }
|
||||
|
||||
public DateTimeOffset DateUpload => DateTimeOffset.FromUnixTimeMilliseconds(DateUploadUnixTime);
|
||||
|
||||
[Column("url")]
|
||||
public string Url { get; set; } = null!;
|
||||
}
|
38
FlowerApp/Data/Model/RecordItem.cs
Normal file
38
FlowerApp/Data/Model/RecordItem.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using SQLite;
|
||||
|
||||
namespace Blahblah.FlowerApp.Data.Model;
|
||||
|
||||
public class RecordItem
|
||||
{
|
||||
[Column("rid"), PrimaryKey, NotNull]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("uid"), NotNull]
|
||||
public int OwnerId { get; set; }
|
||||
|
||||
[Column("fid"), NotNull]
|
||||
public int FlowerId { get; set; }
|
||||
|
||||
[Column("event"), NotNull]
|
||||
public int EventType { get; set; }
|
||||
|
||||
[Column("date"), NotNull]
|
||||
public long DateUnixTime { get; set; }
|
||||
|
||||
public DateTimeOffset Date => DateTimeOffset.FromUnixTimeMilliseconds(DateUnixTime);
|
||||
|
||||
[Column("byuid")]
|
||||
public int? ByUserId { get; set; }
|
||||
|
||||
[Column("byname")]
|
||||
public string? ByUserName { get; set; }
|
||||
|
||||
[Column("memo")]
|
||||
public string? Memo { get; set; }
|
||||
|
||||
[Column("latitude")]
|
||||
public double? Latitude { get; set; }
|
||||
|
||||
[Column("longitude")]
|
||||
public double? Longitude { get; set; }
|
||||
}
|
40
FlowerApp/Data/Model/UserItem.cs
Normal file
40
FlowerApp/Data/Model/UserItem.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using SQLite;
|
||||
|
||||
namespace Blahblah.FlowerApp.Data.Model;
|
||||
|
||||
public class UserItem
|
||||
{
|
||||
[Column("uid"), PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("id"), NotNull]
|
||||
public string UserId { get; set; } = null!;
|
||||
|
||||
[Column("token"), NotNull]
|
||||
public string Token { get; set; } = null!;
|
||||
|
||||
[Column("name"), NotNull]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[Column("level"), NotNull]
|
||||
public int Level { get; set; }
|
||||
|
||||
[Column("regdate"), NotNull]
|
||||
public long RegisterDateUnixTime { get; set; }
|
||||
|
||||
public DateTimeOffset RegisterDate => DateTimeOffset.FromUnixTimeMilliseconds(RegisterDateUnixTime);
|
||||
|
||||
//[Column("activedate")]
|
||||
//public long? ActiveDateUnixTime { get; set; }
|
||||
|
||||
//public DateTimeOffset? ActiveDate => ActiveDateUnixTime == null ? null : DateTimeOffset.FromUnixTimeMilliseconds(ActiveDateUnixTime.Value);
|
||||
|
||||
[Column("email")]
|
||||
public string? Email { get; set; }
|
||||
|
||||
[Column("mobile")]
|
||||
public string? Mobile { get; set; }
|
||||
|
||||
[Column("avatar")]
|
||||
public byte[]? Avatar { get; set; }
|
||||
}
|
Reference in New Issue
Block a user