From 94cec9496f7085034b0b502a4b6a0686cbc2079a Mon Sep 17 00:00:00 2001 From: James Pretorius Date: Tue, 23 Jan 2024 14:44:47 -0500 Subject: [PATCH] Formatting/Style rules & fixes --- FU.API/.editorconfig | 49 +- FU.API/FU.API/Controllers/SearchController.cs | 6 +- FU.API/FU.API/DTOs/Group/GroupSimpleDTO.cs | 28 +- FU.API/FU.API/Data/AppDbContext.cs | 42 +- FU.API/FU.API/Helpers/Exceptions.cs | 4 +- .../IsLoggedInAuthenticationHandler.cs | 5 +- .../FU.API/Helpers/IsLoggedInRequirement.cs | 2 + FU.API/FU.API/Hubs/ChatHub.cs | 3 +- FU.API/FU.API/Interfaces/ICommonService.cs | 24 +- FU.API/FU.API/Interfaces/IPostService.cs | 28 +- FU.API/FU.API/Interfaces/ISearchService.cs | 16 +- FU.API/FU.API/Interfaces/IUserService.cs | 32 +- .../20231127022356_InitialDatabase.cs | 1032 ++++++++--------- ...231203001316_NonNullablePostDescription.cs | 72 +- ...240123145358_NormalizedPostDescAndTitle.cs | 80 +- FU.API/FU.API/Models/Post.cs | 4 +- FU.API/FU.API/Program.cs | 2 +- FU.API/FU.API/Services/AccountsService.cs | 2 +- FU.API/FU.API/Services/CommonService.cs | 101 +- FU.API/FU.API/Services/SearchService.cs | 10 +- FU.API/out.json | 254 ++++ 21 files changed, 1036 insertions(+), 760 deletions(-) create mode 100644 FU.API/out.json diff --git a/FU.API/.editorconfig b/FU.API/.editorconfig index e4be8d55..6426f465 100644 --- a/FU.API/.editorconfig +++ b/FU.API/.editorconfig @@ -3,6 +3,14 @@ # SA1633: File should have header dotnet_diagnostic.SA1633.severity = none +# Xml Comment Analysis Disabled warning +dotnet_diagnostic.SA0001.severity = none + +# KeywordsMustBeSpacedCorrectly +# disabled because conflicts with formatter +# should never happed if using a formatter anyways +dotnet_diagnostic.SA1000.severity = none + # SA1201: Elements should appear in the correct order dotnet_diagnostic.SA1201.severity = none @@ -13,21 +21,23 @@ dotnet_diagnostic.SA1600.severity = none # SA1413: Use trailing comma in multi-line initializers dotnet_diagnostic.SA1413.severity = none csharp_indent_labels = one_less_than_current -csharp_using_directive_placement = outside_namespace:silent +csharp_using_directive_placement = inside_namespace csharp_prefer_simple_using_statement = true:suggestion -csharp_prefer_braces = true:silent -csharp_style_namespace_declarations = block_scoped:silent -csharp_style_prefer_method_group_conversion = true:silent -csharp_style_prefer_top_level_statements = true:silent +csharp_prefer_braces = true +csharp_style_namespace_declarations = file_scoped +csharp_style_prefer_method_group_conversion = true +csharp_style_prefer_top_level_statements = true csharp_style_prefer_primary_constructors = true:suggestion -csharp_style_expression_bodied_methods = false:silent -csharp_style_expression_bodied_constructors = false:silent -csharp_style_expression_bodied_operators = false:silent -csharp_style_expression_bodied_properties = true:silent -csharp_style_expression_bodied_indexers = true:silent -csharp_style_expression_bodied_accessors = true:silent -csharp_style_expression_bodied_lambdas = true:silent -csharp_style_expression_bodied_local_functions = false:silent +csharp_style_expression_bodied_methods = false +csharp_style_expression_bodied_constructors = false +csharp_style_expression_bodied_operators = false +csharp_style_expression_bodied_properties = true +csharp_style_expression_bodied_indexers = true +csharp_style_expression_bodied_accessors = true +csharp_style_expression_bodied_lambdas = true +csharp_style_expression_bodied_local_functions = false +dotnet_diagnostic.IDE0007.severity = none +dotnet_diagnostic.IDE0008.severity = none csharp_space_around_binary_operators = before_and_after [*.{cs,vb}] @@ -84,10 +94,19 @@ end_of_line = crlf dotnet_style_coalesce_expression = true:suggestion dotnet_style_null_propagation = true:suggestion dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion -dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_auto_properties = true dotnet_style_object_initializer = true:suggestion dotnet_style_collection_initializer = true:suggestion dotnet_style_prefer_simplified_boolean_expressions = true:suggestion # SA:1602 Disable enumeration documentation -dotnet_diagnostic.SA1602.severity = none \ No newline at end of file +dotnet_diagnostic.SA1602.severity = none + +# Disable langauge rules +dotnet_diagnostic.CA1303.severity = none +dotnet_diagnostic.CA1304.severity = none +dotnet_diagnostic.CA1311.severity = none +dotnet_diagnostic.CA1305.severity = none + +# disable style rules so they don't overlap with stylecop +dotnet_analyzer_diagnostic.category-Style.severity = none diff --git a/FU.API/FU.API/Controllers/SearchController.cs b/FU.API/FU.API/Controllers/SearchController.cs index 23f58858..a06e2fdd 100644 --- a/FU.API/FU.API/Controllers/SearchController.cs +++ b/FU.API/FU.API/Controllers/SearchController.cs @@ -2,10 +2,8 @@ namespace FU.API.Controllers; using FU.API.DTOs.Post; using FU.API.DTOs.Search; -using FU.API.Exceptions; using FU.API.Helpers; using FU.API.Interfaces; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; [ApiController] @@ -24,7 +22,7 @@ public SearchController(ISearchService searchService) public async Task SearchPosts([FromQuery] PostSearchRequestDTO request) { var posts = await _searchService.SearchPosts(request.ToPostQuery()); - var response = new List(posts.Count()); + var response = new List(posts.Count); // Go through each post and check if the user has joined the post var user = await _searchService.GetCurrentUser(User); @@ -44,4 +42,4 @@ public async Task SearchPosts([FromQuery] PostSearchRequestDTO re return Ok(response); } -} \ No newline at end of file +} diff --git a/FU.API/FU.API/DTOs/Group/GroupSimpleDTO.cs b/FU.API/FU.API/DTOs/Group/GroupSimpleDTO.cs index f0d9f637..7db8f6f6 100644 --- a/FU.API/FU.API/DTOs/Group/GroupSimpleDTO.cs +++ b/FU.API/FU.API/DTOs/Group/GroupSimpleDTO.cs @@ -1,14 +1,14 @@ -namespace FU.API.DTOs.Group; - -public class GroupSimpleDTO -{ - public int Id { get; set; } - - public string Name { get; set; } = string.Empty; - - public string? Description { get; set; } - - public int ChatId { get; set; } - - public ICollection Tags { get; set; } = new HashSet(); -} +namespace FU.API.DTOs.Group; + +public class GroupSimpleDTO +{ + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string? Description { get; set; } + + public int ChatId { get; set; } + + public ICollection Tags { get; set; } = new HashSet(); +} diff --git a/FU.API/FU.API/Data/AppDbContext.cs b/FU.API/FU.API/Data/AppDbContext.cs index 5e3b77e5..f467ec17 100644 --- a/FU.API/FU.API/Data/AppDbContext.cs +++ b/FU.API/FU.API/Data/AppDbContext.cs @@ -20,100 +20,100 @@ public AppDbContext(DbContextOptions options) /// /// Create new models. /// - /// The builder. - protected override void OnModelCreating(ModelBuilder builder) + /// The builder. + protected override void OnModelCreating(ModelBuilder modelBuilder) { // Give 1 foreign key to Chat for LastMessage - builder.Entity() + modelBuilder.Entity() .HasOne(c => c.LastMessage) .WithOne() .HasForeignKey(c => c.LastMessageId); // Make sure the username is unique - builder.Entity() + modelBuilder.Entity() .HasIndex(u => u.Username) .IsUnique(); // Make sure the email is unique - builder.Entity() + modelBuilder.Entity() .HasIndex(u => u.Email) .IsUnique(); // Make sure the name of the tag is unique - builder.Entity() + modelBuilder.Entity() .HasIndex(t => t.Name) .IsUnique(); // Make sure the name of the group is unique - builder.Entity() + modelBuilder.Entity() .HasIndex(g => g.Name) .IsUnique(); // Make sure the name of the game is unique - builder.Entity() + modelBuilder.Entity() .HasIndex(g => g.Name) .IsUnique(); - base.OnModelCreating(builder); + base.OnModelCreating(modelBuilder); } /// /// Gets or sets the users. /// - public DbSet Users { get; set; } + public DbSet Users { get; set; } = null!; /// /// Gets or sets UserRelations. /// - public DbSet UserRelations { get; set; } + public DbSet UserRelations { get; set; } = null!; /// /// Gets or sets chats. /// - public DbSet Chats { get; set; } + public DbSet Chats { get; set; } = null!; /// /// Gets or sets ChatMemberships. /// - public DbSet ChatMemberships { get; set; } + public DbSet ChatMemberships { get; set; } = null!; /// /// Gets or sets Messages. /// - public DbSet Messages { get; set; } + public DbSet Messages { get; set; } = null!; /// /// Gets or sets Games. /// - public DbSet Games { get; set; } + public DbSet Games { get; set; } = null!; /// /// Gets or sets GameRelations. /// - public DbSet GameRelations { get; set; } + public DbSet GameRelations { get; set; } = null!; /// /// Gets or sets Groups. /// - public DbSet Groups { get; set; } + public DbSet Groups { get; set; } = null!; /// /// Gets or sets GroupMemberships. /// - public DbSet GroupMemberships { get; set; } + public DbSet GroupMemberships { get; set; } = null!; /// /// Gets or sets Posts. /// - public DbSet Posts { get; set; } + public DbSet Posts { get; set; } = null!; /// /// Gets or sets Tags. /// - public DbSet Tags { get; set; } + public DbSet Tags { get; set; } = null!; /// /// Gets or sets TagRelations. /// - public DbSet TagRelations { get; set; } + public DbSet TagRelations { get; set; } = null!; } diff --git a/FU.API/FU.API/Helpers/Exceptions.cs b/FU.API/FU.API/Helpers/Exceptions.cs index d731938a..476424af 100644 --- a/FU.API/FU.API/Helpers/Exceptions.cs +++ b/FU.API/FU.API/Helpers/Exceptions.cs @@ -13,7 +13,7 @@ public abstract class ExceptionWithResponse : Exception public ProblemDetails GetProblemDetails() { - return new () + return new() { Title = Title, Detail = Description, @@ -116,4 +116,4 @@ public ConflictException(string description) { Description = description; } -} \ No newline at end of file +} diff --git a/FU.API/FU.API/Helpers/IsLoggedInAuthenticationHandler.cs b/FU.API/FU.API/Helpers/IsLoggedInAuthenticationHandler.cs index 2b28a716..1a9a0362 100644 --- a/FU.API/FU.API/Helpers/IsLoggedInAuthenticationHandler.cs +++ b/FU.API/FU.API/Helpers/IsLoggedInAuthenticationHandler.cs @@ -1,4 +1,5 @@ -using FU.API.Helpers; +namespace FU.API.Helpers; + using Microsoft.AspNetCore.Authorization; /// @@ -31,4 +32,4 @@ protected override Task HandleRequirementAsync(AuthorizationHandlerContext conte return Task.CompletedTask; } -} \ No newline at end of file +} diff --git a/FU.API/FU.API/Helpers/IsLoggedInRequirement.cs b/FU.API/FU.API/Helpers/IsLoggedInRequirement.cs index ab6056c7..fb22c545 100644 --- a/FU.API/FU.API/Helpers/IsLoggedInRequirement.cs +++ b/FU.API/FU.API/Helpers/IsLoggedInRequirement.cs @@ -1,3 +1,5 @@ +namespace FU.API.Helpers; + using Microsoft.AspNetCore.Authorization; /// diff --git a/FU.API/FU.API/Hubs/ChatHub.cs b/FU.API/FU.API/Hubs/ChatHub.cs index 4b187c08..40c7e65d 100644 --- a/FU.API/FU.API/Hubs/ChatHub.cs +++ b/FU.API/FU.API/Hubs/ChatHub.cs @@ -3,7 +3,6 @@ using System; using FU.API.Data; using FU.API.Helpers; -using FU.API.Interfaces; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.SignalR; @@ -16,7 +15,7 @@ public class ChatHub : Hub /// /// List of the connected users names. /// - public static readonly List ConnectedUsers = new (); + public static readonly List ConnectedUsers = new(); /// /// The app db context. diff --git a/FU.API/FU.API/Interfaces/ICommonService.cs b/FU.API/FU.API/Interfaces/ICommonService.cs index bac99cb2..39a73628 100644 --- a/FU.API/FU.API/Interfaces/ICommonService.cs +++ b/FU.API/FU.API/Interfaces/ICommonService.cs @@ -1,13 +1,13 @@ -namespace FU.API.Interfaces; - -using FU.API.Models; -using System.Security.Claims; - -public interface ICommonService -{ - Task GetCurrentUser(ClaimsPrincipal claims); - - Task GetUser(int userId); - - Task HasJoinedPost(int userId, int postId); +namespace FU.API.Interfaces; + +using FU.API.Models; +using System.Security.Claims; + +public interface ICommonService +{ + Task GetCurrentUser(ClaimsPrincipal claims); + + Task GetUser(int userId); + + Task HasJoinedPost(int userId, int postId); } \ No newline at end of file diff --git a/FU.API/FU.API/Interfaces/IPostService.cs b/FU.API/FU.API/Interfaces/IPostService.cs index 19e3d16e..55b48fb3 100644 --- a/FU.API/FU.API/Interfaces/IPostService.cs +++ b/FU.API/FU.API/Interfaces/IPostService.cs @@ -1,14 +1,14 @@ -namespace FU.API.Interfaces; - -using FU.API.Models; - -public interface IPostService : ICommonService -{ - Task CreatePost(Post post); - - Task GetPost(int postId); - - Task JoinPost(int postId, ApplicationUser user); - - Task LeavePost(int postId, ApplicationUser user); -} +namespace FU.API.Interfaces; + +using FU.API.Models; + +public interface IPostService : ICommonService +{ + Task CreatePost(Post post); + + Task GetPost(int postId); + + Task JoinPost(int postId, ApplicationUser user); + + Task LeavePost(int postId, ApplicationUser user); +} diff --git a/FU.API/FU.API/Interfaces/ISearchService.cs b/FU.API/FU.API/Interfaces/ISearchService.cs index 6d09686d..eeb9a137 100644 --- a/FU.API/FU.API/Interfaces/ISearchService.cs +++ b/FU.API/FU.API/Interfaces/ISearchService.cs @@ -1,8 +1,8 @@ -namespace FU.API.Interfaces; - -using FU.API.Models; - -public interface ISearchService : ICommonService -{ - Task> SearchPosts(PostQuery query); -} +namespace FU.API.Interfaces; + +using FU.API.Models; + +public interface ISearchService : ICommonService +{ + Task> SearchPosts(PostQuery query); +} diff --git a/FU.API/FU.API/Interfaces/IUserService.cs b/FU.API/FU.API/Interfaces/IUserService.cs index 75c7aa15..3bfa39e7 100644 --- a/FU.API/FU.API/Interfaces/IUserService.cs +++ b/FU.API/FU.API/Interfaces/IUserService.cs @@ -1,16 +1,16 @@ -namespace FU.API.Interfaces; - -using FU.API.Models; - -public interface IUserService : ICommonService -{ - Task GetUserProfile(int userId); - - Task UpdateUserProfile(UserProfile profileChanges); - - Task> GetUsersAssociatedPosts(int userId, int limit, int offset); - - Task> GetUsersGroups(int userId, int limit, int offset); - - Task> GetUsersPlayers(int userId, int limit, int offset); -} +namespace FU.API.Interfaces; + +using FU.API.Models; + +public interface IUserService : ICommonService +{ + Task GetUserProfile(int userId); + + Task UpdateUserProfile(UserProfile profileChanges); + + Task> GetUsersAssociatedPosts(int userId, int limit, int offset); + + Task> GetUsersGroups(int userId, int limit, int offset); + + Task> GetUsersPlayers(int userId, int limit, int offset); +} diff --git a/FU.API/FU.API/Migrations/20231127022356_InitialDatabase.cs b/FU.API/FU.API/Migrations/20231127022356_InitialDatabase.cs index dbda35bf..3aa64ec1 100644 --- a/FU.API/FU.API/Migrations/20231127022356_InitialDatabase.cs +++ b/FU.API/FU.API/Migrations/20231127022356_InitialDatabase.cs @@ -1,516 +1,516 @@ -#nullable disable - -namespace FU.API.Migrations -{ - using System; - using Microsoft.EntityFrameworkCore.Migrations; - using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - - /// - public partial class InitialDatabase : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Games", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "text", nullable: false), - NormalizedName = table.Column(type: "text", nullable: false), - ImageUrl = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Games", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Tags", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Tags", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - UserId = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - PfpUrl = table.Column(type: "text", nullable: false), - IsOnline = table.Column(type: "boolean", nullable: false), - IsAdmin = table.Column(type: "boolean", nullable: false), - Bio = table.Column(type: "text", nullable: true), - DOB = table.Column(type: "date", nullable: true), - Username = table.Column(type: "text", nullable: false), - NormalizedUsername = table.Column(type: "text", nullable: false), - PasswordHash = table.Column(type: "text", nullable: false), - Email = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.UserId); - }); - - migrationBuilder.CreateTable( - name: "GameRelations", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - GameId = table.Column(type: "integer", nullable: false), - ApplicationUserUserId = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_GameRelations", x => x.Id); - table.ForeignKey( - name: "FK_GameRelations_Games_GameId", - column: x => x.GameId, - principalTable: "Games", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_GameRelations_Users_ApplicationUserUserId", - column: x => x.ApplicationUserUserId, - principalTable: "Users", - principalColumn: "UserId"); - }); - - migrationBuilder.CreateTable( - name: "UserRelations", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - User1Id = table.Column(type: "integer", nullable: false), - User2Id = table.Column(type: "integer", nullable: false), - Status = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserRelations", x => x.Id); - table.ForeignKey( - name: "FK_UserRelations_Users_User1Id", - column: x => x.User1Id, - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_UserRelations_Users_User2Id", - column: x => x.User2Id, - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ChatMemberships", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "integer", nullable: false), - ChatId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ChatMemberships", x => x.Id); - table.ForeignKey( - name: "FK_ChatMemberships_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Chats", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ChatName = table.Column(type: "text", nullable: true), - ChatType = table.Column(type: "integer", nullable: false), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), - LastMessageId = table.Column(type: "integer", nullable: true), - LastMessageAt = table.Column(type: "timestamp with time zone", nullable: true), - CreatorId = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Chats", x => x.Id); - table.ForeignKey( - name: "FK_Chats_Users_CreatorId", - column: x => x.CreatorId, - principalTable: "Users", - principalColumn: "UserId"); - }); - - migrationBuilder.CreateTable( - name: "Groups", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "text", nullable: false), - NormalizedName = table.Column(type: "text", nullable: false), - ImageUrl = table.Column(type: "text", nullable: true), - Description = table.Column(type: "text", nullable: true), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), - CreatorId = table.Column(type: "integer", nullable: true), - ChatId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Groups", x => x.Id); - table.ForeignKey( - name: "FK_Groups_Chats_ChatId", - column: x => x.ChatId, - principalTable: "Chats", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Groups_Users_CreatorId", - column: x => x.CreatorId, - principalTable: "Users", - principalColumn: "UserId"); - }); - - migrationBuilder.CreateTable( - name: "Messages", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), - Content = table.Column(type: "text", nullable: false), - SenderId = table.Column(type: "integer", nullable: false), - ChatId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Messages", x => x.Id); - table.ForeignKey( - name: "FK_Messages_Chats_ChatId", - column: x => x.ChatId, - principalTable: "Chats", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Messages_Users_SenderId", - column: x => x.SenderId, - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Posts", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Title = table.Column(type: "text", nullable: false), - GameId = table.Column(type: "integer", nullable: false), - Description = table.Column(type: "text", nullable: true), - StartTime = table.Column(type: "timestamp with time zone", nullable: true), - EndTime = table.Column(type: "timestamp with time zone", nullable: true), - MaxPlayers = table.Column(type: "integer", nullable: true), - ChatId = table.Column(type: "integer", nullable: false), - CreatorId = table.Column(type: "integer", nullable: false), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Posts", x => x.Id); - table.ForeignKey( - name: "FK_Posts_Chats_ChatId", - column: x => x.ChatId, - principalTable: "Chats", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Posts_Games_GameId", - column: x => x.GameId, - principalTable: "Games", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Posts_Users_CreatorId", - column: x => x.CreatorId, - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "GroupMemberships", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "integer", nullable: false), - GroupId = table.Column(type: "integer", nullable: false), - Role = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_GroupMemberships", x => x.Id); - table.ForeignKey( - name: "FK_GroupMemberships_Groups_GroupId", - column: x => x.GroupId, - principalTable: "Groups", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_GroupMemberships_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "TagRelations", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - TagId = table.Column(type: "integer", nullable: false), - ApplicationUserUserId = table.Column(type: "integer", nullable: true), - GroupId = table.Column(type: "integer", nullable: true), - PostId = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_TagRelations", x => x.Id); - table.ForeignKey( - name: "FK_TagRelations_Groups_GroupId", - column: x => x.GroupId, - principalTable: "Groups", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_TagRelations_Posts_PostId", - column: x => x.PostId, - principalTable: "Posts", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_TagRelations_Tags_TagId", - column: x => x.TagId, - principalTable: "Tags", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_TagRelations_Users_ApplicationUserUserId", - column: x => x.ApplicationUserUserId, - principalTable: "Users", - principalColumn: "UserId"); - }); - - migrationBuilder.CreateIndex( - name: "IX_ChatMemberships_ChatId", - table: "ChatMemberships", - column: "ChatId"); - - migrationBuilder.CreateIndex( - name: "IX_ChatMemberships_UserId", - table: "ChatMemberships", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_Chats_CreatorId", - table: "Chats", - column: "CreatorId"); - - migrationBuilder.CreateIndex( - name: "IX_Chats_LastMessageId", - table: "Chats", - column: "LastMessageId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_GameRelations_ApplicationUserUserId", - table: "GameRelations", - column: "ApplicationUserUserId"); - - migrationBuilder.CreateIndex( - name: "IX_GameRelations_GameId", - table: "GameRelations", - column: "GameId"); - - migrationBuilder.CreateIndex( - name: "IX_Games_Name", - table: "Games", - column: "Name", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_GroupMemberships_GroupId", - table: "GroupMemberships", - column: "GroupId"); - - migrationBuilder.CreateIndex( - name: "IX_GroupMemberships_UserId", - table: "GroupMemberships", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_Groups_ChatId", - table: "Groups", - column: "ChatId"); - - migrationBuilder.CreateIndex( - name: "IX_Groups_CreatorId", - table: "Groups", - column: "CreatorId"); - - migrationBuilder.CreateIndex( - name: "IX_Groups_Name", - table: "Groups", - column: "Name", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Messages_ChatId", - table: "Messages", - column: "ChatId"); - - migrationBuilder.CreateIndex( - name: "IX_Messages_SenderId", - table: "Messages", - column: "SenderId"); - - migrationBuilder.CreateIndex( - name: "IX_Posts_ChatId", - table: "Posts", - column: "ChatId"); - - migrationBuilder.CreateIndex( - name: "IX_Posts_CreatorId", - table: "Posts", - column: "CreatorId"); - - migrationBuilder.CreateIndex( - name: "IX_Posts_GameId", - table: "Posts", - column: "GameId"); - - migrationBuilder.CreateIndex( - name: "IX_TagRelations_ApplicationUserUserId", - table: "TagRelations", - column: "ApplicationUserUserId"); - - migrationBuilder.CreateIndex( - name: "IX_TagRelations_GroupId", - table: "TagRelations", - column: "GroupId"); - - migrationBuilder.CreateIndex( - name: "IX_TagRelations_PostId", - table: "TagRelations", - column: "PostId"); - - migrationBuilder.CreateIndex( - name: "IX_TagRelations_TagId", - table: "TagRelations", - column: "TagId"); - - migrationBuilder.CreateIndex( - name: "IX_Tags_Name", - table: "Tags", - column: "Name", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_UserRelations_User1Id", - table: "UserRelations", - column: "User1Id"); - - migrationBuilder.CreateIndex( - name: "IX_UserRelations_User2Id", - table: "UserRelations", - column: "User2Id"); - - migrationBuilder.CreateIndex( - name: "IX_Users_Email", - table: "Users", - column: "Email", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Users_Username", - table: "Users", - column: "Username", - unique: true); - - migrationBuilder.AddForeignKey( - name: "FK_ChatMemberships_Chats_ChatId", - table: "ChatMemberships", - column: "ChatId", - principalTable: "Chats", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_Chats_Messages_LastMessageId", - table: "Chats", - column: "LastMessageId", - principalTable: "Messages", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Messages_Chats_ChatId", - table: "Messages"); - - migrationBuilder.DropTable( - name: "ChatMemberships"); - - migrationBuilder.DropTable( - name: "GameRelations"); - - migrationBuilder.DropTable( - name: "GroupMemberships"); - - migrationBuilder.DropTable( - name: "TagRelations"); - - migrationBuilder.DropTable( - name: "UserRelations"); - - migrationBuilder.DropTable( - name: "Groups"); - - migrationBuilder.DropTable( - name: "Posts"); - - migrationBuilder.DropTable( - name: "Tags"); - - migrationBuilder.DropTable( - name: "Games"); - - migrationBuilder.DropTable( - name: "Chats"); - - migrationBuilder.DropTable( - name: "Messages"); - - migrationBuilder.DropTable( - name: "Users"); - } - } -} +#nullable disable + +namespace FU.API.Migrations +{ + using System; + using Microsoft.EntityFrameworkCore.Migrations; + using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + + /// + public partial class InitialDatabase : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Games", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + NormalizedName = table.Column(type: "text", nullable: false), + ImageUrl = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Games", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Tags", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Tags", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + UserId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + PfpUrl = table.Column(type: "text", nullable: false), + IsOnline = table.Column(type: "boolean", nullable: false), + IsAdmin = table.Column(type: "boolean", nullable: false), + Bio = table.Column(type: "text", nullable: true), + DOB = table.Column(type: "date", nullable: true), + Username = table.Column(type: "text", nullable: false), + NormalizedUsername = table.Column(type: "text", nullable: false), + PasswordHash = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.UserId); + }); + + migrationBuilder.CreateTable( + name: "GameRelations", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + GameId = table.Column(type: "integer", nullable: false), + ApplicationUserUserId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_GameRelations", x => x.Id); + table.ForeignKey( + name: "FK_GameRelations_Games_GameId", + column: x => x.GameId, + principalTable: "Games", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GameRelations_Users_ApplicationUserUserId", + column: x => x.ApplicationUserUserId, + principalTable: "Users", + principalColumn: "UserId"); + }); + + migrationBuilder.CreateTable( + name: "UserRelations", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + User1Id = table.Column(type: "integer", nullable: false), + User2Id = table.Column(type: "integer", nullable: false), + Status = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserRelations", x => x.Id); + table.ForeignKey( + name: "FK_UserRelations_Users_User1Id", + column: x => x.User1Id, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_UserRelations_Users_User2Id", + column: x => x.User2Id, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ChatMemberships", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "integer", nullable: false), + ChatId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChatMemberships", x => x.Id); + table.ForeignKey( + name: "FK_ChatMemberships_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Chats", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ChatName = table.Column(type: "text", nullable: true), + ChatType = table.Column(type: "integer", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + LastMessageId = table.Column(type: "integer", nullable: true), + LastMessageAt = table.Column(type: "timestamp with time zone", nullable: true), + CreatorId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Chats", x => x.Id); + table.ForeignKey( + name: "FK_Chats_Users_CreatorId", + column: x => x.CreatorId, + principalTable: "Users", + principalColumn: "UserId"); + }); + + migrationBuilder.CreateTable( + name: "Groups", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + NormalizedName = table.Column(type: "text", nullable: false), + ImageUrl = table.Column(type: "text", nullable: true), + Description = table.Column(type: "text", nullable: true), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + CreatorId = table.Column(type: "integer", nullable: true), + ChatId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Groups", x => x.Id); + table.ForeignKey( + name: "FK_Groups_Chats_ChatId", + column: x => x.ChatId, + principalTable: "Chats", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Groups_Users_CreatorId", + column: x => x.CreatorId, + principalTable: "Users", + principalColumn: "UserId"); + }); + + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + Content = table.Column(type: "text", nullable: false), + SenderId = table.Column(type: "integer", nullable: false), + ChatId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.Id); + table.ForeignKey( + name: "FK_Messages_Chats_ChatId", + column: x => x.ChatId, + principalTable: "Chats", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Messages_Users_SenderId", + column: x => x.SenderId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Posts", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Title = table.Column(type: "text", nullable: false), + GameId = table.Column(type: "integer", nullable: false), + Description = table.Column(type: "text", nullable: true), + StartTime = table.Column(type: "timestamp with time zone", nullable: true), + EndTime = table.Column(type: "timestamp with time zone", nullable: true), + MaxPlayers = table.Column(type: "integer", nullable: true), + ChatId = table.Column(type: "integer", nullable: false), + CreatorId = table.Column(type: "integer", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Posts", x => x.Id); + table.ForeignKey( + name: "FK_Posts_Chats_ChatId", + column: x => x.ChatId, + principalTable: "Chats", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Posts_Games_GameId", + column: x => x.GameId, + principalTable: "Games", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Posts_Users_CreatorId", + column: x => x.CreatorId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "GroupMemberships", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "integer", nullable: false), + GroupId = table.Column(type: "integer", nullable: false), + Role = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GroupMemberships", x => x.Id); + table.ForeignKey( + name: "FK_GroupMemberships_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GroupMemberships_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "TagRelations", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TagId = table.Column(type: "integer", nullable: false), + ApplicationUserUserId = table.Column(type: "integer", nullable: true), + GroupId = table.Column(type: "integer", nullable: true), + PostId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_TagRelations", x => x.Id); + table.ForeignKey( + name: "FK_TagRelations_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_TagRelations_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_TagRelations_Tags_TagId", + column: x => x.TagId, + principalTable: "Tags", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_TagRelations_Users_ApplicationUserUserId", + column: x => x.ApplicationUserUserId, + principalTable: "Users", + principalColumn: "UserId"); + }); + + migrationBuilder.CreateIndex( + name: "IX_ChatMemberships_ChatId", + table: "ChatMemberships", + column: "ChatId"); + + migrationBuilder.CreateIndex( + name: "IX_ChatMemberships_UserId", + table: "ChatMemberships", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Chats_CreatorId", + table: "Chats", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Chats_LastMessageId", + table: "Chats", + column: "LastMessageId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_GameRelations_ApplicationUserUserId", + table: "GameRelations", + column: "ApplicationUserUserId"); + + migrationBuilder.CreateIndex( + name: "IX_GameRelations_GameId", + table: "GameRelations", + column: "GameId"); + + migrationBuilder.CreateIndex( + name: "IX_Games_Name", + table: "Games", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_GroupMemberships_GroupId", + table: "GroupMemberships", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupMemberships_UserId", + table: "GroupMemberships", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Groups_ChatId", + table: "Groups", + column: "ChatId"); + + migrationBuilder.CreateIndex( + name: "IX_Groups_CreatorId", + table: "Groups", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Groups_Name", + table: "Groups", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Messages_ChatId", + table: "Messages", + column: "ChatId"); + + migrationBuilder.CreateIndex( + name: "IX_Messages_SenderId", + table: "Messages", + column: "SenderId"); + + migrationBuilder.CreateIndex( + name: "IX_Posts_ChatId", + table: "Posts", + column: "ChatId"); + + migrationBuilder.CreateIndex( + name: "IX_Posts_CreatorId", + table: "Posts", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Posts_GameId", + table: "Posts", + column: "GameId"); + + migrationBuilder.CreateIndex( + name: "IX_TagRelations_ApplicationUserUserId", + table: "TagRelations", + column: "ApplicationUserUserId"); + + migrationBuilder.CreateIndex( + name: "IX_TagRelations_GroupId", + table: "TagRelations", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_TagRelations_PostId", + table: "TagRelations", + column: "PostId"); + + migrationBuilder.CreateIndex( + name: "IX_TagRelations_TagId", + table: "TagRelations", + column: "TagId"); + + migrationBuilder.CreateIndex( + name: "IX_Tags_Name", + table: "Tags", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_UserRelations_User1Id", + table: "UserRelations", + column: "User1Id"); + + migrationBuilder.CreateIndex( + name: "IX_UserRelations_User2Id", + table: "UserRelations", + column: "User2Id"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Email", + table: "Users", + column: "Email", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Users_Username", + table: "Users", + column: "Username", + unique: true); + + migrationBuilder.AddForeignKey( + name: "FK_ChatMemberships_Chats_ChatId", + table: "ChatMemberships", + column: "ChatId", + principalTable: "Chats", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Chats_Messages_LastMessageId", + table: "Chats", + column: "LastMessageId", + principalTable: "Messages", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Messages_Chats_ChatId", + table: "Messages"); + + migrationBuilder.DropTable( + name: "ChatMemberships"); + + migrationBuilder.DropTable( + name: "GameRelations"); + + migrationBuilder.DropTable( + name: "GroupMemberships"); + + migrationBuilder.DropTable( + name: "TagRelations"); + + migrationBuilder.DropTable( + name: "UserRelations"); + + migrationBuilder.DropTable( + name: "Groups"); + + migrationBuilder.DropTable( + name: "Posts"); + + migrationBuilder.DropTable( + name: "Tags"); + + migrationBuilder.DropTable( + name: "Games"); + + migrationBuilder.DropTable( + name: "Chats"); + + migrationBuilder.DropTable( + name: "Messages"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/FU.API/FU.API/Migrations/20231203001316_NonNullablePostDescription.cs b/FU.API/FU.API/Migrations/20231203001316_NonNullablePostDescription.cs index 47762e41..f7801599 100644 --- a/FU.API/FU.API/Migrations/20231203001316_NonNullablePostDescription.cs +++ b/FU.API/FU.API/Migrations/20231203001316_NonNullablePostDescription.cs @@ -1,36 +1,36 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace FU.API.Migrations -{ - /// - public partial class NonNullablePostDescription : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "Description", - table: "Posts", - type: "text", - nullable: false, - defaultValue: "", - oldClrType: typeof(string), - oldType: "text", - oldNullable: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "Description", - table: "Posts", - type: "text", - nullable: true, - oldClrType: typeof(string), - oldType: "text"); - } - } -} +#nullable disable + +namespace FU.API.Migrations +{ + using Microsoft.EntityFrameworkCore.Migrations; + + /// + public partial class NonNullablePostDescription : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Description", + table: "Posts", + type: "text", + nullable: false, + defaultValue: string.Empty, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Description", + table: "Posts", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + } + } +} diff --git a/FU.API/FU.API/Migrations/20240123145358_NormalizedPostDescAndTitle.cs b/FU.API/FU.API/Migrations/20240123145358_NormalizedPostDescAndTitle.cs index 4ebe5ae7..1103cb67 100644 --- a/FU.API/FU.API/Migrations/20240123145358_NormalizedPostDescAndTitle.cs +++ b/FU.API/FU.API/Migrations/20240123145358_NormalizedPostDescAndTitle.cs @@ -1,40 +1,40 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace FU.API.Migrations -{ - /// - public partial class NormalizedPostDescAndTitle : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "NormalizedDescription", - table: "Posts", - type: "text", - nullable: false, - defaultValue: ""); - - migrationBuilder.AddColumn( - name: "NormalizedTitle", - table: "Posts", - type: "text", - nullable: false, - defaultValue: ""); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "NormalizedDescription", - table: "Posts"); - - migrationBuilder.DropColumn( - name: "NormalizedTitle", - table: "Posts"); - } - } -} +#nullable disable + +namespace FU.API.Migrations +{ + using Microsoft.EntityFrameworkCore.Migrations; + + /// + public partial class NormalizedPostDescAndTitle : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "NormalizedDescription", + table: "Posts", + type: "text", + nullable: false, + defaultValue: string.Empty); + + migrationBuilder.AddColumn( + name: "NormalizedTitle", + table: "Posts", + type: "text", + nullable: false, + defaultValue: string.Empty); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "NormalizedDescription", + table: "Posts"); + + migrationBuilder.DropColumn( + name: "NormalizedTitle", + table: "Posts"); + } + } +} diff --git a/FU.API/FU.API/Models/Post.cs b/FU.API/FU.API/Models/Post.cs index 0a1e0a5c..5ce72382 100644 --- a/FU.API/FU.API/Models/Post.cs +++ b/FU.API/FU.API/Models/Post.cs @@ -1,6 +1,6 @@ -using System.ComponentModel.DataAnnotations.Schema; +namespace FU.API.Models; -namespace FU.API.Models; +using System.ComponentModel.DataAnnotations.Schema; /// /// The post class. diff --git a/FU.API/FU.API/Program.cs b/FU.API/FU.API/Program.cs index 59ad05e4..6e15f94b 100644 --- a/FU.API/FU.API/Program.cs +++ b/FU.API/FU.API/Program.cs @@ -32,7 +32,7 @@ { options.RequireHttpsMetadata = false; options.SaveToken = true; - options.TokenValidationParameters = new () + options.TokenValidationParameters = new() { IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSecret)), ValidateLifetime = true, diff --git a/FU.API/FU.API/Services/AccountsService.cs b/FU.API/FU.API/Services/AccountsService.cs index 92afe85e..d452d872 100644 --- a/FU.API/FU.API/Services/AccountsService.cs +++ b/FU.API/FU.API/Services/AccountsService.cs @@ -68,7 +68,7 @@ public AccountsService(IConfiguration configuration, AppDbContext dbContext) var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration[ConfigKey.JwtSecret] ?? string.Empty)); var signingCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); - List claims = new () + List claims = new() { new (CustomClaimTypes.UserId, user.UserId.ToString()) }; diff --git a/FU.API/FU.API/Services/CommonService.cs b/FU.API/FU.API/Services/CommonService.cs index b882b815..ddd53526 100644 --- a/FU.API/FU.API/Services/CommonService.cs +++ b/FU.API/FU.API/Services/CommonService.cs @@ -1,51 +1,50 @@ -namespace FU.API.Services; - -using FU.API.Data; -using FU.API.Exceptions; -using FU.API.Helpers; -using FU.API.Interfaces; -using FU.API.Models; -using Microsoft.EntityFrameworkCore; -using System.Security.Claims; - -public class CommonService : ICommonService -{ - private readonly AppDbContext _dbContext; - - public CommonService(AppDbContext dbContext) - { - _dbContext = dbContext; - } - - public async Task GetCurrentUser(ClaimsPrincipal claims) - { - var stringId = claims.FindFirstValue(CustomClaimTypes.UserId); - - if (stringId is null || !int.TryParse(stringId, out int userId)) - { - return null; - } - - // Get the user from the database - return await _dbContext.Users.FindAsync(userId); - } - - public async Task GetUser(int userId) - { - return await _dbContext.Users.FindAsync(userId); - } - - public async Task HasJoinedPost(int userId, int postId) - { - var chat = await _dbContext.Posts - .Include(p => p.Chat) - .ThenInclude(c => c.Members) - .ThenInclude(cu => cu.User) - .Where(p => p.Id == postId) - .Select(p => p.Chat) - .FirstOrDefaultAsync(); - - var res = chat is not null && chat.Members.Any(m => m.UserId == userId); - return res; - } -} \ No newline at end of file +namespace FU.API.Services; + +using FU.API.Data; +using FU.API.Helpers; +using FU.API.Interfaces; +using FU.API.Models; +using Microsoft.EntityFrameworkCore; +using System.Security.Claims; + +public class CommonService : ICommonService +{ + private readonly AppDbContext _dbContext; + + public CommonService(AppDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task GetCurrentUser(ClaimsPrincipal claims) + { + var stringId = claims.FindFirstValue(CustomClaimTypes.UserId); + + if (stringId is null || !int.TryParse(stringId, out int userId)) + { + return null; + } + + // Get the user from the database + return await _dbContext.Users.FindAsync(userId); + } + + public async Task GetUser(int userId) + { + return await _dbContext.Users.FindAsync(userId); + } + + public async Task HasJoinedPost(int userId, int postId) + { + var chat = await _dbContext.Posts + .Include(p => p.Chat) + .ThenInclude(c => c.Members) + .ThenInclude(cu => cu.User) + .Where(p => p.Id == postId) + .Select(p => p.Chat) + .FirstOrDefaultAsync(); + + var res = chat is not null && chat.Members.Any(m => m.UserId == userId); + return res; + } +} diff --git a/FU.API/FU.API/Services/SearchService.cs b/FU.API/FU.API/Services/SearchService.cs index 8a989c85..e9f9b3ae 100644 --- a/FU.API/FU.API/Services/SearchService.cs +++ b/FU.API/FU.API/Services/SearchService.cs @@ -31,7 +31,7 @@ public async Task> SearchPosts(PostQuery query) // Filter by tags // A post must have every tag in the filter - foreach (var tagId in query.TagIds) + foreach (int tagId in query.TagIds) { dbQuery = dbQuery.Where(p => p.Tags.Any(tr => tr.TagId == tagId)); } @@ -70,15 +70,19 @@ public async Task> SearchPosts(PostQuery query) .ToListAsync(); } - private static Expression> ContainsKeywords(List keywords) + private static Expression> ContainsKeywords(List keywords) { - if (keywords.Count == 0) return PredicateBuilder.New(true); // nothing to do so return a true predicate + if (keywords.Count == 0) + { + return PredicateBuilder.New(true); // nothing to do so return a true predicate + } var predicate = PredicateBuilder.New(false); // create a predicate that's false by default foreach (string keyword in keywords) { predicate = predicate.Or(p => p.NormalizedDescription.Contains(keyword.ToUpper()) || p.NormalizedTitle.Contains(keyword.ToUpper())); } + return predicate; } diff --git a/FU.API/out.json b/FU.API/out.json new file mode 100644 index 00000000..dc3d1a2a --- /dev/null +++ b/FU.API/out.json @@ -0,0 +1,254 @@ +[ + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "e7df7996-0148-4d03-a920-e2aa53d87edf" + }, + "FileName": "Exceptions.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Helpers/Exceptions.cs", + "FileChanges": [ + { + "LineNumber": 1, + "CharNumber": 1, + "DiagnosticId": "WHITESPACE", + "FormatDescription": "Fix whitespace formatting." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "18091396-6b90-495f-81b8-9e02572ba073" + }, + "FileName": "Mapper.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Helpers/Mapper.cs", + "FileChanges": [ + { + "LineNumber": 1, + "CharNumber": 1, + "DiagnosticId": "WHITESPACE", + "FormatDescription": "Fix whitespace formatting." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "02d414a2-8e78-4417-84a6-a7e802e2fbde" + }, + "FileName": "ChatHub.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Hubs/ChatHub.cs", + "FileChanges": [ + { + "LineNumber": 1, + "CharNumber": 1, + "DiagnosticId": "WHITESPACE", + "FormatDescription": "Fix whitespace formatting." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "c93c3f52-1d1e-43ef-b28d-fec4553e24b0" + }, + "FileName": "PostQuery.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Models/PostQuery.cs", + "FileChanges": [ + { + "LineNumber": 1, + "CharNumber": 1, + "DiagnosticId": "WHITESPACE", + "FormatDescription": "Fix whitespace formatting." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "4df40c96-fad7-4b03-8d01-851e553d58bb" + }, + "FileName": "Program.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Program.cs", + "FileChanges": [ + { + "LineNumber": 1, + "CharNumber": 1, + "DiagnosticId": "WHITESPACE", + "FormatDescription": "Fix whitespace formatting." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "a09f1031-3eb9-4cd7-8a16-7308051b03a6" + }, + "FileName": "AccountsService.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Services/AccountsService.cs", + "FileChanges": [ + { + "LineNumber": 1, + "CharNumber": 1, + "DiagnosticId": "WHITESPACE", + "FormatDescription": "Fix whitespace formatting." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "e7df7996-0148-4d03-a920-e2aa53d87edf" + }, + "FileName": "Exceptions.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Helpers/Exceptions.cs", + "FileChanges": [ + { + "LineNumber": 16, + "CharNumber": 16, + "DiagnosticId": "SA1000", + "FormatDescription": "warning SA1000: The keyword \u0027new\u0027 should be followed by a space." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "18091396-6b90-495f-81b8-9e02572ba073" + }, + "FileName": "Mapper.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Helpers/Mapper.cs", + "FileChanges": [ + { + "LineNumber": 91, + "CharNumber": 22, + "DiagnosticId": "SA1000", + "FormatDescription": "warning SA1000: The keyword \u0027new\u0027 should be followed by a space." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "02d414a2-8e78-4417-84a6-a7e802e2fbde" + }, + "FileName": "ChatHub.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Hubs/ChatHub.cs", + "FileChanges": [ + { + "LineNumber": 18, + "CharNumber": 58, + "DiagnosticId": "SA1000", + "FormatDescription": "warning SA1000: The keyword \u0027new\u0027 should be followed by a space." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "c93c3f52-1d1e-43ef-b28d-fec4553e24b0" + }, + "FileName": "PostQuery.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Models/PostQuery.cs", + "FileChanges": [ + { + "LineNumber": 5, + "CharNumber": 46, + "DiagnosticId": "SA1000", + "FormatDescription": "warning SA1000: The keyword \u0027new\u0027 should be followed by a space." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "c93c3f52-1d1e-43ef-b28d-fec4553e24b0" + }, + "FileName": "PostQuery.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Models/PostQuery.cs", + "FileChanges": [ + { + "LineNumber": 6, + "CharNumber": 45, + "DiagnosticId": "SA1000", + "FormatDescription": "warning SA1000: The keyword \u0027new\u0027 should be followed by a space." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "c93c3f52-1d1e-43ef-b28d-fec4553e24b0" + }, + "FileName": "PostQuery.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Models/PostQuery.cs", + "FileChanges": [ + { + "LineNumber": 9, + "CharNumber": 50, + "DiagnosticId": "SA1000", + "FormatDescription": "warning SA1000: The keyword \u0027new\u0027 should be followed by a space." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "4df40c96-fad7-4b03-8d01-851e553d58bb" + }, + "FileName": "Program.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Program.cs", + "FileChanges": [ + { + "LineNumber": 35, + "CharNumber": 41, + "DiagnosticId": "SA1000", + "FormatDescription": "warning SA1000: The keyword \u0027new\u0027 should be followed by a space." + } + ] + }, + { + "DocumentId": { + "ProjectId": { + "Id": "015f8422-b1a5-4402-9135-1f3afea97228" + }, + "Id": "a09f1031-3eb9-4cd7-8a16-7308051b03a6" + }, + "FileName": "AccountsService.cs", + "FilePath": "/home/james/Documents/SRC/PalmettoProgrammers/FU.API/FU.API/Services/AccountsService.cs", + "FileChanges": [ + { + "LineNumber": 71, + "CharNumber": 30, + "DiagnosticId": "SA1000", + "FormatDescription": "warning SA1000: The keyword \u0027new\u0027 should be followed by a space." + } + ] + } +] \ No newline at end of file