commit 5800f7167bc65e42d2bff44368efad12cf76374f Author: zhangyousheng Date: Sat Jul 29 00:59:17 2023 +0800 feat: 项目初始化并添加数据库使用 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cd967fc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19ac9c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,341 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Mac cache/options directory +.DS_Store +*/.DS_Store + +# Visual Studio 2015 cache/options directory +.vs/ +.vscode/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ \ No newline at end of file diff --git a/UserPointManagement.sln b/UserPointManagement.sln new file mode 100644 index 0000000..eddcc78 --- /dev/null +++ b/UserPointManagement.sln @@ -0,0 +1,51 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{14E4E7B1-DAC3-4F63-9C6F-3875AE5C7502}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{EB952040-7FE7-492A-BBAA-E347A3C049F1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserPointManagement.Web", "src\UserPointManagement.Web\UserPointManagement.Web.csproj", "{F76FAFB7-B604-4CD6-AF5D-B7BB47F34EFC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserPointManagement.Persistence", "src\UserPointManagement.Persistence\UserPointManagement.Persistence.csproj", "{4F219EA1-BC60-475A-9BC2-5BE6DD38C221}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserPointManagement.Application", "src\UserPointManagement.Application\UserPointManagement.Application.csproj", "{F7D6BA14-96C2-4DA9-8BC7-F50DFA14EC66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserPointManagement.Model", "src\UserPointManagement.Model\UserPointManagement.Model.csproj", "{75EC6A62-86F4-4D0C-A222-9BA11AA82A0E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserPointManagement.Tests", "test\UserPointManagement.Tests\UserPointManagement.Tests.csproj", "{F831F9D1-54CD-4566-ADBB-BAE879A78488}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F76FAFB7-B604-4CD6-AF5D-B7BB47F34EFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F76FAFB7-B604-4CD6-AF5D-B7BB47F34EFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F76FAFB7-B604-4CD6-AF5D-B7BB47F34EFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F76FAFB7-B604-4CD6-AF5D-B7BB47F34EFC}.Release|Any CPU.Build.0 = Release|Any CPU + {4F219EA1-BC60-475A-9BC2-5BE6DD38C221}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F219EA1-BC60-475A-9BC2-5BE6DD38C221}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F219EA1-BC60-475A-9BC2-5BE6DD38C221}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F219EA1-BC60-475A-9BC2-5BE6DD38C221}.Release|Any CPU.Build.0 = Release|Any CPU + {F7D6BA14-96C2-4DA9-8BC7-F50DFA14EC66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7D6BA14-96C2-4DA9-8BC7-F50DFA14EC66}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7D6BA14-96C2-4DA9-8BC7-F50DFA14EC66}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7D6BA14-96C2-4DA9-8BC7-F50DFA14EC66}.Release|Any CPU.Build.0 = Release|Any CPU + {75EC6A62-86F4-4D0C-A222-9BA11AA82A0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {75EC6A62-86F4-4D0C-A222-9BA11AA82A0E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {75EC6A62-86F4-4D0C-A222-9BA11AA82A0E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {75EC6A62-86F4-4D0C-A222-9BA11AA82A0E}.Release|Any CPU.Build.0 = Release|Any CPU + {F831F9D1-54CD-4566-ADBB-BAE879A78488}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F831F9D1-54CD-4566-ADBB-BAE879A78488}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F831F9D1-54CD-4566-ADBB-BAE879A78488}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F831F9D1-54CD-4566-ADBB-BAE879A78488}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {F76FAFB7-B604-4CD6-AF5D-B7BB47F34EFC} = {14E4E7B1-DAC3-4F63-9C6F-3875AE5C7502} + {4F219EA1-BC60-475A-9BC2-5BE6DD38C221} = {14E4E7B1-DAC3-4F63-9C6F-3875AE5C7502} + {F7D6BA14-96C2-4DA9-8BC7-F50DFA14EC66} = {14E4E7B1-DAC3-4F63-9C6F-3875AE5C7502} + {75EC6A62-86F4-4D0C-A222-9BA11AA82A0E} = {14E4E7B1-DAC3-4F63-9C6F-3875AE5C7502} + {F831F9D1-54CD-4566-ADBB-BAE879A78488} = {EB952040-7FE7-492A-BBAA-E347A3C049F1} + EndGlobalSection +EndGlobal diff --git a/global.json b/global.json new file mode 100644 index 0000000..1bcf6c0 --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "6.0.0", + "rollForward": "latestMinor", + "allowPrerelease": false + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Application/ServiceInjectExtensions.cs b/src/UserPointManagement.Application/ServiceInjectExtensions.cs new file mode 100644 index 0000000..e9c385d --- /dev/null +++ b/src/UserPointManagement.Application/ServiceInjectExtensions.cs @@ -0,0 +1,27 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace UserPointManagement.Application; + +public static class ServiceInjectExtensions +{ + public static IServiceCollection AddServices(this IServiceCollection services) + { + var assembly = typeof(ServiceInjectExtensions).Assembly; + var types = assembly + .GetTypes() + .Where(t => + !t.IsGenericType && + !t.IsAbstract && + t.IsClass && + !t.Name.EndsWith("ApiService") && + t.Name.EndsWith("Service")) + .ToList(); + foreach (var type in types) + { + var baseType = type.GetInterfaces().FirstOrDefault(t => t.Name == $"I{type.Name}"); + services.TryAddScoped(baseType, type); + } + return services; + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Application/Services/UserService.cs b/src/UserPointManagement.Application/Services/UserService.cs new file mode 100644 index 0000000..bdbd997 --- /dev/null +++ b/src/UserPointManagement.Application/Services/UserService.cs @@ -0,0 +1,11 @@ +namespace UserPointManagement.Application.Services; + +public interface IUserService +{ + +} + +public class UserService : IUserService +{ + +} \ No newline at end of file diff --git a/src/UserPointManagement.Application/UserPointManagement.Application.csproj b/src/UserPointManagement.Application/UserPointManagement.Application.csproj new file mode 100644 index 0000000..168c16f --- /dev/null +++ b/src/UserPointManagement.Application/UserPointManagement.Application.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/src/UserPointManagement.Model/Entities/User.cs b/src/UserPointManagement.Model/Entities/User.cs new file mode 100644 index 0000000..ca12ba6 --- /dev/null +++ b/src/UserPointManagement.Model/Entities/User.cs @@ -0,0 +1,10 @@ +namespace UserPointManagement.Model.Entities; + +public class User +{ + public int Id { get; set; } + + public string Name { get; set; } + + public string Mobile { get; set; } +} \ No newline at end of file diff --git a/src/UserPointManagement.Model/UserPointManagement.Model.csproj b/src/UserPointManagement.Model/UserPointManagement.Model.csproj new file mode 100644 index 0000000..168c16f --- /dev/null +++ b/src/UserPointManagement.Model/UserPointManagement.Model.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/src/UserPointManagement.Persistence/EntityTypeConfigurations/UserConfiguration.cs b/src/UserPointManagement.Persistence/EntityTypeConfigurations/UserConfiguration.cs new file mode 100644 index 0000000..473ad28 --- /dev/null +++ b/src/UserPointManagement.Persistence/EntityTypeConfigurations/UserConfiguration.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using UserPointManagement.Model.Entities; + +namespace UserPointManagement.Persistence.EntityTypeConfigurations; + +public class UserConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(e => e.Id); + + builder.Property(e => e.Id) + .HasComment("主键"); + + builder.Property(e => e.Name) + .HasComment("姓名") + .HasMaxLength(50); + + builder.Property(e => e.Mobile) + .HasComment("手机号") + .HasMaxLength(30); + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Persistence/Migrations/20230728165153_Initial.Designer.cs b/src/UserPointManagement.Persistence/Migrations/20230728165153_Initial.Designer.cs new file mode 100644 index 0000000..12afa0b --- /dev/null +++ b/src/UserPointManagement.Persistence/Migrations/20230728165153_Initial.Designer.cs @@ -0,0 +1,58 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UserPointManagement.Persistence; + +#nullable disable + +namespace UserPointManagement.Persistence.Migrations +{ + [DbContext(typeof(UserPointManagementDbContext))] + [Migration("20230728165153_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UserPointManagement.Model.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id") + .HasComment("主键"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Mobile") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)") + .HasColumnName("mobile") + .HasComment("手机号"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasColumnName("name") + .HasComment("姓名"); + + b.HasKey("Id") + .HasName("pk_user"); + + b.ToTable("user", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/UserPointManagement.Persistence/Migrations/20230728165153_Initial.cs b/src/UserPointManagement.Persistence/Migrations/20230728165153_Initial.cs new file mode 100644 index 0000000..49f9e87 --- /dev/null +++ b/src/UserPointManagement.Persistence/Migrations/20230728165153_Initial.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace UserPointManagement.Persistence.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + id = table.Column(type: "integer", nullable: false, comment: "主键") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false, comment: "姓名"), + mobile = table.Column(type: "character varying(30)", maxLength: 30, nullable: false, comment: "手机号") + }, + constraints: table => + { + table.PrimaryKey("pk_user", x => x.id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/src/UserPointManagement.Persistence/Migrations/UserPointManagementDbContextModelSnapshot.cs b/src/UserPointManagement.Persistence/Migrations/UserPointManagementDbContextModelSnapshot.cs new file mode 100644 index 0000000..86235b8 --- /dev/null +++ b/src/UserPointManagement.Persistence/Migrations/UserPointManagementDbContextModelSnapshot.cs @@ -0,0 +1,56 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UserPointManagement.Persistence; + +#nullable disable + +namespace UserPointManagement.Persistence.Migrations +{ + [DbContext(typeof(UserPointManagementDbContext))] + partial class UserPointManagementDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UserPointManagement.Model.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id") + .HasComment("主键"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Mobile") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)") + .HasColumnName("mobile") + .HasComment("手机号"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasColumnName("name") + .HasComment("姓名"); + + b.HasKey("Id") + .HasName("pk_user"); + + b.ToTable("user", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/UserPointManagement.Persistence/ModelBuilderExtensions.cs b/src/UserPointManagement.Persistence/ModelBuilderExtensions.cs new file mode 100644 index 0000000..0255143 --- /dev/null +++ b/src/UserPointManagement.Persistence/ModelBuilderExtensions.cs @@ -0,0 +1,26 @@ +using System.Text.RegularExpressions; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +namespace UserPointManagement.Persistence +{ + public static class ModelBuilderExtensions + { + public static void SnakeCaseTableNameConvention(this ModelBuilder modelBuilder) + { + foreach (IMutableEntityType entity in modelBuilder.Model.GetEntityTypes()) + { + var pattern = + new Regex(@"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+"); + + var snakeCaseName = entity.DisplayName() == null + ? null + : string + .Join("_", pattern.Matches(entity.DisplayName()).Cast().Select(m => m.Value)) + .ToLower(); + + entity.SetTableName(snakeCaseName); + } + } + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Persistence/RepositoryInjectExtensions.cs b/src/UserPointManagement.Persistence/RepositoryInjectExtensions.cs new file mode 100644 index 0000000..cd54bb9 --- /dev/null +++ b/src/UserPointManagement.Persistence/RepositoryInjectExtensions.cs @@ -0,0 +1,27 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace UserPointManagement.Persistence +{ + public static class RepositoryInjectExtensions + { + public static IServiceCollection AddRepositories(this IServiceCollection services) + { + var assembly = typeof(RepositoryInjectExtensions).Assembly; + var types = assembly + .GetTypes() + .Where(t => + !t.IsGenericType && + !t.IsAbstract && + t.IsClass && + t.Name.EndsWith("Repository")) + .ToList(); + foreach (var type in types) + { + var baseType = type.GetInterfaces().FirstOrDefault(t => t.Name == $"I{type.Name}"); + services.TryAddScoped(baseType, type); + } + return services; + } + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Persistence/UserPointManagement.Persistence.csproj b/src/UserPointManagement.Persistence/UserPointManagement.Persistence.csproj new file mode 100644 index 0000000..0b524ff --- /dev/null +++ b/src/UserPointManagement.Persistence/UserPointManagement.Persistence.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + diff --git a/src/UserPointManagement.Persistence/UserPointManagementDbContext.cs b/src/UserPointManagement.Persistence/UserPointManagementDbContext.cs new file mode 100644 index 0000000..611d648 --- /dev/null +++ b/src/UserPointManagement.Persistence/UserPointManagementDbContext.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using UserPointManagement.Model.Entities; +using UserPointManagement.Persistence.EntityTypeConfigurations; + +namespace UserPointManagement.Persistence; + +public class UserPointManagementDbContext : Microsoft.EntityFrameworkCore.DbContext +{ + public UserPointManagementDbContext(DbContextOptions options) : base(options) + { + } + + public virtual DbSet Users { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.SnakeCaseTableNameConvention(); + modelBuilder.ApplyConfiguration(new UserConfiguration()); + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Persistence/UserPointManagementDbContextFactory.cs b/src/UserPointManagement.Persistence/UserPointManagementDbContextFactory.cs new file mode 100644 index 0000000..f8cdfdb --- /dev/null +++ b/src/UserPointManagement.Persistence/UserPointManagementDbContextFactory.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using UserPointManagement.Persistence; + +namespace UserPointManagement.Web; + +public class UserPointManagementDbContextFactory : IDesignTimeDbContextFactory +{ + public UserPointManagementDbContext CreateDbContext(string[] args) + { + var optionsBuilder = new DbContextOptionsBuilder(); + optionsBuilder + .UseNpgsql("Server=67.230.184.225;Port=58007;UserId=postgres;Password=postgres;Database=tiamo;") + .UseSnakeCaseNamingConvention(); + + return new UserPointManagementDbContext(optionsBuilder.Options); + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Web/App.razor b/src/UserPointManagement.Web/App.razor new file mode 100644 index 0000000..b5c2bdb --- /dev/null +++ b/src/UserPointManagement.Web/App.razor @@ -0,0 +1,11 @@ + + + + + + +

