Skip to content

Commit

Permalink
Update UseCases folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderlan committed Aug 1, 2024
1 parent 028f686 commit 4b7dd3b
Show file tree
Hide file tree
Showing 42 changed files with 90 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/Company.Orion.Api/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using Microsoft.AspNetCore.Mvc.Razor;
using Company.Orion.Api.Configuration;
using Company.Orion.Application.Core;
using Company.Orion.Application.Core.Commands.UserCreate;
using Company.Orion.Crosscutting.Ioc.Dependencies;
using Company.Orion.Domain.Core.Authentication;
using Company.Orion.Application.Core.UseCases.User.Commands.Create;

namespace Company.Orion.Api;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Company.Orion.Application.Core.Commands.LoginWithCredentials;
using Company.Orion.Domain.Core.Extensions;
using Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithCredentials;

namespace Company.Orion.Api.Configuration;

Expand Down
4 changes: 2 additions & 2 deletions src/Company.Orion.Api/Controllers/V1/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Company.Orion.Application.Core.Commands.LoginWithCredentials;
using Company.Orion.Application.Core.Commands.LoginWithRefreshToken;
using Company.Orion.Domain.Core.Exceptions;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
using Company.Orion.Api.Configuration;
using Company.Orion.Api.Controllers.Base;
using Company.Orion.Api.Models;
using Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithCredentials;
using Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithRefreshToken;

namespace Company.Orion.Api.Controllers.V1;

Expand Down
10 changes: 5 additions & 5 deletions src/Company.Orion.Api/Controllers/V1/UsersController.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Asp.Versioning;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Company.Orion.Application.Core.Commands.UserChangePassword;
using Company.Orion.Application.Core.Commands.UserCreate;
using Company.Orion.Application.Core.Commands.UserDelete;
using Company.Orion.Application.Core.Commands.UserUpdate;
using Company.Orion.Application.Core.Queries.UserGetById;
using Company.Orion.Application.Core.Queries.UserGetPaginated;
using Company.Orion.Domain.Core.Exceptions;
using Company.Orion.Domain.Core.ValueObjects.Pagination;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;
using Company.Orion.Api.Attributes;
using Company.Orion.Api.Controllers.Base;
using static Company.Orion.Domain.Core.Authentication.AuthorizationConfiguration;
using Company.Orion.Application.Core.UseCases.User.Commands.Update;
using Company.Orion.Application.Core.UseCases.User.Commands.Create;
using Company.Orion.Application.Core.UseCases.User.Queries.GetPaginated;
using Company.Orion.Application.Core.UseCases.User.Commands.ChangePassword;
using Company.Orion.Application.Core.UseCases.User.Queries.GetById;

namespace Company.Orion.Api.Controllers.V1;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using MediatR;

namespace Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithCredentials;

