Skip to content

Commit

Permalink
refactor/cct-28-Refactor code migration (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: PNB309 <nguyen.phucbinh445@gmail.com>
  • Loading branch information
thanhpt1110 and leesoonduck3009 authored Oct 19, 2024
1 parent 742b318 commit f4c21aa
Show file tree
Hide file tree
Showing 111 changed files with 2,072 additions and 754 deletions.
60 changes: 60 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# top-most EditorConfig file
root = true

# C# files
[*.cs]
indent_style = space
indent_size = 4
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

# Organize usings
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = true

# C# specific formatting rules
# Use 'var' instead of explicit type when the type is apparent
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = false:suggestion

# Use expression-bodied members when possible
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_constructors = true:suggestion
csharp_style_expression_bodied_operators = true:suggestion
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion

# Use pattern matching when possible
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion

# Prefer 'is not null' over '!= null'
csharp_style_prefer_is_not_expression = true:suggestion

# Prefer 'null' check over 'object' check
csharp_style_prefer_null_check_over_type_check = true:suggestion

# Use 'default' literal instead of 'default(T)'
csharp_style_prefer_simple_default_expression = true:suggestion

# Use 'nameof' instead of string literals for parameter names
csharp_style_prefer_nameof_expression = true:suggestion

# Use 'using' statement instead of 'using' declaration
csharp_prefer_simple_using_statement = true:suggestion

# Use 'readonly' modifier for fields that are only assigned in the constructor
dotnet_style_readonly_field = true:suggestion

# Use 'this.' prefix for instance members
dotnet_style_qualification_for_field = true:suggestion
dotnet_style_qualification_for_property = true:suggestion
dotnet_style_qualification_for_method = true:suggestion
dotnet_style_qualification_for_event = true:suggestion

# Use 'private' modifier for fields
dotnet_style_require_accessibility_modifiers = always:suggestion
2 changes: 2 additions & 0 deletions src/ChitChat.Application/ChitChat.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="System.Linq.Expressions" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -20,6 +21,7 @@

<ItemGroup>
<Folder Include="Services\Caching\CacheKey\" />
<Folder Include="Validators\Conversation\" />
</ItemGroup>

</Project>
11 changes: 6 additions & 5 deletions src/ChitChat.Application/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using ChitChat.Application.Validators;
using FluentValidation;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace ChitChat.Application
{
Expand All @@ -31,12 +29,15 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection

// Add Services
services.AddServices();


return services;
}
public static IServiceCollection AddServices(this IServiceCollection services) {
public static IServiceCollection AddServices(this IServiceCollection services)
{
services.AddScoped<IUserService, UserService>();
services.AddScoped<IConversationService, ConversationService>();
services.AddScoped<IMessageService, MessageService>();
return services;
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/ChitChat.Application/Exceptions/ApplicationException.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using ChitChat.Application.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ChitChat.Application.Models;

namespace ChitChat.Application.Exceptions
{
Expand Down
2 changes: 1 addition & 1 deletion src/ChitChat.Application/Exceptions/NotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public NotFoundException(string code, Type type) : base(ValidationTexts.NotFound
Code = ApiResultErrorCodes.NotFound;
}

public NotFoundException(string message): base(message)
public NotFoundException(string message) : base(message)
{
Code = ApiResultErrorCodes.NotFound;
}
Expand Down
4 changes: 1 addition & 3 deletions src/ChitChat.Application/GlobalUsing.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
global using System;
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text;
global using System.Threading.Tasks;
global using Microsoft.EntityFrameworkCore;
9 changes: 1 addition & 8 deletions src/ChitChat.Application/Helpers/IClaimService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Helpers
namespace ChitChat.Application.Helpers
{
public interface IClaimService
{
Expand Down
5 changes: 0 additions & 5 deletions src/ChitChat.Application/Helpers/ITokenService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using ChitChat.Domain.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Helpers
{
Expand Down
5 changes: 0 additions & 5 deletions src/ChitChat.Application/Localization/ValidationText.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using ChitChat.Domain.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Localization
{
Expand Down
6 changes: 0 additions & 6 deletions src/ChitChat.Application/Mapping/IMappingProfileMarker.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Mapping
{
public interface IMappingProfileMarker
Expand Down
14 changes: 14 additions & 0 deletions src/ChitChat.Application/Mapping/MessageProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using AutoMapper;
using ChitChat.Application.Models.Dtos.Message;

namespace ChitChat.Application.Mapping
{
public class MessageProfile : Profile
{
public MessageProfile()
{
CreateMap<RequestSendMessageDto, Message>();
CreateMap<Message, MessageDto>();
}
}
}
13 changes: 4 additions & 9 deletions src/ChitChat.Application/Mapping/UserProfile.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
using AutoMapper;
using AutoMapper;
using ChitChat.Application.Models.Dtos.User;
using ChitChat.Domain.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Mapping
{
public class UserProfile: Profile
public class UserProfile : Profile
{
public UserProfile() {
public UserProfile()
{
CreateMap<UserApplication, UserDto>();
CreateMap<RegisterationRequestDto, UserApplication>();
CreateMap<LoginRequestDto, UserApplication>();

}
}
}
6 changes: 0 additions & 6 deletions src/ChitChat.Application/Models/ApiResult.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Models
{
public class ApiResult<T>
Expand Down
6 changes: 0 additions & 6 deletions src/ChitChat.Application/Models/Dtos/BaseResponseDto.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Models.Dtos
{
public class BaseResponseDto
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using ChitChat.Application.Models.Dtos.Message;
using ChitChat.Application.Models.Dtos.User;

namespace ChitChat.Application.Models.Dtos.Conversation
{
public class ConversationDto
{
public Guid Id { get; set; }
public UserDto UserReceiver { get; set; }
public MessageDto? LastMessage { get; set; }
public bool IsSeen { get; set; } = false;
}
}
13 changes: 13 additions & 0 deletions src/ChitChat.Application/Models/Dtos/Message/MessageDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace ChitChat.Application.Models.Dtos.Message
{
public class MessageDto
{
Guid Id { get; set; }
public string MessageText { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime UpdateOn { get; set; }
public string SenderId { get; set; }
public Guid ConversationId { get; set; }
public string Status { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ChitChat.Application.Models.Dtos.Message
{
public class RequestSearchMessageDto
{
public string Text { get; set; }
public Guid ConversationId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ChitChat.Application.Models.Dtos.Message
{
public class RequestSendMessageDto
{
public Guid ConversationId { get; set; }
public string MessageText { get; set; }
}
}
6 changes: 0 additions & 6 deletions src/ChitChat.Application/Models/Dtos/User/LoginRequestDto.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Models.Dtos.User
{
public class LoginRequestDto
Expand Down
6 changes: 0 additions & 6 deletions src/ChitChat.Application/Models/Dtos/User/LoginResponseDto.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Models.Dtos.User
{
public class LoginResponseDto
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Models.Dtos.User
namespace ChitChat.Application.Models.Dtos.User
{
public class RegisterationRequestDto
{
Expand Down
10 changes: 2 additions & 8 deletions src/ChitChat.Application/Models/Dtos/User/UserDto.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Models.Dtos.User
namespace ChitChat.Application.Models.Dtos.User
{
public class UserDto
{
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }

public string AvatarUrl { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Services.Caching
{
public class CacheEntryOptions
Expand All @@ -17,5 +11,4 @@ public class CacheEntryOptions
SlidingExpiration = TimeSpan.FromHours(1)
};
}

}
6 changes: 0 additions & 6 deletions src/ChitChat.Application/Services/Caching/ICachingService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChitChat.Application.Services.Caching
{
public interface ICachingService
Expand Down
Loading

0 comments on commit f4c21aa

Please sign in to comment.