From 4bf330f82495f9818b367b5aec1b9867dd4f39f3 Mon Sep 17 00:00:00 2001 From: Tsanie Lily Date: Mon, 26 Jun 2023 22:33:44 +0800 Subject: [PATCH] sync code --- App/Constants.cs | 2 + App/Data/FlowerDatabase.cs | 4 +- App/Data/Model/FlowerItem.cs | 10 +- App/Data/Model/PhotoItem.cs | 28 + App/Data/Model/RecordItem.cs | 14 +- App/Data/Model/UserItem.cs | 11 +- App/Extensions.cs | 36 + App/FlowerStory.csproj | 20 +- App/Localizations.Designer.cs | 72 + App/Localizations.resx | 123 ++ App/Localizations.zh-CN.resx | 123 ++ App/MainPage.xaml | 6 +- App/MainPage.xaml.cs | 5 + App/MauiProgram.cs | 2 + Server/Controller/BaseController.cs | 4 +- Server/Controller/BaseController.result.cs | 87 + Server/Controller/EventApiController.cs | 7 +- Server/Controller/FlowerApiController.cs | 248 ++- .../Controller/FlowerApiController.structs.cs | 15 +- Server/Controller/ImageController.cs | 35 +- Server/Controller/SwaggerController.cs | 35 +- Server/Controller/UserApiController.cs | 3 + Server/Data/Model/PhotoItem.cs | 3 + Server/Program.cs | 5 +- Server/Properties/launchSettings.json | 2 +- Server/wwwroot/js/redoc.standalone.js | 1806 +++++++++++++++++ 26 files changed, 2644 insertions(+), 62 deletions(-) create mode 100644 App/Data/Model/PhotoItem.cs create mode 100644 App/Extensions.cs create mode 100644 App/Localizations.Designer.cs create mode 100644 App/Localizations.resx create mode 100644 App/Localizations.zh-CN.resx create mode 100644 Server/Controller/BaseController.result.cs create mode 100644 Server/wwwroot/js/redoc.standalone.js diff --git a/App/Constants.cs b/App/Constants.cs index 893fc3f..efc9eff 100644 --- a/App/Constants.cs +++ b/App/Constants.cs @@ -5,6 +5,8 @@ public sealed class Constants public const string CategoryOther = "other"; public const string EventUnknown = "unknown"; + public const string BaseUrl = "https://flower.tsanie.org"; + public const SQLite.SQLiteOpenFlags Flags = SQLite.SQLiteOpenFlags.ReadWrite | SQLite.SQLiteOpenFlags.Create | diff --git a/App/Data/FlowerDatabase.cs b/App/Data/FlowerDatabase.cs index 1aaa4d0..aaa9b33 100644 --- a/App/Data/FlowerDatabase.cs +++ b/App/Data/FlowerDatabase.cs @@ -26,12 +26,12 @@ public class FlowerDatabase #if DEBUG var result = #endif - await database.CreateTablesAsync(); + await database.CreateTablesAsync(); #if DEBUG foreach (var item in result.Results) { - logger.LogDebug("create table {table}, result: {result}", item.Key, item.Value); + logger.LogInformation("create table {table}, result: {result}", item.Key, item.Value); } #endif } diff --git a/App/Data/Model/FlowerItem.cs b/App/Data/Model/FlowerItem.cs index 61e5e0f..408eb7c 100644 --- a/App/Data/Model/FlowerItem.cs +++ b/App/Data/Model/FlowerItem.cs @@ -18,11 +18,11 @@ public class FlowerItem { if (categoryName == null) { - if (!Constants.Categories.TryGetValue(CategoryId, out categoryName)) + if (!Constants.Categories.TryGetValue(CategoryId, out var name)) { - categoryName = Constants.CategoryOther; + name = Constants.CategoryOther; } - // TODO: i18n + categoryName = LocalizationResource.GetText(name); } return categoryName; } @@ -40,6 +40,6 @@ public class FlowerItem [Column("purchase")] public string Purchase { get; set; } - [Column("photo")] - public byte[] Photo { get; set; } + [Column("memo")] + public string Memo { get; set; } } diff --git a/App/Data/Model/PhotoItem.cs b/App/Data/Model/PhotoItem.cs new file mode 100644 index 0000000..ca46aeb --- /dev/null +++ b/App/Data/Model/PhotoItem.cs @@ -0,0 +1,28 @@ +using SQLite; + +namespace Blahblah.FlowerStory.Data.Model; + +[Table("photos")] +public class PhotoItem +{ + [Column("pid"), PrimaryKey, AutoIncrement] + public int Id { get; set; } + + [Column("fid")] + public int FlowerId { get; set; } + + [Column("rid")] + public int RecordId { get; set; } + + [Column("filetype")] + public string FileType { get; set; } + + [Column("filename")] + public string FileName { get; set; } + + [Column("path")] + public string Path { get; set; } + + [Column("dateupload")] + public DateTimeOffset DateUpload { get; set; } +} diff --git a/App/Data/Model/RecordItem.cs b/App/Data/Model/RecordItem.cs index 196fe54..742d2ba 100644 --- a/App/Data/Model/RecordItem.cs +++ b/App/Data/Model/RecordItem.cs @@ -8,6 +8,9 @@ public class RecordItem [Column("rid"), PrimaryKey, AutoIncrement] public int Id { get; set; } + [Column("fid")] + public int FlowerId { get; set; } + [Column("eid")] public int EventId { get; set; } @@ -18,15 +21,16 @@ public class RecordItem { if (eventName == null) { + string evtkey; if (Constants.Events.TryGetValue(EventId, out var @event)) { - eventName = @event.Name; + evtkey = @event.Name; } else { - eventName = Constants.EventUnknown; + evtkey = Constants.EventUnknown; } - // TODO: i18n + eventName = LocalizationResource.GetText(evtkey); } return eventName; } @@ -41,6 +45,6 @@ public class RecordItem [Column("byname")] public string ByUserName { get; set; } - [Column("photo")] - public byte[] Photo { get; set; } + [Column("memo")] + public string Memo { get; set; } } diff --git a/App/Data/Model/UserItem.cs b/App/Data/Model/UserItem.cs index 17a5b71..0638988 100644 --- a/App/Data/Model/UserItem.cs +++ b/App/Data/Model/UserItem.cs @@ -2,10 +2,19 @@ public class UserItem { - public string Id { get; set; } + public int Id { get; set; } + + public string UserId { get; set; } + public int Level { get; set; } + public DateTimeOffset RegisterDate { get; set; } + public string Name { get; set; } + public string Email { get; set; } + public string Mobile { get; set; } + + public byte[] Avatar { get; set; } } diff --git a/App/Extensions.cs b/App/Extensions.cs new file mode 100644 index 0000000..742a2a2 --- /dev/null +++ b/App/Extensions.cs @@ -0,0 +1,36 @@ +using Microsoft.Extensions.Localization; +using System.Text; + +namespace Blahblah.FlowerStory; + +[ContentProperty(nameof(Key))] +public class LocalizeExtension : IMarkupExtension +{ + //private IStringLocalizer Localizer { get; } + + public string Key { get; set; } + + //public LocalizeExtension() + //{ + // Localizer = MauiApplication.Current.Services.GetService>(); + //} + + public object ProvideValue(IServiceProvider _) + { + return LocalizationResource.Localizer.GetString(Key); + } + + object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) => ProvideValue(serviceProvider); +} + +sealed class LocalizationResource +{ + private static IStringLocalizer localizer; + + public static IStringLocalizer Localizer => localizer ??= MauiApplication.Current.Services.GetService>(); + + public static string GetText(string key) + { + return Localizer.GetString(key); + } +} diff --git a/App/FlowerStory.csproj b/App/FlowerStory.csproj index 42d7ff7..3b86351 100644 --- a/App/FlowerStory.csproj +++ b/App/FlowerStory.csproj @@ -70,8 +70,26 @@ + + + - + + + + + + True + True + Localizations.resx + + + + + + ResXFileCodeGenerator + Localizations.Designer.cs + diff --git a/App/Localizations.Designer.cs b/App/Localizations.Designer.cs new file mode 100644 index 0000000..77b7667 --- /dev/null +++ b/App/Localizations.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Blahblah.FlowerStory { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Localizations { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Localizations() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Blahblah.FlowerStory.Localizations", typeof(Localizations).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Unknown. + /// + internal static string unknown { + get { + return ResourceManager.GetString("unknown", resourceCulture); + } + } + } +} diff --git a/App/Localizations.resx b/App/Localizations.resx new file mode 100644 index 0000000..769ce41 --- /dev/null +++ b/App/Localizations.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Unknown + + \ No newline at end of file diff --git a/App/Localizations.zh-CN.resx b/App/Localizations.zh-CN.resx new file mode 100644 index 0000000..e094abf --- /dev/null +++ b/App/Localizations.zh-CN.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 未知 + + \ No newline at end of file diff --git a/App/MainPage.xaml b/App/MainPage.xaml index 09dda56..0c38c9a 100644 --- a/App/MainPage.xaml +++ b/App/MainPage.xaml @@ -1,6 +1,8 @@  @@ -15,8 +17,10 @@ HeightRequest="200" HorizontalOptions="Center" /> + +