Sorry, there's nothing at this address.

+
+
+
+ \ No newline at end of file diff --git a/src/UserPointManagement.Web/Layouts/BasicLayout.razor b/src/UserPointManagement.Web/Layouts/BasicLayout.razor new file mode 100644 index 0000000..408a496 --- /dev/null +++ b/src/UserPointManagement.Web/Layouts/BasicLayout.razor @@ -0,0 +1,56 @@ +@namespace UserPointManagement.Web +@inherits LayoutComponentBase + + + + + + + @Body + + + + + + + +@code +{ + private readonly MenuDataItem[] _menuData = + { + new MenuDataItem + { + Path = "/", + Name = "welcome", + Key = "welcome", + Icon = "smile", + } + }; + + public LinkItem[] Links { get; set; } = + { + new LinkItem + { + Key = "Ant Design Blazor", + Title = "Ant Design Blazor", + Href = "https://antblazor.com", + BlankTarget = true, + }, + new LinkItem + { + Key = "github", + Title = (RenderFragment)(@), + Href = "https://github.com/ant-design-blazor/ant-design-pro-blazor", + BlankTarget = true, + }, + new LinkItem + { + Key = "Blazor", + Title = "Blazor", + Href = "https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor?WT.mc_id=DT-MVP-5003987", + BlankTarget = true, + } + }; +} \ No newline at end of file diff --git a/src/UserPointManagement.Web/Pages/Welcome.razor b/src/UserPointManagement.Web/Pages/Welcome.razor new file mode 100644 index 0000000..52b7a10 --- /dev/null +++ b/src/UserPointManagement.Web/Pages/Welcome.razor @@ -0,0 +1,41 @@ +@page "/" + + + + + + + Use .NET CLI to install the latest template quickly. + + +
 dotnet new --install AntDesign.Templates::0.1.0-*