public class LoginWithCredentialsRequest : IRequest<LoginWithCredentialsResponse>
{
public string Email { get; set; }
public string Password { get; set; }
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MediatR;
using Company.Orion.Domain.Core.Services.Interfaces;

namespace Company.Orion.Application.Core.Commands.LoginWithCredentials;
namespace Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithCredentials;

public class LoginWithCredentialsRequestHandler(IUserService userService) : IRequestHandler<LoginWithCredentialsRequest, LoginWithCredentialsResponse>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Company.Orion.Domain.Core.Entities.Enuns;

namespace Company.Orion.Application.Core.Commands.LoginWithCredentials;
namespace Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithCredentials;

public class LoginWithCredentialsResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using MediatR;

namespace Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithRefreshToken;

public class LoginWithRefreshTokenRequest : IRequest<LoginWithRefreshTokenResponse>
{
public string Token { get; set; }
public string RefreshToken { get; set; }
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MediatR;
using Company.Orion.Domain.Core.Services.Interfaces;

namespace Company.Orion.Application.Core.Commands.LoginWithRefreshToken;
namespace Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithRefreshToken;

public class LoginWithRefreshTokenRequestHandler(IUserService userService)
: IRequestHandler<LoginWithRefreshTokenRequest, LoginWithRefreshTokenResponse>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithCredentials;

namespace Company.Orion.Application.Core.UseCases.Auth.Commands.LoginWithRefreshToken;

public class LoginWithRefreshTokenResponse : LoginWithCredentialsResponse;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MediatR;

namespace Company.Orion.Application.Core.Commands.UserChangePassword
namespace Company.Orion.Application.Core.UseCases.User.Commands.ChangePassword
{
public class UserChangePasswordRequest : IRequest<Unit>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Company.Orion.Domain.Core.Authentication;
using Company.Orion.Domain.Core.Services.Interfaces;

namespace Company.Orion.Application.Core.Commands.UserChangePassword
namespace Company.Orion.Application.Core.UseCases.User.Commands.ChangePassword
{
public class UserUpdatePasswordRequestHandler(
IUserService userService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Company.Orion.Crosscutting.Resources;
using Company.Orion.Crosscutting.Resources.Messages;

namespace Company.Orion.Application.Core.Commands.UserChangePassword;
namespace Company.Orion.Application.Core.UseCases.User.Commands.ChangePassword;

public class UserChangePasswordRequestValidator : AbstractValidator<UserChangePasswordRequest>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Company.Orion.Domain.Core.Entities;
using Company.Orion.Domain.Core.Entities.Enuns;

namespace Company.Orion.Application.Core.Commands.UserCreate;
namespace Company.Orion.Application.Core.UseCases.User.Commands.Create;

public class UserCreateRequest : IRequest <UserCreateResponse>
public class UserCreateRequest : IRequest<UserCreateResponse>
{
public string Name { get; set; }
public string Password { get; set; }
Expand All @@ -15,7 +15,7 @@ public static implicit operator User(UserCreateRequest request)
{
if (request is null)
return default;

return new User
{
Name = request.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using MediatR;
using Company.Orion.Domain.Core.Services.Interfaces;

namespace Company.Orion.Application.Core.Commands.UserCreate;
namespace Company.Orion.Application.Core.UseCases.User.Commands.Create;

public class UserCreateRequestHandler(IUserService userService, IMediator mediator)
: IRequestHandler<UserCreateRequest, UserCreateResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Company.Orion.Crosscutting.Resources;
using Company.Orion.Crosscutting.Resources.Messages;

namespace Company.Orion.Application.Core.Commands.UserCreate;
namespace Company.Orion.Application.Core.UseCases.User.Commands.Create;

public class UserCreateRequestValidator : AbstractValidator<UserCreateRequest>
{
Expand All @@ -15,10 +15,10 @@ public UserCreateRequestValidator(IStringLocalizer<OrionResources> stringLocaliz

RuleFor(c => c.Name)
.NotEmpty().WithMessage(stringLocalizer[MessagesKeys.UserMessages.EmptyName]);

RuleFor(c => c.Email)
.NotEmpty().WithMessage(stringLocalizer[MessagesKeys.UserMessages.EmptyEmail]);

RuleFor(c => c.Password)
.NotEmpty().WithMessage(stringLocalizer[MessagesKeys.UserMessages.EmptyPassword]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Company.Orion.Domain.Core.Entities;
using Company.Orion.Domain.Core.Entities.Enuns;

namespace Company.Orion.Application.Core.Commands.UserCreate;
namespace Company.Orion.Application.Core.UseCases.User.Commands.Create;

public class UserCreateResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MediatR;

namespace Company.Orion.Application.Core.Commands.UserDelete;
namespace Company.Orion.Application.Core.UseCases.User.Commands.Delete;

public record UserDeleteRequest(string PublicId) : IRequest;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MediatR;
using Company.Orion.Domain.Core.Services.Interfaces;

namespace Company.Orion.Application.Core.Commands.UserDelete;
namespace Company.Orion.Application.Core.UseCases.User.Commands.Delete;

public class UserDeleteRequestHandler(IUserService userService) : IRequestHandler<UserDeleteRequest>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
using Company.Orion.Domain.Core.Entities;
using Company.Orion.Domain.Core.Entities.Enuns;

namespace Company.Orion.Application.Core.Commands.UserUpdate;
namespace Company.Orion.Application.Core.UseCases.User.Commands.Update;

public class UserUpdateRequest : IRequest
{
public string PublicId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public UserProfile Profile { get; set; }

public static implicit operator User(UserUpdateRequest request)
{
if (request is null)
return default;

return new User
{
PublicId = request.PublicId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MediatR;
using Company.Orion.Domain.Core.Services.Interfaces;

namespace Company.Orion.Application.Core.Commands.UserUpdate;
namespace Company.Orion.Application.Core.UseCases.User.Commands.Update;

public class UserUpdateRequestHandler(IUserService userService) : IRequestHandler<UserUpdateRequest>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Company.Orion.Crosscutting.Resources;
using Company.Orion.Crosscutting.Resources.Messages;

namespace Company.Orion.Application.Core.Commands.UserUpdate;
namespace Company.Orion.Application.Core.UseCases.User.Commands.Update;

public class UserUpdateRequestValidator : AbstractValidator<UserUpdateRequest>
{
Expand All @@ -15,10 +15,10 @@ public UserUpdateRequestValidator(IStringLocalizer<OrionResources> stringLocaliz

RuleFor(c => c.Name)
.NotEmpty().WithMessage(stringLocalizer[MessagesKeys.UserMessages.EmptyName]);

RuleFor(c => c.Email)
.NotEmpty().WithMessage(stringLocalizer[MessagesKeys.UserMessages.EmptyEmail]);

RuleFor(c => c.PublicId)
.NotEmpty().WithMessage(stringLocalizer[MessagesKeys.UserMessages.EmptyId]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MediatR;
using Company.Orion.Domain.Core.Entities;

namespace Company.Orion.Application.Core.Notifications.UserCreated
namespace Company.Orion.Application.Core.UseCases.User.Notifications.UserCreated
{
public class UserCreatedNotification(User user) : INotification
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Newtonsoft.Json;
using Company.Orion.Domain.Core.Authentication;

namespace Company.Orion.Application.Core.Notifications.UserCreated
namespace Company.Orion.Application.Core.UseCases.User.Notifications.UserCreated
{
public class UserCreatedNotificationHandler(
ILogger<UserCreatedNotificationHandler> logger,
Expand All @@ -12,7 +12,7 @@ public class UserCreatedNotificationHandler(
{
public async Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
{
logger.LogInformation("A notification {notificationType} has been received. Notification details: {notification}. Action performed by: {currentUserName}",
logger.LogInformation("A notification {notificationType} has been received. Notification details: {notification}. Action performed by: {currentUserName}",
nameof(UserCreatedNotification),
JsonConvert.SerializeObject(notification, Formatting.Indented),
currentUser.ToString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MediatR;

namespace Company.Orion.Application.Core.Notifications.UserPasswordChanged
namespace Company.Orion.Application.Core.UseCases.User.Notifications.UserPasswordChanged
{
public class UserPasswordChangedNotification : INotification;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Newtonsoft.Json;
using Company.Orion.Domain.Core.Authentication;

namespace Company.Orion.Application.Core.Notifications.UserPasswordChanged
namespace Company.Orion.Application.Core.UseCases.User.Notifications.UserPasswordChanged
{
public class UserPasswordChangedNotificationHandler(
ILogger<UserPasswordChangedNotificationHandler> logger,
Expand All @@ -12,7 +12,7 @@ public class UserPasswordChangedNotificationHandler(
{
public async Task Handle(UserPasswordChangedNotification notification, CancellationToken cancellationToken)
{
logger.LogInformation("A notification {notificationType} has been received. Notification details: {notification}. Action performed by: {currentUserName}",
logger.LogInformation("A notification {notificationType} has been received. Notification details: {notification}. Action performed by: {currentUserName}",
nameof(UserPasswordChangedNotification),
JsonConvert.SerializeObject(notification, Formatting.Indented),
currentUser.ToString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MediatR;

namespace Company.Orion.Application.Core.Queries.UserGetById;
namespace Company.Orion.Application.Core.UseCases.User.Queries.GetById;

public record UserGetByIdRequest(string PublicId) : IRequest<UserGetByIdResponse>;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using MediatR;
using Company.Orion.Domain.Core.Services.Interfaces;

namespace Company.Orion.Application.Core.Queries.UserGetById;
namespace Company.Orion.Application.Core.UseCases.User.Queries.GetById;

public class UserGetByIdHandler(IUserService userService) : IRequestHandler<UserGetByIdRequest, UserGetByIdResponse>
{
public async Task<UserGetByIdResponse> Handle(UserGetByIdRequest request, CancellationToken cancellationToken)
{
return (UserGetByIdResponse) await userService.FindByIdAsync(request.PublicId);
return (UserGetByIdResponse)await userService.FindByIdAsync(request.PublicId);
}
}
Loading

0 comments on commit 4b7dd3b

Please sign in to comment.