diff --git a/AGSS/AGSS.csproj b/AGSS/AGSS.csproj index a799f8c..32f5c9f 100644 --- a/AGSS/AGSS.csproj +++ b/AGSS/AGSS.csproj @@ -10,13 +10,19 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - + + + diff --git a/AGSS/Controllers/User/UserInfoController.cs b/AGSS/Controllers/User/UserInfoController.cs new file mode 100644 index 0000000..b09afe6 --- /dev/null +++ b/AGSS/Controllers/User/UserInfoController.cs @@ -0,0 +1,31 @@ +using AGSS.Models; +using AGSS.Models.Entities; +using AGSS.Models.Template; +using Microsoft.AspNetCore.Mvc; + +namespace AGSS.Controllers.User; + +[ApiController] +[Route("api/[controller]/[action]")] +public class UserInfoController : ControllerBase +{ + private readonly DBContext _context; + + public UserInfoController(DBContext context) + { + _context = context; + } + + [HttpGet] + public async Task My() + { + UserModel user = new UserModel + { + AuthId = "123" + }; + + _context.UserModels.Add(user); + await _context.SaveChangesAsync(); + return Ok(new ReturnTemplate(200, "成功",user)); + } +} \ No newline at end of file diff --git a/AGSS/Models/DBContext.cs b/AGSS/Models/DBContext.cs new file mode 100644 index 0000000..b14151b --- /dev/null +++ b/AGSS/Models/DBContext.cs @@ -0,0 +1,14 @@ +using AGSS.Models.Entities; +using Microsoft.EntityFrameworkCore; + +namespace AGSS.Models; + +public class DBContext : DbContext +{ + public DBContext(DbContextOptions options) + : base(options) + { + } + + public DbSet UserModels { get; set; } +} \ No newline at end of file diff --git a/AGSS/Models/Entities/User.cs b/AGSS/Models/Entities/User.cs new file mode 100644 index 0000000..5c4f2d0 --- /dev/null +++ b/AGSS/Models/Entities/User.cs @@ -0,0 +1,8 @@ +namespace AGSS.Models.Entities; + +public class UserModel +{ + public Guid Id { get; set; } + public required string AuthId { get; set; } + +} \ No newline at end of file diff --git a/AGSS/Models/Template/ReturnTemplate.cs b/AGSS/Models/Template/ReturnTemplate.cs new file mode 100644 index 0000000..98e976c --- /dev/null +++ b/AGSS/Models/Template/ReturnTemplate.cs @@ -0,0 +1,3 @@ +namespace AGSS.Models.Template; + + public record ReturnTemplate(int Code, string Msg, object Data); diff --git a/AGSS/Program.cs b/AGSS/Program.cs index 1b71f31..415bc5b 100644 --- a/AGSS/Program.cs +++ b/AGSS/Program.cs @@ -1,4 +1,6 @@ +using AGSS.Models; using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; @@ -16,10 +18,11 @@ var builder = WebApplication.CreateBuilder(args); -// ȡ var domain = builder.Configuration["Auth0:Domain"]; var audience =builder.Configuration["Auth0:Audience"]; +builder.Services.AddDbContext(opt => + opt.UseNpgsql(builder.Configuration.GetConnectionString("DBContext"))); builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => @@ -59,10 +62,6 @@ app.UseAuthentication(); app.UseAuthorization(); -#pragma warning disable ASP0014 // Suggest using top level route registrations -app.UseEndpoints(endpoints => endpoints.MapControllers()); -#pragma warning restore ASP0014 // Suggest using top level route registrations - app.MapControllers(); diff --git a/AGSS/appsettings.Development.json b/AGSS/appsettings.Development.json index 0c208ae..bda9442 100644 --- a/AGSS/appsettings.Development.json +++ b/AGSS/appsettings.Development.json @@ -4,5 +4,14 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "AllowedHosts": "*", + "Auth0": { + "Domain": "", + "Audience": "", + "ClientId": "" + }, + "DataBase": { + "ConnectionString": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=luolan12323;" } } diff --git a/AGSS/appsettings.json b/AGSS/appsettings.json index ec10538..99ba56a 100644 --- a/AGSS/appsettings.json +++ b/AGSS/appsettings.json @@ -10,5 +10,8 @@ "Domain": "", "Audience": "", "ClientId": "" + }, + "ConnectionStrings": { + "DBContext": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=luolan12323;" } }