+ + + Create an empty blazor WebAssembly project + + +
 dotnet new antdesign --host=wasm
+ + + Create a blazor webassembly project with all pages. + + +
 dotnet new antdesign --host=wasm --full
+
+

+ Want to add more pages? Please refer to + + ant-design-pro-blazor project + + . +

+
diff --git a/src/UserPointManagement.Web/Pages/Welcome.razor.css b/src/UserPointManagement.Web/Pages/Welcome.razor.css new file mode 100644 index 0000000..8a2325f --- /dev/null +++ b/src/UserPointManagement.Web/Pages/Welcome.razor.css @@ -0,0 +1,7 @@ +.pre { + margin: 12px 0; + padding: 12px 20px; + background: #fff; + box-shadow: 0 1px 2px -2px rgba(0, 0, 0, 0.16), + 0 3px 6px 0 rgba(0, 0, 0, 0.12), 0 5px 12px 4px rgba(0, 0, 0, 0.09); +} diff --git a/src/UserPointManagement.Web/Program.cs b/src/UserPointManagement.Web/Program.cs new file mode 100644 index 0000000..dc9af71 --- /dev/null +++ b/src/UserPointManagement.Web/Program.cs @@ -0,0 +1,38 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using AntDesign.ProLayout; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using UserPointManagement.Application; +using UserPointManagement.Persistence; + +namespace UserPointManagement.Web +{ + public class Program + { + public static async Task Main(string[] args) + { + var builder = WebAssemblyHostBuilder.CreateDefault(args); + builder.RootComponents.Add("#app"); + + builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); + builder.Services.AddAntDesign(); + builder.Services.AddServices(); + builder.Services.AddRepositories(); + builder.Services.Configure(builder.Configuration.GetSection("ProSettings")); + + builder.Services.AddDbContext(option => + { + option + .UseNpgsql(builder.Configuration["Connection:UserPointManagement"]) + .UseSnakeCaseNamingConvention(); + }); + + var host = builder.Build(); + await host.RunAsync(); + } + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Web/Properties/launchSettings.json b/src/UserPointManagement.Web/Properties/launchSettings.json new file mode 100644 index 0000000..f7c97e3 --- /dev/null +++ b/src/UserPointManagement.Web/Properties/launchSettings.json @@ -0,0 +1,29 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:53775/", + "sslPort": 44358 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "UserPointManagement.Web": { + "commandName": "Project", + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + } + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Web/README.md b/src/UserPointManagement.Web/README.md new file mode 100644 index 0000000..c605fc5 --- /dev/null +++ b/src/UserPointManagement.Web/README.md @@ -0,0 +1 @@ +# UserPointManagement.Web \ No newline at end of file diff --git a/src/UserPointManagement.Web/UserPointManagement.Web.csproj b/src/UserPointManagement.Web/UserPointManagement.Web.csproj new file mode 100644 index 0000000..7eeafa1 --- /dev/null +++ b/src/UserPointManagement.Web/UserPointManagement.Web.csproj @@ -0,0 +1,22 @@ + + + + net6 + 3.0 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/UserPointManagement.Web/_Imports.razor b/src/UserPointManagement.Web/_Imports.razor new file mode 100644 index 0000000..f35f054 --- /dev/null +++ b/src/UserPointManagement.Web/_Imports.razor @@ -0,0 +1,11 @@ +@using AntDesign +@using AntDesign.Charts +@using AntDesign.ProLayout +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using Microsoft.AspNetCore.Components.WebAssembly.Http +@using Microsoft.JSInterop +@using UserPointManagement.Web diff --git a/src/UserPointManagement.Web/wwwroot/appsettings.json b/src/UserPointManagement.Web/wwwroot/appsettings.json new file mode 100644 index 0000000..a71e664 --- /dev/null +++ b/src/UserPointManagement.Web/wwwroot/appsettings.json @@ -0,0 +1,19 @@ +{ + "ProSettings": { + "NavTheme": "dark", + "Layout": "side", + "ContentWidth": "Fluid", + "FixedHeader": false, + "FixSiderbar": true, + "Title": "Ant Design Pro", + "PrimaryColor": "daybreak", + "ColorWeak": false, + "SplitMenus": false, + "HeaderRender": true, + "FooterRender": true, + "MenuRender": true, + "MenuHeaderRender": true, + "HeaderHeight": 48 + }, + "Connection:UserPointManagement": "Server=67.230.184.225;Port=58007;UserId=postgres;Password=postgres;Database=tiamo;" +} \ No newline at end of file diff --git a/src/UserPointManagement.Web/wwwroot/assets/403.svg b/src/UserPointManagement.Web/wwwroot/assets/403.svg new file mode 100644 index 0000000..610f136 --- /dev/null +++ b/src/UserPointManagement.Web/wwwroot/assets/403.svg @@ -0,0 +1,508 @@ + + + + Group 9 + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/UserPointManagement.Web/wwwroot/assets/logo.svg b/src/UserPointManagement.Web/wwwroot/assets/logo.svg new file mode 100644 index 0000000..239bf69 --- /dev/null +++ b/src/UserPointManagement.Web/wwwroot/assets/logo.svg @@ -0,0 +1 @@ +Group 28 Copy 5Created with Sketch. \ No newline at end of file diff --git a/src/UserPointManagement.Web/wwwroot/css/site.css b/src/UserPointManagement.Web/wwwroot/css/site.css new file mode 100644 index 0000000..0fa9a0d --- /dev/null +++ b/src/UserPointManagement.Web/wwwroot/css/site.css @@ -0,0 +1,52 @@ +/* stylelint-disable at-rule-empty-line-before,at-rule-name-space-after,at-rule-no-unknown */ +/* stylelint-disable no-duplicate-selectors */ +/* stylelint-disable */ +/* stylelint-disable declaration-bang-space-before,no-duplicate-selectors,string-no-newline */ +html, +body, +#root, +#app, +app { + height: 100%; +} +.colorWeak { + filter: invert(80%); +} +.ant-layout { + min-height: 100vh; +} +canvas { + display: block; +} +body { + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} +ul, +ol { + list-style: none; +} +@media (max-width: 480px) { + .ant-table { + width: 100%; + overflow-x: auto; + } + .ant-table-thead > tr > th, + .ant-table-tbody > tr > th, + .ant-table-thead > tr > td, + .ant-table-tbody > tr > td { + white-space: pre; + } + .ant-table-thead > tr > th > span, + .ant-table-tbody > tr > th > span, + .ant-table-thead > tr > td > span, + .ant-table-tbody > tr > td > span { + display: block; + } +} +@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { + body .ant-design-pro > .ant-layout { + min-height: 100vh; + } +} diff --git a/src/UserPointManagement.Web/wwwroot/favicon.ico b/src/UserPointManagement.Web/wwwroot/favicon.ico new file mode 100644 index 0000000..60a4278 Binary files /dev/null and b/src/UserPointManagement.Web/wwwroot/favicon.ico differ diff --git a/src/UserPointManagement.Web/wwwroot/index.html b/src/UserPointManagement.Web/wwwroot/index.html new file mode 100644 index 0000000..f91cd32 --- /dev/null +++ b/src/UserPointManagement.Web/wwwroot/index.html @@ -0,0 +1,210 @@ + + + + + + + + + + + Ant Design Pro Blazor + + + + + + + + + + +
+ +
+ logo +
+
+ +
+
+
+ + Ant Design Blazor
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/src/UserPointManagement.Web/wwwroot/pro_icon.svg b/src/UserPointManagement.Web/wwwroot/pro_icon.svg new file mode 100644 index 0000000..e075b78 --- /dev/null +++ b/src/UserPointManagement.Web/wwwroot/pro_icon.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/test/UserPointManagement.Tests/Startup.cs b/test/UserPointManagement.Tests/Startup.cs new file mode 100644 index 0000000..05f68a2 --- /dev/null +++ b/test/UserPointManagement.Tests/Startup.cs @@ -0,0 +1,49 @@ +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using UserPointManagement.Application; +using UserPointManagement.Persistence; +using Xunit.DependencyInjection; +using Xunit.DependencyInjection.Logging; + +namespace UserPointManagement.Tests +{ + public class Startup + { + public void ConfigureHost(IHostBuilder hostBuilder) + { + hostBuilder + .ConfigureAppConfiguration(builder => + { + // 注册配置 + builder + .AddInMemoryCollection(new List> + { + new ("Connection:UserPointManagement", "Server=67.230.184.225;Port=58007;UserId=postgres;Password=postgres;Database=tiamo;"), + }).Build(); + }) + .ConfigureServices((context, services) => + { + // 注册自定义服务 + services.AddDbContext(option => + { + option.UseNpgsql(context.Configuration["Connection:UserPointManagement"]) + .UseSnakeCaseNamingConvention(); + }); + + services.AddServices(); + services.AddRepositories(); + + }); + } + + public void Configure(ILoggerFactory loggerFactory, ITestOutputHelperAccessor accessor) + { + using var provider = new XunitTestOutputLoggerProvider(accessor); + loggerFactory.AddProvider(provider); + } + } +} \ No newline at end of file diff --git a/test/UserPointManagement.Tests/UserPointManagement.Tests.csproj b/test/UserPointManagement.Tests/UserPointManagement.Tests.csproj new file mode 100644 index 0000000..3c61fcb --- /dev/null +++ b/test/UserPointManagement.Tests/UserPointManagement.Tests.csproj @@ -0,0 +1,29 @@ + + + + net6.0 + enable + + false + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + +