From 1075225001ff6619892815f00561043522a3efda Mon Sep 17 00:00:00 2001 From: yawaflua Date: Wed, 17 Apr 2024 22:55:07 +0300 Subject: [PATCH] make backend for my site --- Areas/MyFeature/Pages/Page1.cshtml | 2 +- Areas/MyFeature/Pages/Page1.cshtml.cs | 2 +- Auth/ApiKeyAuthorization.cs | 12 +- Auth/ApiKeyTypes.cs | 2 +- .../{HomeController.cs => ApiController.cs} | 172 +++++++----------- Controllers/RedirectController.cs | 34 ++++ ...0231127204250_Migrate271122342.Designer.cs | 8 +- Migrations/20231127204250_Migrate271122342.cs | 2 +- ...20231204171742_Migrate04122016.Designer.cs | 8 +- Migrations/20231204171742_Migrate04122016.cs | 2 +- .../20231204210831_Migrate0512.Designer.cs | 10 +- Migrations/20231204210831_Migrate0512.cs | 2 +- ...20231218172614_Migrate18122023.Designer.cs | 16 +- Migrations/20231218172614_Migrate18122023.cs | 2 +- ...20231218173546_Migrate18122035.Designer.cs | 16 +- Migrations/20231218173546_Migrate18122035.cs | 2 +- ...1219143602_Migrate191220231734.Designer.cs | 16 +- .../20231219143602_Migrate191220231734.cs | 2 +- ...1223164820_Migrate321220231944.Designer.cs | 10 +- .../20231223164820_Migrate321220231944.cs | 2 +- ...31225062718_Migrate25122023926.Designer.cs | 12 +- .../20231225062718_Migrate25122023926.cs | 2 +- ...3302_Migrate_22_32__15_03_2024.Designer.cs | 164 +++++++++++++++++ ...0240315193302_Migrate_22_32__15_03_2024.cs | 38 ++++ Migrations/AppDbContextModelSnapshot.cs | 41 ++++- Models/AppDbContext.cs | 10 +- Models/Tables/ApiKey.cs | 4 +- Models/Tables/Blogs.cs | 2 +- Models/Tables/Comments.cs | 2 +- Models/Tables/Projects.cs | 16 ++ Models/Tables/Redirects.cs | 2 +- Pages/AdminPanel.cshtml | 2 +- Pages/AdminPanel.cshtml.cs | 2 +- Pages/Authorize.cshtml | 10 +- Pages/Authorize.cshtml.cs | 2 +- Pages/Blog.cshtml | 2 +- Pages/Blog.cshtml.cs | 4 +- Pages/Error.cshtml.cs | 2 +- Pages/Index.cshtml | 2 +- Pages/Index.cshtml.cs | 30 +-- Pages/NotFound.cshtml.cs | 2 +- Pages/Privacy.cshtml.cs | 2 +- Pages/_ViewImports.cshtml | 4 +- Pages/rrobotsTxt.cshtml | 12 ++ Program.cs | 17 +- Properties/launchSettings.json | 66 ++++--- Startup.cs | 66 +++---- Utilities/AppDbContextUtilities.cs | 13 ++ yaflay.ru.csproj => api.yawaflua.ru.csproj | 20 +- yaflay.ru.sln => yawaflua.ru.sln | 10 +- 50 files changed, 571 insertions(+), 312 deletions(-) rename Controllers/{HomeController.cs => ApiController.cs} (55%) create mode 100644 Controllers/RedirectController.cs create mode 100644 Migrations/20240315193302_Migrate_22_32__15_03_2024.Designer.cs create mode 100644 Migrations/20240315193302_Migrate_22_32__15_03_2024.cs create mode 100644 Models/Tables/Projects.cs create mode 100644 Pages/rrobotsTxt.cshtml create mode 100644 Utilities/AppDbContextUtilities.cs rename yaflay.ru.csproj => api.yawaflua.ru.csproj (63%) rename yaflay.ru.sln => yawaflua.ru.sln (59%) diff --git a/Areas/MyFeature/Pages/Page1.cshtml b/Areas/MyFeature/Pages/Page1.cshtml index fd9fb4b..25e0304 100644 --- a/Areas/MyFeature/Pages/Page1.cshtml +++ b/Areas/MyFeature/Pages/Page1.cshtml @@ -1,5 +1,5 @@ @page -@model yaflay.ru.MyFeature.Pages.Page1Model +@model yawaflua.ru.MyFeature.Pages.Page1Model diff --git a/Areas/MyFeature/Pages/Page1.cshtml.cs b/Areas/MyFeature/Pages/Page1.cshtml.cs index 2c8de40..476d05b 100644 --- a/Areas/MyFeature/Pages/Page1.cshtml.cs +++ b/Areas/MyFeature/Pages/Page1.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace yaflay.ru.MyFeature.Pages +namespace yawaflua.ru.MyFeature.Pages { public class Page1Model : PageModel { diff --git a/Auth/ApiKeyAuthorization.cs b/Auth/ApiKeyAuthorization.cs index 9dbac0a..f6534fd 100644 --- a/Auth/ApiKeyAuthorization.cs +++ b/Auth/ApiKeyAuthorization.cs @@ -3,12 +3,12 @@ using System.Text.Encodings.Web; using Microsoft.AspNetCore.Authentication; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; -using yaflay.ru.Database.Tables; -using yaflay.ru.Models; -using yaflay.ru.Models.Tables; +using yawaflua.ru.Database.Tables; +using yawaflua.ru.Models; +using yawaflua.ru.Models.Tables; -namespace yaflay.ru.Auth; +namespace yawaflua.ru.Auth; public class ApiKeyAuthantication : AuthenticationHandler { @@ -29,7 +29,9 @@ public class ApiKeyAuthantication : AuthenticationHandler HandleAuthenticateAsync() { - if (!Request.Headers.TryGetValue("Authorization", out var apiKeyHeaderValues)) + if (!Request.Host.Value.StartsWith("api")) + return AuthenticateResult.NoResult(); + if (!Request.Headers.TryGetValue("Authorization", out var apiKeyHeaderValues) && Request.Host.Value.StartsWith("api")) return AuthenticateResult.Fail("API Key was not provided."); string? providedApiKey = apiKeyHeaderValues.FirstOrDefault()?.Replace("Bearer ", ""); diff --git a/Auth/ApiKeyTypes.cs b/Auth/ApiKeyTypes.cs index 86c23ea..514b49c 100644 --- a/Auth/ApiKeyTypes.cs +++ b/Auth/ApiKeyTypes.cs @@ -1,4 +1,4 @@ -namespace yaflay.ru.Auth +namespace yawaflua.ru.Auth { public enum ApiKeyTypes diff --git a/Controllers/HomeController.cs b/Controllers/ApiController.cs similarity index 55% rename from Controllers/HomeController.cs rename to Controllers/ApiController.cs index bbf1ac9..2184684 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/ApiController.cs @@ -1,24 +1,24 @@ using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.RateLimiting; -using System.Text.Json; using System.Text.Json.Nodes; -using yaflay.ru.Models.Tables; +using yawaflua.ru.Models.Tables; using Microsoft.Extensions.Caching.Memory; -using yaflay.ru.Models; +using yawaflua.ru.Models; using System; using Microsoft.AspNetCore.Authorization; -using yaflay.ru.Auth; -using yaflay.ru.Database.Tables; +using yawaflua.ru.Auth; +using yawaflua.ru.Database.Tables; +using yawaflua.ru.Utilities; +using api.yawaflua.ru.Models.Tables; +using Newtonsoft.Json; -namespace yaflay.ru.Controllers +namespace yawaflua.ru.Controllers { - [Route("")] - public class HomeController : Controller + [Route("api/")] + public class ApiController : Controller { private IMemoryCache cache; private AppDbContext ctx; - public HomeController(IMemoryCache cache, AppDbContext ctx) + public ApiController(IMemoryCache cache, AppDbContext ctx) { this.cache = cache; this.ctx = ctx; @@ -29,29 +29,16 @@ namespace yaflay.ru.Controllers public string watermelon { get; set; } public string discordId { get; set; } public ApiKeyTypes type { get; set; } - + } public class commentBody { public string text { get; set; } public string sender { get; set; } } - public class articleBody - { - public string title { get; set; } - public string annotation { get; set; } - public string text { get; set; } - public string image { get; set; } - public string author { get; set; } - } - public class redirectBody - { - public string url { get; set; } - public string uri { get; set; } - public string author { get; set; } - } - [HttpGet("api/Index")] + + [HttpGet("Index")] public async Task getIndexPage() { string? indexPage = cache.Get($"indexPage"); @@ -65,11 +52,24 @@ namespace yaflay.ru.Controllers return Ok(indexPage); } - [HttpPost("api/redirects")] - [Authorize(AuthenticationSchemes = "DISCORD-OAUTH-PRIVATE")] - public async Task createRedirectUri([FromBody]redirectBody body) + [HttpGet("Projects")] + public async Task getProjects() + { + Console.WriteLine("Im here"); + Projects[] projects = Array.Empty(); + if (cache.TryGetValue("projects", out projects) || ctx.Projects.Any()) + { + projects ??= ctx.Projects.ToArray(); + cache.Set("projects", (object)projects); + } + Console.WriteLine(JsonConvert.SerializeObject(projects)); + return Ok(projects); + } + + [HttpPost("redirects")] + [Authorize(AuthenticationSchemes = "DISCORD-OAUTH-PRIVATE")] + public async Task createRedirectUri([FromQuery]string url, [FromQuery] string uri) { - Console.WriteLine("url" + body.uri); HttpResponseMessage message; using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://discordapp.com/api/oauth2/@me")) @@ -83,8 +83,8 @@ namespace yaflay.ru.Controllers { Redirects redirects = new() { - redirectTo = body.url, - uri = body.uri + redirectTo = url, + uri = uri }; await ctx.Redirects.AddAsync(redirects); await ctx.SaveChangesAsync(); @@ -95,9 +95,9 @@ namespace yaflay.ru.Controllers return Unauthorized(); } } - [HttpPost("api/Blog")] + [HttpPost("Blog")] [Authorize(AuthenticationSchemes = "DISCORD-OAUTH-PRIVATE")] - public async Task createArticle([FromBody] articleBody body) + public async Task createArticle([FromQuery] string title, [FromQuery] string annotation, [FromQuery] string text, [FromQuery] string image, [FromQuery] string author) { HttpResponseMessage message; @@ -109,36 +109,27 @@ namespace yaflay.ru.Controllers } string responseBody = await message.Content.ReadAsStringAsync(); JsonNode response = JsonNode.Parse(responseBody); - if (response["user"] != null || Startup.ownerId?.FirstOrDefault(response["user"]?["id"].ToString()) == null ) + if (response["user"] != null && Startup.ownerId?.FirstOrDefault(response["user"]?["id"].ToString()) != null ) { - try + + Blogs article = new() { - Blogs article = new() - { - Annotation = body.annotation, - authorId = response["user"]["id"].ToString(), - dateTime = DateTime.Now, - ImageUrl = body.image, - Text = body.text, - Title = body.title, - authorNickname = response["user"]["global_name"].ToString() - }; - await ctx.Blogs.AddAsync(article); - await ctx.SaveChangesAsync(); - return Ok(body); - } - catch (Exception ex) - { - Console.WriteLine("error: HomeController error"); - Console.WriteLine("debug: lines: 80-96"); - Console.WriteLine($"debug: data from site: {body}"); - Console.WriteLine($"debug: exception: {ex.Message}"); - return StatusCode(500, body); - } + Annotation = annotation, + authorId = response["user"]["id"].ToString(), + dateTime = DateTime.Now, + ImageUrl = image, + Text = text, + Title = title, + authorNickname = response["user"]["global_name"].ToString() + }; + await ctx.Blogs.AddAsync(article); + await ctx.SaveChangesAsync(); + return Ok(); + } else { - return Unauthorized(body); + return Unauthorized(); } } [HttpGet("logout")] @@ -150,7 +141,7 @@ namespace yaflay.ru.Controllers return Redirect("/"); } - [HttpGet("api/Blog/{blogId?}/comments")] + [HttpGet("Blog/{blogId?}/comments")] public async Task blogComments(int? blogId) { Comments[]? comments = (Comments[]?)cache.Get($"commentsWithBlogId{blogId}"); @@ -163,16 +154,16 @@ namespace yaflay.ru.Controllers return Ok(comments); } - [HttpPost("api/Blog/{blogId}/comments")] + [HttpPost("Blog/{blogId}/comments")] [Authorize(AuthenticationSchemes = "DISCORD-OAUTH-PUBLIC")] - public async Task CreateBlogComments(int blogId, [FromBody]commentBody body) + public async Task CreateBlogComments(int blogId, [FromQuery] string text, [FromQuery] string sender) { Comments comment = new() { - creatorMail = body.sender, + creatorMail = sender, dateTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), - Text = body.text, + Text = text, postId = blogId }; await ctx.Comments.AddAsync(comment); @@ -180,23 +171,16 @@ namespace yaflay.ru.Controllers return Ok(); } - [HttpGet("api/Blog/{blogId}")] - public async Task blog(int blogId) + [HttpGet("Blog/{id}")] + public async Task blog(int id) { - Blogs? blog = cache.Get($"blogWithId{blogId}"); - if (blog == null) - { - blog = ctx.Blogs.FirstOrDefault(k => k.Id == blogId); - if (blog != null) - cache.Set($"blogWithId{blogId}", (object)blog, DateTime.Now.AddMinutes(10)); - - - } - - + Blogs? blog; + if (!cache.TryGetValue($"blogWithId{id}", out blog) && ctx.Blogs.TryGetValue(k => k.Id == id, out blog)) + cache.Set($"blogWithId{id}", blog, DateTime.Now.AddMinutes(30)); + return Ok(blog); } - [HttpGet("api/Blog")] + [HttpGet("Blog")] public async Task allBlogs() { Blogs[]? blogs = cache.Get($"allBlogs"); @@ -210,19 +194,9 @@ namespace yaflay.ru.Controllers } return Ok(blogs); } - [HttpPost("api/authorize")] + [HttpPost("authorize")] public async Task authorizeUser([FromBody] authorizeBody body) { - var fromCache = cache.Get($"apiKey-melon-{body.melon}"); - if (fromCache == null) - { - var melon = ctx.ApiKeys.FirstOrDefault(k => k.Melon == body.melon); - if (melon != null) - { - cache.Set($"apiKey-melon-{body.melon}", (object)melon, DateTime.Now.AddMinutes(20)); - } - } - await ctx.ApiKeys.AddAsync( new() { @@ -235,23 +209,7 @@ namespace yaflay.ru.Controllers await ctx.SaveChangesAsync(); return Ok(body.melon); } - [HttpGet("r/{uri}")] - public async Task FromGitHub(string uri) - { - Console.WriteLine(uri); - //if (uri == "404") { return Ok(); } - Redirects? fromCache = cache.Get($"redirectsWithUrl-{uri}") ?? null; - if (fromCache == null) - { - fromCache = ctx.Redirects.FirstOrDefault(k => k.uri == uri); - Console.WriteLine("Im here!"); - if (fromCache != null) - cache.Set($"redirectsWithUrl-{uri}", (object)fromCache, DateTime.Now.AddMinutes(10)); - } - Console.WriteLine(fromCache?.ToString()); - return Redirect(fromCache?.redirectTo ?? "/404"); - - } + } } diff --git a/Controllers/RedirectController.cs b/Controllers/RedirectController.cs new file mode 100644 index 0000000..c9193be --- /dev/null +++ b/Controllers/RedirectController.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Caching.Memory; +using yawaflua.ru.Models; +using yawaflua.ru.Models.Tables; +using yawaflua.ru.Utilities; + +namespace yawaflua.ru.Controllers +{ + [Route("/r/")] + [Authorize] + public class RedirectController : ControllerBase + { + private AppDbContext ctx; + private MemoryCache cache; + public RedirectController(AppDbContext ctx, MemoryCache cache) + { + this.ctx = ctx; + this.cache = cache; + } + [HttpGet("{uri}")] + public async Task FromGitHub(string uri) + { + Console.WriteLine(uri); + Redirects redirects; + if (!cache.TryGetValue($"redirectsWithUrl-{uri}", out redirects) || ctx.Redirects.TryGetValue(k => k.uri == uri, out redirects)) + cache.Set($"redirectsWithUrl-{uri}", redirects, DateTime.Now.AddMinutes(10)); + + return Redirect(redirects?.redirectTo ?? "/404"); + + } + } +} diff --git a/Migrations/20231127204250_Migrate271122342.Designer.cs b/Migrations/20231127204250_Migrate271122342.Designer.cs index 9bb4cf4..e5586a0 100644 --- a/Migrations/20231127204250_Migrate271122342.Designer.cs +++ b/Migrations/20231127204250_Migrate271122342.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using yaflay.ru.Models; +using yawaflua.ru.Models; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { [DbContext(typeof(AppDbContext))] [Migration("20231127204250_Migrate271122342")] @@ -25,7 +25,7 @@ namespace yaflay.ru.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -56,7 +56,7 @@ namespace yaflay.ru.Migrations b.ToTable("Blogs", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => { b.Property("Id") .ValueGeneratedOnAdd() diff --git a/Migrations/20231127204250_Migrate271122342.cs b/Migrations/20231127204250_Migrate271122342.cs index 0489649..55d2d70 100644 --- a/Migrations/20231127204250_Migrate271122342.cs +++ b/Migrations/20231127204250_Migrate271122342.cs @@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { /// public partial class Migrate271122342 : Migration diff --git a/Migrations/20231204171742_Migrate04122016.Designer.cs b/Migrations/20231204171742_Migrate04122016.Designer.cs index 47c47bf..3326e0a 100644 --- a/Migrations/20231204171742_Migrate04122016.Designer.cs +++ b/Migrations/20231204171742_Migrate04122016.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using yaflay.ru.Models; +using yawaflua.ru.Models; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { [DbContext(typeof(AppDbContext))] [Migration("20231204171742_Migrate04122016")] @@ -25,7 +25,7 @@ namespace yaflay.ru.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -56,7 +56,7 @@ namespace yaflay.ru.Migrations b.ToTable("Blogs", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => { b.Property("Id") .ValueGeneratedOnAdd() diff --git a/Migrations/20231204171742_Migrate04122016.cs b/Migrations/20231204171742_Migrate04122016.cs index 8b12cc2..9d77da6 100644 --- a/Migrations/20231204171742_Migrate04122016.cs +++ b/Migrations/20231204171742_Migrate04122016.cs @@ -2,7 +2,7 @@ #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { /// public partial class Migrate04122016 : Migration diff --git a/Migrations/20231204210831_Migrate0512.Designer.cs b/Migrations/20231204210831_Migrate0512.Designer.cs index 83334f8..23236a6 100644 --- a/Migrations/20231204210831_Migrate0512.Designer.cs +++ b/Migrations/20231204210831_Migrate0512.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using yaflay.ru.Models; +using yawaflua.ru.Models; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { [DbContext(typeof(AppDbContext))] [Migration("20231204210831_Migrate0512")] @@ -25,7 +25,7 @@ namespace yaflay.ru.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -56,7 +56,7 @@ namespace yaflay.ru.Migrations b.ToTable("Blogs", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -83,7 +83,7 @@ namespace yaflay.ru.Migrations b.ToTable("Comments", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Redirects", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Redirects", b => { b.Property("Id") .ValueGeneratedOnAdd() diff --git a/Migrations/20231204210831_Migrate0512.cs b/Migrations/20231204210831_Migrate0512.cs index 6129f3a..f665391 100644 --- a/Migrations/20231204210831_Migrate0512.cs +++ b/Migrations/20231204210831_Migrate0512.cs @@ -3,7 +3,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { /// public partial class Migrate0512 : Migration diff --git a/Migrations/20231218172614_Migrate18122023.Designer.cs b/Migrations/20231218172614_Migrate18122023.Designer.cs index e1a8efa..86fcf04 100644 --- a/Migrations/20231218172614_Migrate18122023.Designer.cs +++ b/Migrations/20231218172614_Migrate18122023.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using yaflay.ru.Models; +using yawaflua.ru.Models; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { [DbContext(typeof(AppDbContext))] [Migration("20231218172614_Migrate18122023")] @@ -25,7 +25,7 @@ namespace yaflay.ru.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("yaflay.ru.Models.Tables.Author", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Author", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -45,7 +45,7 @@ namespace yaflay.ru.Migrations b.ToTable("Author"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -81,7 +81,7 @@ namespace yaflay.ru.Migrations b.ToTable("Blogs", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -108,7 +108,7 @@ namespace yaflay.ru.Migrations b.ToTable("Comments", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Redirects", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Redirects", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -129,9 +129,9 @@ namespace yaflay.ru.Migrations b.ToTable("Redirects"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { - b.HasOne("yaflay.ru.Models.Tables.Author", "author") + b.HasOne("yawaflua.ru.Models.Tables.Author", "author") .WithMany() .HasForeignKey("authorId") .OnDelete(DeleteBehavior.Cascade) diff --git a/Migrations/20231218172614_Migrate18122023.cs b/Migrations/20231218172614_Migrate18122023.cs index 28f09de..a088c19 100644 --- a/Migrations/20231218172614_Migrate18122023.cs +++ b/Migrations/20231218172614_Migrate18122023.cs @@ -3,7 +3,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { /// public partial class Migrate18122023 : Migration diff --git a/Migrations/20231218173546_Migrate18122035.Designer.cs b/Migrations/20231218173546_Migrate18122035.Designer.cs index 9638f5b..0367da8 100644 --- a/Migrations/20231218173546_Migrate18122035.Designer.cs +++ b/Migrations/20231218173546_Migrate18122035.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using yaflay.ru.Models; +using yawaflua.ru.Models; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { [DbContext(typeof(AppDbContext))] [Migration("20231218173546_Migrate18122035")] @@ -25,7 +25,7 @@ namespace yaflay.ru.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("yaflay.ru.Models.Tables.Author", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Author", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -45,7 +45,7 @@ namespace yaflay.ru.Migrations b.ToTable("Author"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -81,7 +81,7 @@ namespace yaflay.ru.Migrations b.ToTable("Blogs", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -108,7 +108,7 @@ namespace yaflay.ru.Migrations b.ToTable("Comments", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Redirects", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Redirects", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -129,9 +129,9 @@ namespace yaflay.ru.Migrations b.ToTable("Redirects"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { - b.HasOne("yaflay.ru.Models.Tables.Author", "author") + b.HasOne("yawaflua.ru.Models.Tables.Author", "author") .WithMany() .HasForeignKey("authorId") .OnDelete(DeleteBehavior.Cascade) diff --git a/Migrations/20231218173546_Migrate18122035.cs b/Migrations/20231218173546_Migrate18122035.cs index 0d5f17f..4260650 100644 --- a/Migrations/20231218173546_Migrate18122035.cs +++ b/Migrations/20231218173546_Migrate18122035.cs @@ -2,7 +2,7 @@ #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { /// public partial class Migrate18122035 : Migration diff --git a/Migrations/20231219143602_Migrate191220231734.Designer.cs b/Migrations/20231219143602_Migrate191220231734.Designer.cs index b5def8a..7693eef 100644 --- a/Migrations/20231219143602_Migrate191220231734.Designer.cs +++ b/Migrations/20231219143602_Migrate191220231734.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using yaflay.ru.Models; +using yawaflua.ru.Models; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { [DbContext(typeof(AppDbContext))] [Migration("20231219143602_Migrate191220231734")] @@ -25,7 +25,7 @@ namespace yaflay.ru.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("yaflay.ru.Models.Tables.Author", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Author", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -45,7 +45,7 @@ namespace yaflay.ru.Migrations b.ToTable("Author"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -81,7 +81,7 @@ namespace yaflay.ru.Migrations b.ToTable("Blogs", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -108,7 +108,7 @@ namespace yaflay.ru.Migrations b.ToTable("Comments", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Redirects", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Redirects", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -127,9 +127,9 @@ namespace yaflay.ru.Migrations b.ToTable("Redirects"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { - b.HasOne("yaflay.ru.Models.Tables.Author", "author") + b.HasOne("yawaflua.ru.Models.Tables.Author", "author") .WithMany() .HasForeignKey("authorId") .OnDelete(DeleteBehavior.Cascade) diff --git a/Migrations/20231219143602_Migrate191220231734.cs b/Migrations/20231219143602_Migrate191220231734.cs index 113c98d..4f43ba3 100644 --- a/Migrations/20231219143602_Migrate191220231734.cs +++ b/Migrations/20231219143602_Migrate191220231734.cs @@ -2,7 +2,7 @@ #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { /// public partial class Migrate191220231734 : Migration diff --git a/Migrations/20231223164820_Migrate321220231944.Designer.cs b/Migrations/20231223164820_Migrate321220231944.Designer.cs index 4f06a6d..681853f 100644 --- a/Migrations/20231223164820_Migrate321220231944.Designer.cs +++ b/Migrations/20231223164820_Migrate321220231944.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using yaflay.ru.Models; +using yawaflua.ru.Models; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { [DbContext(typeof(AppDbContext))] [Migration("20231223164820_Migrate321220231944")] @@ -25,7 +25,7 @@ namespace yaflay.ru.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -64,7 +64,7 @@ namespace yaflay.ru.Migrations b.ToTable("Blogs", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -91,7 +91,7 @@ namespace yaflay.ru.Migrations b.ToTable("Comments", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Redirects", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Redirects", b => { b.Property("Id") .ValueGeneratedOnAdd() diff --git a/Migrations/20231223164820_Migrate321220231944.cs b/Migrations/20231223164820_Migrate321220231944.cs index bdc52b8..63ddce3 100644 --- a/Migrations/20231223164820_Migrate321220231944.cs +++ b/Migrations/20231223164820_Migrate321220231944.cs @@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { /// public partial class Migrate321220231944 : Migration diff --git a/Migrations/20231225062718_Migrate25122023926.Designer.cs b/Migrations/20231225062718_Migrate25122023926.Designer.cs index 8d6c5a2..9e12159 100644 --- a/Migrations/20231225062718_Migrate25122023926.Designer.cs +++ b/Migrations/20231225062718_Migrate25122023926.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using yaflay.ru.Models; +using yawaflua.ru.Models; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { [DbContext(typeof(AppDbContext))] [Migration("20231225062718_Migrate25122023926")] @@ -25,7 +25,7 @@ namespace yaflay.ru.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("yaflay.ru.Database.Tables.ApiKey", b => + modelBuilder.Entity("yawaflua.ru.Database.Tables.ApiKey", b => { b.Property("Key") .HasColumnType("text"); @@ -45,7 +45,7 @@ namespace yaflay.ru.Migrations b.ToTable("ApiKeys", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -84,7 +84,7 @@ namespace yaflay.ru.Migrations b.ToTable("Blogs", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -111,7 +111,7 @@ namespace yaflay.ru.Migrations b.ToTable("Comments", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Redirects", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Redirects", b => { b.Property("Id") .ValueGeneratedOnAdd() diff --git a/Migrations/20231225062718_Migrate25122023926.cs b/Migrations/20231225062718_Migrate25122023926.cs index cab1ab1..9883d14 100644 --- a/Migrations/20231225062718_Migrate25122023926.cs +++ b/Migrations/20231225062718_Migrate25122023926.cs @@ -2,7 +2,7 @@ #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { /// public partial class Migrate25122023926 : Migration diff --git a/Migrations/20240315193302_Migrate_22_32__15_03_2024.Designer.cs b/Migrations/20240315193302_Migrate_22_32__15_03_2024.Designer.cs new file mode 100644 index 0000000..00300c9 --- /dev/null +++ b/Migrations/20240315193302_Migrate_22_32__15_03_2024.Designer.cs @@ -0,0 +1,164 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using yawaflua.ru.Models; + +#nullable disable + +namespace yawaflua.ru.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20240315193302_Migrate_22_32__15_03_2024")] + partial class Migrate_22_32__15_03_2024 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.12") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("api.yawaflua.ru.Models.Tables.Projects", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("id")); + + b.Property("description") + .IsRequired() + .HasColumnType("text"); + + b.Property("image") + .IsRequired() + .HasColumnType("text"); + + b.Property("name") + .IsRequired() + .HasColumnType("text"); + + b.Property("url") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("id"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("yawaflua.ru.Database.Tables.ApiKey", b => + { + b.Property("Key") + .HasColumnType("text"); + + b.Property("DiscordOwnerId") + .HasColumnType("numeric(20,0)"); + + b.Property("Melon") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Key"); + + b.ToTable("ApiKeys", "public"); + }); + + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Annotation") + .IsRequired() + .HasColumnType("text"); + + b.Property("ImageUrl") + .HasColumnType("text"); + + b.Property("Text") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.Property("authorId") + .IsRequired() + .HasColumnType("text"); + + b.Property("authorNickname") + .IsRequired() + .HasColumnType("text"); + + b.Property("dateTime") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.ToTable("Blogs", "public"); + }); + + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Text") + .IsRequired() + .HasColumnType("text"); + + b.Property("creatorMail") + .IsRequired() + .HasColumnType("text"); + + b.Property("dateTime") + .HasColumnType("bigint"); + + b.Property("postId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Comments", "public"); + }); + + modelBuilder.Entity("yawaflua.ru.Models.Tables.Redirects", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("redirectTo") + .HasColumnType("text"); + + b.Property("uri") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Redirects"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20240315193302_Migrate_22_32__15_03_2024.cs b/Migrations/20240315193302_Migrate_22_32__15_03_2024.cs new file mode 100644 index 0000000..02a1174 --- /dev/null +++ b/Migrations/20240315193302_Migrate_22_32__15_03_2024.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace yawaflua.ru.Migrations +{ + /// + public partial class Migrate_22_32__15_03_2024 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Projects", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + name = table.Column(type: "text", nullable: false), + description = table.Column(type: "text", nullable: false), + url = table.Column(type: "text", nullable: false), + image = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Projects", x => x.id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Projects"); + } + } +} diff --git a/Migrations/AppDbContextModelSnapshot.cs b/Migrations/AppDbContextModelSnapshot.cs index 34fff11..91ec0cd 100644 --- a/Migrations/AppDbContextModelSnapshot.cs +++ b/Migrations/AppDbContextModelSnapshot.cs @@ -4,11 +4,11 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using yaflay.ru.Models; +using yawaflua.ru.Models; #nullable disable -namespace yaflay.ru.Migrations +namespace yawaflua.ru.Migrations { [DbContext(typeof(AppDbContext))] partial class AppDbContextModelSnapshot : ModelSnapshot @@ -22,7 +22,36 @@ namespace yaflay.ru.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("yaflay.ru.Database.Tables.ApiKey", b => + modelBuilder.Entity("api.yawaflua.ru.Models.Tables.Projects", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("id")); + + b.Property("description") + .IsRequired() + .HasColumnType("text"); + + b.Property("image") + .IsRequired() + .HasColumnType("text"); + + b.Property("name") + .IsRequired() + .HasColumnType("text"); + + b.Property("url") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("id"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("yawaflua.ru.Database.Tables.ApiKey", b => { b.Property("Key") .HasColumnType("text"); @@ -42,7 +71,7 @@ namespace yaflay.ru.Migrations b.ToTable("ApiKeys", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Blogs", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -81,7 +110,7 @@ namespace yaflay.ru.Migrations b.ToTable("Blogs", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Comments", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -108,7 +137,7 @@ namespace yaflay.ru.Migrations b.ToTable("Comments", "public"); }); - modelBuilder.Entity("yaflay.ru.Models.Tables.Redirects", b => + modelBuilder.Entity("yawaflua.ru.Models.Tables.Redirects", b => { b.Property("Id") .ValueGeneratedOnAdd() diff --git a/Models/AppDbContext.cs b/Models/AppDbContext.cs index fa362ff..5a0c1b1 100644 --- a/Models/AppDbContext.cs +++ b/Models/AppDbContext.cs @@ -1,8 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using yaflay.ru.Database.Tables; -using yaflay.ru.Models.Tables; +using api.yawaflua.ru.Models.Tables; +using Microsoft.EntityFrameworkCore; +using yawaflua.ru.Database.Tables; +using yawaflua.ru.Models.Tables; -namespace yaflay.ru.Models +namespace yawaflua.ru.Models { public class AppDbContext : DbContext { @@ -15,6 +16,7 @@ namespace yaflay.ru.Models public DbSet Comments { get; set; } public DbSet Redirects { get; set; } public DbSet ApiKeys { get; set; } + public DbSet Projects { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); diff --git a/Models/Tables/ApiKey.cs b/Models/Tables/ApiKey.cs index a4d60f3..3572e6b 100644 --- a/Models/Tables/ApiKey.cs +++ b/Models/Tables/ApiKey.cs @@ -4,9 +4,9 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Threading.Tasks; -using yaflay.ru.Auth; +using yawaflua.ru.Auth; -namespace yaflay.ru.Database.Tables; +namespace yawaflua.ru.Database.Tables; [Table("ApiKeys", Schema = "public")] public class ApiKey diff --git a/Models/Tables/Blogs.cs b/Models/Tables/Blogs.cs index 843be95..83d1ff7 100644 --- a/Models/Tables/Blogs.cs +++ b/Models/Tables/Blogs.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations.Schema; -namespace yaflay.ru.Models.Tables +namespace yawaflua.ru.Models.Tables { [Table("Blogs", Schema = "public")] public class Blogs diff --git a/Models/Tables/Comments.cs b/Models/Tables/Comments.cs index 0985391..43aacaf 100644 --- a/Models/Tables/Comments.cs +++ b/Models/Tables/Comments.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Net.Mail; -namespace yaflay.ru.Models.Tables +namespace yawaflua.ru.Models.Tables { [Table("Comments", Schema = "public")] public class Comments diff --git a/Models/Tables/Projects.cs b/Models/Tables/Projects.cs new file mode 100644 index 0000000..5da7465 --- /dev/null +++ b/Models/Tables/Projects.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace api.yawaflua.ru.Models.Tables +{ + [Table("Projects")] + public class Projects + { + [Key] + public int id { get; set; } + public string name { get; set; } + public string description { get; set; } + public string url { get; set; } + public string image { get; set; } + } +} diff --git a/Models/Tables/Redirects.cs b/Models/Tables/Redirects.cs index 393a03d..ecbd44e 100644 --- a/Models/Tables/Redirects.cs +++ b/Models/Tables/Redirects.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; -namespace yaflay.ru.Models.Tables +namespace yawaflua.ru.Models.Tables { public class Redirects { diff --git a/Pages/AdminPanel.cshtml b/Pages/AdminPanel.cshtml index c8e0c4f..35c7e2f 100644 --- a/Pages/AdminPanel.cshtml +++ b/Pages/AdminPanel.cshtml @@ -1,5 +1,5 @@ @page "{type?}" -@model yaflay.ru.Pages.AdminPanelModel +@model yawaflua.ru.Pages.AdminPanelModel @using System.Text.Json.Nodes @{ ViewData["Title"] = "AdminPanel"; diff --git a/Pages/AdminPanel.cshtml.cs b/Pages/AdminPanel.cshtml.cs index aee9ad1..dc4925f 100644 --- a/Pages/AdminPanel.cshtml.cs +++ b/Pages/AdminPanel.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace yaflay.ru.Pages +namespace yawaflua.ru.Pages { public class AdminPanelModel : PageModel { diff --git a/Pages/Authorize.cshtml b/Pages/Authorize.cshtml index e8bb050..b9b9bcc 100644 --- a/Pages/Authorize.cshtml +++ b/Pages/Authorize.cshtml @@ -1,5 +1,5 @@ @page "{code}" -@model yaflay.ru.Pages.AuthorizeModel +@model yawaflua.ru.Pages.AuthorizeModel @using System.Text.Json.Nodes @using Newtonsoft.Json @{ @@ -58,10 +58,10 @@ {

Ошибка! Попробуй авторизоваться заново

- Console.Error.WriteLine("debug: START \\/ \nDon't worry, this message is not bad as you think"); + Console.Error.WriteLine("debug: START \\/ \ninfo: Don't worry, this message is not bad as you think"); Console.Error.WriteLine("error: DiscordAuthorize is not worked"); Console.Error.WriteLine($"debug: Body from discord: {body}\ndebug: Sended data to discord: {message.Content.ReadAsStringAsync().Result}"); - Console.Error.WriteLine($"info: Check environment data: \nClientId={Startup.clientId}\nClientSecret={Startup.clientSecret}\nRedirectUrl={Startup.redirectUrl}\nOwnerId={String.Join(",", Startup.ownerId)} "); + Console.Error.WriteLine($"info: Check environment data: \n ClientId={Startup.clientId}\n ClientSecret={Startup.clientSecret}\n RedirectUrl={Startup.redirectUrl}\n OwnerId={String.Join(",", Startup.ownerId)} "); Console.Error.WriteLine("info: If any data is null and you set data in environment or appsettings.json, please create issue with this debug messages "); Console.Error.WriteLine("debug: END /\\"); } @@ -72,7 +72,7 @@ try { HttpContent bodytoApi; - bodytoApi = new StringContent(JsonConvert.SerializeObject(new yaflay.ru.Controllers.HomeController.authorizeBody() + bodytoApi = new StringContent(JsonConvert.SerializeObject(new yawaflua.ru.Controllers.ApiController.authorizeBody() { discordId = body["user"]["id"].ToString(), melon = body["access_token"].ToString(), @@ -87,7 +87,7 @@ Console.WriteLine(ex.Message); } - Response.Redirect("/authorize"); + Response.Redirect("/authorize", true); } } } diff --git a/Pages/Authorize.cshtml.cs b/Pages/Authorize.cshtml.cs index e033847..a4cee1f 100644 --- a/Pages/Authorize.cshtml.cs +++ b/Pages/Authorize.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace yaflay.ru.Pages +namespace yawaflua.ru.Pages { public class AuthorizeModel : PageModel { diff --git a/Pages/Blog.cshtml b/Pages/Blog.cshtml index 27b534d..8f73fc2 100644 --- a/Pages/Blog.cshtml +++ b/Pages/Blog.cshtml @@ -1,6 +1,6 @@ @page "{id?}" @model BlogModel -@using yaflay.ru.Models.Tables +@using yawaflua.ru.Models.Tables @using Newtonsoft.Json @{ string path = $"{this.Request.Scheme}://{this.Request.Host}"; diff --git a/Pages/Blog.cshtml.cs b/Pages/Blog.cshtml.cs index bfff5dc..11f640e 100644 --- a/Pages/Blog.cshtml.cs +++ b/Pages/Blog.cshtml.cs @@ -1,9 +1,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.RazorPages; -using yaflay.ru.Models.Tables; +using yawaflua.ru.Models.Tables; -namespace yaflay.ru.Pages +namespace yawaflua.ru.Pages { public class BlogModel : PageModel { diff --git a/Pages/Error.cshtml.cs b/Pages/Error.cshtml.cs index 4dd0e6d..cc2c845 100644 --- a/Pages/Error.cshtml.cs +++ b/Pages/Error.cshtml.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using System.Diagnostics; -namespace yaflay.ru.Pages +namespace yawaflua.ru.Pages { [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [IgnoreAntiforgeryToken] diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml index bdeed3e..ebbc081 100644 --- a/Pages/Index.cshtml +++ b/Pages/Index.cshtml @@ -1,4 +1,4 @@ -@page "{uri?}" +@page @model IndexModel @{ ViewData["Title"] = "yawaflua"; diff --git a/Pages/Index.cshtml.cs b/Pages/Index.cshtml.cs index 5b819cc..ed6155a 100644 --- a/Pages/Index.cshtml.cs +++ b/Pages/Index.cshtml.cs @@ -1,17 +1,16 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Caching.Memory; -using yaflay.ru.Models; -using yaflay.ru.Models.Tables; +using yawaflua.ru.Models; +using yawaflua.ru.Models.Tables; -namespace yaflay.ru.Pages +namespace yawaflua.ru.Pages { public class IndexModel : PageModel { private readonly ILogger _logger; public IMemoryCache cache; public AppDbContext ctx; - public string? uri { get; set; } = null; public IndexModel(ILogger logger, IMemoryCache cache, AppDbContext ctx) { _logger = logger; @@ -19,28 +18,11 @@ namespace yaflay.ru.Pages this.ctx = ctx; } - public void OnGet(string? uri) + public void OnGet() { + + Page(); - this.uri = uri ?? null; - Console.WriteLine(uri); - if (this.uri != null) - { - Redirects? fromCache = cache.Get($"redirectsWithUrl-{uri}") ?? null; - if (fromCache == null) - { - fromCache = ctx.Redirects.FirstOrDefault(k => k.uri == uri); - Console.WriteLine("Im here!"); - if (fromCache != null) - cache.Set($"redirectsWithUrl-{uri}", (object)fromCache, DateTime.Now.AddMinutes(10)); - } - Console.WriteLine(fromCache?.ToString()); - Response.Redirect(fromCache?.redirectTo ?? "/404"); - } - else - { - Page(); - } } } diff --git a/Pages/NotFound.cshtml.cs b/Pages/NotFound.cshtml.cs index fd38070..7a328de 100644 --- a/Pages/NotFound.cshtml.cs +++ b/Pages/NotFound.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace yaflay.ru.Pages +namespace yawaflua.ru.Pages { public class Index1Model : PageModel { diff --git a/Pages/Privacy.cshtml.cs b/Pages/Privacy.cshtml.cs index ae14f07..5040c53 100644 --- a/Pages/Privacy.cshtml.cs +++ b/Pages/Privacy.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace yaflay.ru.Pages +namespace yawaflua.ru.Pages { public class PrivacyModel : PageModel { diff --git a/Pages/_ViewImports.cshtml b/Pages/_ViewImports.cshtml index 53d6583..56b9d61 100644 --- a/Pages/_ViewImports.cshtml +++ b/Pages/_ViewImports.cshtml @@ -1,3 +1,3 @@ -@using yaflay.ru -@namespace yaflay.ru.Pages +@using yawaflua.ru +@namespace yawaflua.ru.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/Pages/rrobotsTxt.cshtml b/Pages/rrobotsTxt.cshtml new file mode 100644 index 0000000..263d25e --- /dev/null +++ b/Pages/rrobotsTxt.cshtml @@ -0,0 +1,12 @@ +@page +@{ + Layout = null; + this.Response.ContentType = "text/plain"; +} +User-agent: * +Disallow: /* +Disallow: /* +Allow: /Blog +Allow: /Blog/* +Allow: /Privacy +Allow: / \ No newline at end of file diff --git a/Program.cs b/Program.cs index 325b4af..7eccd3b 100644 --- a/Program.cs +++ b/Program.cs @@ -1,25 +1,10 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; -using yaflay.ru; +using yawaflua.ru; public class Program { public static void Main() { - Func parse = (string name) => Environment.GetEnvironmentVariable(name) ?? null; - - Startup.clientId = parse("CLIENTID"); - Startup.clientSecret = parse("CLIENTSECRET"); - Startup.redirectUrl = parse("REDIRECTURL"); - if (!(parse("PSQL_HOST") == null | parse("PSQL_USER") == null | parse("PSQL_PASSWORD") == null | parse("PSQL_DATABASE") == null)) - { - Startup.connectionString = $"Host={parse("PSQL_HOST")};Username={parse("PSQL_USER")};Password={parse("PSQL_PASSWORD")};Database={parse("PSQL_DATABASE")}"; - } - if (parse("OWNERID") != null) - { - Startup.ownerId = new string?[] { parse("OWNERID") }; - } - Startup.readmeFile = parse("READMEFILE"); - CreateHostBuilder() .Build() .Run(); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 8ae4c6c..58d7044 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -1,35 +1,45 @@ { - "profiles": { - "yaflay.ru": { - "commandName": "Project", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "dotnetRunMessages": true, - "applicationUrl": "https://localhost:7269;http://localhost:5070" - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "Docker": { - "commandName": "Docker", - "launchBrowser": true, - "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", - "publishAllPorts": true, - "useSSL": true - } - }, + "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:3236", - "sslPort": 44373 + "applicationUrl": "http://localhost:16072", + "sslPort": 44366 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5144", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7049;http://localhost:5144", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy" + } } } -} \ No newline at end of file +} + diff --git a/Startup.cs b/Startup.cs index 27e956a..9ba3bfc 100644 --- a/Startup.cs +++ b/Startup.cs @@ -5,12 +5,14 @@ using System.Reflection.Metadata.Ecma335; using System.Runtime.CompilerServices; using DotNetEd.CoreAdmin; using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Mvc.TagHelpers; using Microsoft.EntityFrameworkCore; -using yaflay.ru.Auth; -using yaflay.ru.Models; +using Microsoft.Extensions.Caching.Memory; +using yawaflua.ru.Auth; +using yawaflua.ru.Models; -namespace yaflay.ru +namespace yawaflua.ru { public class Startup { @@ -28,40 +30,16 @@ namespace yaflay.ru public Startup() { configuration = new ConfigurationBuilder() - .AddEnvironmentVariables(prefix: "m.") + .AddEnvironmentVariables() .AddJsonFile("appsettings.json", optional: true) .Build(); - if (clientId == null | clientSecret == null | redirectUrl == null) - { - clientId = configuration.GetValue("clientId"); - clientSecret = configuration.GetValue("clientSecret"); - redirectUrl = configuration.GetValue("redirectUrl"); - } - if (connectionString == null) - { - connectionString = configuration.GetValue("connectionString"); - Console.WriteLine("Connectionstring" + connectionString); - if (connectionString == null) - { - throw new ArgumentException("ConnectionString is null!"); - } - } - if (ownerId == null) - { - ownerId = new[] { configuration.GetValue("ownerId") }; - if (ownerId?.Length == 0) - { - throw new ArgumentException("Owner id is null!"); - } - } - if (readmeFile == null) - { - readmeFile = configuration.GetValue("readmeFile"); - if (readmeFile == null) - { - throw new ArgumentException("ReadmeFile link is null"); - } - } + + clientId = configuration.GetValue("clientId"); + clientSecret = configuration.GetValue("clientSecret"); + redirectUrl = configuration.GetValue("redirectUrl"); + connectionString = configuration.GetValue("connectionString"); + ownerId = configuration.GetValue("ownerId"); + readmeFile = configuration.GetValue("readmeFile"); } public void ConfigureServices(IServiceCollection services) @@ -81,6 +59,8 @@ namespace yaflay.ru .AddTransient() .AddSingleton(configuration) .AddDbContext(c => c.UseNpgsql(connectionString: connectionString)) + .AddSwaggerGen() + .AddSingleton(new MemoryCache(new MemoryCacheOptions())) .AddAuthorization(k => { k.AddPolicy("DISCORD-OAUTH-PUBLIC", policyBuilder => { @@ -98,12 +78,13 @@ namespace yaflay.ru options.DefaultChallengeScheme = "Bearer"; options.AddScheme("DISCORD-OAUTH-PRIVATE", "DISCORD-OAUTH-PRIVATE"); options.AddScheme("DISCORD-OAUTH-PUBLIC", "DISCORD-OAUTH-PUBLIC"); + options.RequireAuthenticatedSignIn = false; }).AddScheme("Bearer", options => {}); services.AddMvc() .AddRazorPagesOptions(options => { options.Conventions.AddPageRoute("/RobotsTxt", "/Robots.txt"); - options.Conventions.AddPageRoute("/RobotsTxt", "/robots.txt"); + options.Conventions.AddPageRoute("/rrobotsTxt", "/robots.txt"); options.Conventions.AddPageRoute("/NotFound", "/404"); options.Conventions.AddPageRoute("/IternalErrorPage", "/500"); options.Conventions.AddPageRoute("/Authorize", "/authorize"); @@ -132,17 +113,24 @@ namespace yaflay.ru app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); + app.UseSwagger((options) => + { + options.RouteTemplate = "swagger/v1/swagger.json"; + }); + app.UseSwaggerUI(); #if DEBUG app.UseCoreAdminCustomTitle("yawaflua"); app.UseCoreAdminCustomAuth((k) => Task.FromResult(true)); app.UseCoreAdminCustomUrl("admin/coreadmin"); #endif - app.UseCors(k => { k.AllowAnyMethod(); k.AllowAnyOrigin(); k.AllowAnyHeader(); }); + app.UseCors(k => { k.WithMethods("POST", "GET", "PATCH", "PUT"); k.AllowAnyOrigin(); k.AllowAnyHeader(); }); app.UseEndpoints(endpoints => { - endpoints.MapDefaultControllerRoute(); + endpoints.MapDefaultControllerRoute().AllowAnonymous(); + endpoints.MapFallbackToFile("/index.html").AllowAnonymous(); + endpoints.MapSwagger(); endpoints.MapRazorPages(); - endpoints.MapControllers(); + endpoints.MapControllers().AllowAnonymous(); }); } diff --git a/Utilities/AppDbContextUtilities.cs b/Utilities/AppDbContextUtilities.cs new file mode 100644 index 0000000..58af4ee --- /dev/null +++ b/Utilities/AppDbContextUtilities.cs @@ -0,0 +1,13 @@ +using Microsoft.EntityFrameworkCore; + +namespace yawaflua.ru.Utilities +{ + public static class AppDbContextUtilities + { + public static bool TryGetValue(this DbSet set, Func predicate, out T? value) where T : class + { + value = set.FirstOrDefault(predicate); + return value != null; + } + } +} diff --git a/yaflay.ru.csproj b/api.yawaflua.ru.csproj similarity index 63% rename from yaflay.ru.csproj rename to api.yawaflua.ru.csproj index f1b3b19..efdbc0d 100644 --- a/yaflay.ru.csproj +++ b/api.yawaflua.ru.csproj @@ -1,15 +1,33 @@ - net7.0 + net8.0 enable enable 0c1057bc-b206-4a40-b003-9b6299aa9c64 Linux . true + yawaflua + yawaflua + npm run serve -- --host 0.0.0.0 --port 8080 + http://localhost:8080 + ..\frontend.yawaflua.ru + + + 8.*-* + + + + + + + false + + + diff --git a/yaflay.ru.sln b/yawaflua.ru.sln similarity index 59% rename from yaflay.ru.sln rename to yawaflua.ru.sln index 6d36628..242ee10 100644 --- a/yaflay.ru.sln +++ b/yawaflua.ru.sln @@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.6.33723.286 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "yaflay.ru", "yaflay.ru.csproj", "{3AA2FE9B-D1AF-4B12-B090-7E4529BA40E0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api.yawaflua.ru", "api.yawaflua.ru.csproj", "{3AA2FE9B-D1AF-4B12-B090-7E4529BA40E0}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{82D95147-E21B-45B6-B636-A145A498D56E}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig EndProjectSection EndProject +Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "frontend.yawaflua.ru", "..\frontend.yawaflua.ru\frontend.yawaflua.ru.esproj", "{62466D84-4FD6-4CF4-ACA2-C19662E6B7FD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -20,6 +22,12 @@ Global {3AA2FE9B-D1AF-4B12-B090-7E4529BA40E0}.Debug|Any CPU.Build.0 = Debug|Any CPU {3AA2FE9B-D1AF-4B12-B090-7E4529BA40E0}.Release|Any CPU.ActiveCfg = Release|Any CPU {3AA2FE9B-D1AF-4B12-B090-7E4529BA40E0}.Release|Any CPU.Build.0 = Release|Any CPU + {62466D84-4FD6-4CF4-ACA2-C19662E6B7FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62466D84-4FD6-4CF4-ACA2-C19662E6B7FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62466D84-4FD6-4CF4-ACA2-C19662E6B7FD}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {62466D84-4FD6-4CF4-ACA2-C19662E6B7FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62466D84-4FD6-4CF4-ACA2-C19662E6B7FD}.Release|Any CPU.Build.0 = Release|Any CPU + {62466D84-4FD6-4CF4-ACA2-C19662E6B7FD}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE