Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search post description and title for any keyword #205

Merged
merged 7 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions FU.API/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}]
Expand Down Expand Up @@ -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
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
6 changes: 2 additions & 4 deletions FU.API/FU.API/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -24,7 +22,7 @@ public SearchController(ISearchService searchService)
public async Task<IActionResult> SearchPosts([FromQuery] PostSearchRequestDTO request)
{
var posts = await _searchService.SearchPosts(request.ToPostQuery());
var response = new List<PostResponseDTO>(posts.Count());
var response = new List<PostResponseDTO>(posts.Count);

// Go through each post and check if the user has joined the post
var user = await _searchService.GetCurrentUser(User);
Expand All @@ -44,4 +42,4 @@ public async Task<IActionResult> SearchPosts([FromQuery] PostSearchRequestDTO re

return Ok(response);
}
}
}
28 changes: 14 additions & 14 deletions FU.API/FU.API/DTOs/Group/GroupSimpleDTO.cs
Original file line number Diff line number Diff line change
@@ -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<string> Tags { get; set; } = new HashSet<string>();
}
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<string> Tags { get; set; } = new HashSet<string>();
}
42 changes: 21 additions & 21 deletions FU.API/FU.API/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,100 +20,100 @@ public AppDbContext(DbContextOptions<AppDbContext> options)
/// <summary>
/// Create new models.
/// </summary>
/// <param name="builder">The builder.</param>
protected override void OnModelCreating(ModelBuilder builder)
/// <param name="modelBuilder">The builder.</param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Give 1 foreign key to Chat for LastMessage
builder.Entity<Chat>()
modelBuilder.Entity<Chat>()
.HasOne(c => c.LastMessage)
.WithOne()
.HasForeignKey<Chat>(c => c.LastMessageId);

// Make sure the username is unique
builder.Entity<ApplicationUser>()
modelBuilder.Entity<ApplicationUser>()
.HasIndex(u => u.Username)
.IsUnique();

// Make sure the email is unique
builder.Entity<ApplicationUser>()
modelBuilder.Entity<ApplicationUser>()
.HasIndex(u => u.Email)
.IsUnique();

// Make sure the name of the tag is unique
builder.Entity<Tag>()
modelBuilder.Entity<Tag>()
.HasIndex(t => t.Name)
.IsUnique();

// Make sure the name of the group is unique
builder.Entity<Group>()
modelBuilder.Entity<Group>()
.HasIndex(g => g.Name)
.IsUnique();

// Make sure the name of the game is unique
builder.Entity<Game>()
modelBuilder.Entity<Game>()
.HasIndex(g => g.Name)
.IsUnique();

base.OnModelCreating(builder);
base.OnModelCreating(modelBuilder);
}

/// <summary>
/// Gets or sets the users.
/// </summary>
public DbSet<ApplicationUser> Users { get; set; }
public DbSet<ApplicationUser> Users { get; set; } = null!;

/// <summary>
/// Gets or sets UserRelations.
/// </summary>
public DbSet<UserRelation> UserRelations { get; set; }
public DbSet<UserRelation> UserRelations { get; set; } = null!;

/// <summary>
/// Gets or sets chats.
/// </summary>
public DbSet<Chat> Chats { get; set; }
public DbSet<Chat> Chats { get; set; } = null!;

/// <summary>
/// Gets or sets ChatMemberships.
/// </summary>
public DbSet<ChatMembership> ChatMemberships { get; set; }
public DbSet<ChatMembership> ChatMemberships { get; set; } = null!;

/// <summary>
/// Gets or sets Messages.
/// </summary>
public DbSet<Message> Messages { get; set; }
public DbSet<Message> Messages { get; set; } = null!;

/// <summary>
/// Gets or sets Games.
/// </summary>
public DbSet<Game> Games { get; set; }
public DbSet<Game> Games { get; set; } = null!;

/// <summary>
/// Gets or sets GameRelations.
/// </summary>
public DbSet<GameRelation> GameRelations { get; set; }
public DbSet<GameRelation> GameRelations { get; set; } = null!;

/// <summary>
/// Gets or sets Groups.
/// </summary>
public DbSet<Group> Groups { get; set; }
public DbSet<Group> Groups { get; set; } = null!;

/// <summary>
/// Gets or sets GroupMemberships.
/// </summary>
public DbSet<GroupMembership> GroupMemberships { get; set; }
public DbSet<GroupMembership> GroupMemberships { get; set; } = null!;

/// <summary>
/// Gets or sets Posts.
/// </summary>
public DbSet<Post> Posts { get; set; }
public DbSet<Post> Posts { get; set; } = null!;

/// <summary>
/// Gets or sets Tags.
/// </summary>
public DbSet<Tag> Tags { get; set; }
public DbSet<Tag> Tags { get; set; } = null!;

/// <summary>
/// Gets or sets TagRelations.
/// </summary>
public DbSet<TagRelation> TagRelations { get; set; }
public DbSet<TagRelation> TagRelations { get; set; } = null!;
}
1 change: 1 addition & 0 deletions FU.API/FU.API/FU.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.0" />
<PackageReference Include="LinqKit" Version="1.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.13" />
<PackageReference Include="DotNetEnv" Version="2.5.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.11" />
Expand Down
4 changes: 2 additions & 2 deletions FU.API/FU.API/Helpers/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class ExceptionWithResponse : Exception

public ProblemDetails GetProblemDetails()
{
return new ()
return new()
{
Title = Title,
Detail = Description,
Expand Down Expand Up @@ -116,4 +116,4 @@ public ConflictException(string description)
{
Description = description;
}
}
}
5 changes: 3 additions & 2 deletions FU.API/FU.API/Helpers/IsLoggedInAuthenticationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FU.API.Helpers;
namespace FU.API.Helpers;

using Microsoft.AspNetCore.Authorization;

/// <summary>
Expand Down Expand Up @@ -31,4 +32,4 @@ protected override Task HandleRequirementAsync(AuthorizationHandlerContext conte

return Task.CompletedTask;
}
}
}
2 changes: 2 additions & 0 deletions FU.API/FU.API/Helpers/IsLoggedInRequirement.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace FU.API.Helpers;

using Microsoft.AspNetCore.Authorization;

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions FU.API/FU.API/Helpers/Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public static PostQuery ToPostQuery(this PostSearchRequestDTO dto)
MinimumRequiredPlayers = dto.MinPlayers ?? 0,
Limit = dto.Limit ?? 20,
Offset = dto.Offset ?? 0,
SortBy = new ()
SortBy = new()
};

if (dto.Keywords is not null)
{
query.DescriptionContains = dto.Keywords.Split(" ").ToList();
query.Keywords = dto.Keywords.Split(" ").ToList();
}

if (dto.Games is not null)
Expand Down Expand Up @@ -196,4 +196,4 @@ public static GroupSimpleDTO ToSimpleDto(this Group group)

public static IEnumerable<GroupSimpleDTO> ToSimpleDtos(this IEnumerable<Group> groups) =>
groups.Select(group => group.ToSimpleDto());
}
}
3 changes: 1 addition & 2 deletions FU.API/FU.API/Hubs/ChatHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,7 +15,7 @@ public class ChatHub : Hub
/// <summary>
/// List of the connected users names.
/// </summary>
public static readonly List<string> ConnectedUsers = new ();
public static readonly List<string> ConnectedUsers = new();

/// <summary>
/// The app db context.
Expand Down
24 changes: 12 additions & 12 deletions FU.API/FU.API/Interfaces/ICommonService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace FU.API.Interfaces;

using FU.API.Models;
using System.Security.Claims;

public interface ICommonService
{
Task<ApplicationUser?> GetCurrentUser(ClaimsPrincipal claims);

Task<ApplicationUser?> GetUser(int userId);

Task<bool> HasJoinedPost(int userId, int postId);
namespace FU.API.Interfaces;
using FU.API.Models;
using System.Security.Claims;
public interface ICommonService
{
Task<ApplicationUser?> GetCurrentUser(ClaimsPrincipal claims);
Task<ApplicationUser?> GetUser(int userId);
Task<bool> HasJoinedPost(int userId, int postId);
}
28 changes: 14 additions & 14 deletions FU.API/FU.API/Interfaces/IPostService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace FU.API.Interfaces;

using FU.API.Models;

public interface IPostService : ICommonService
{
Task<Post> CreatePost(Post post);

Task<Post?> 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<Post> CreatePost(Post post);
Task<Post?> GetPost(int postId);
Task JoinPost(int postId, ApplicationUser user);
Task LeavePost(int postId, ApplicationUser user);
}
Loading
Loading