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

Backend.tofik abdu.assessment #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 18 additions & 5 deletions backend/BackendAssessment/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1"/>
<PackageReference Include="File.TypeChecker" Version="4.0.0"/>
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0"/>
<PackageReference Include="MediatR" Version="12.0.1"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.5"/>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="File.TypeChecker" Version="4.0.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="MediatR" Version="12.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.5" />
</ItemGroup>

<ItemGroup>
<Folder Include="Contracts\repository\" />
<Folder Include="DTO\Identity\Validation\" />
<Folder Include="Features\BookingProduct\Handler\Queries\" />
<Folder Include="Features\BookingProduct\Request\Queries\" />
<Folder Include="Features\Identity\Handlers\Queries\" />
<Folder Include="Features\Identity\Requests\Queries\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Application
{
public static class ApplicationServiceRegistration
{
public static IServiceCollection ConfigureApplicationServices(this IServiceCollection services)
{
services.AddAutoMapper(Assembly.GetExecutingAssembly());
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(Assembly.GetExecutingAssembly()));

return services;
}
}
}
17 changes: 17 additions & 0 deletions backend/BackendAssessment/Application/Common/BaseResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Common
{
public class BaseResponse<T>
{
public bool Success { get; set; }

public string Message { get; set; }

public T Value { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Domain.Entites;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Contracts
{
public interface IBookingProductRepository : IGenericRepository<BookProduct>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Domain.Entites;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Contracts
{
public interface ICategoryRepository : IGenericRepository<Category>
{
public Task<bool> CategoryExist(string category);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Contracts
{
public interface IGenericRepository<T>
{
public Task<T> Add(T entity);
public Task<bool> Delete(T entity);
public Task<T> Update(T entity);

public Task<T> GetbyId(int id);

public Task<List<T>> GetAll();

public Task<bool> Exists(int id);

public Task<int> Delete(int id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Domain.Entites;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Contracts
{
public interface IProductRepository : IGenericRepository<Product>
{
public Task<List<Product>> GetProductsByCategory(string category);
}
}
17 changes: 17 additions & 0 deletions backend/BackendAssessment/Application/Contracts/IUnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Contracts
{
public interface IUnitOfWork : IDisposable
{
public IProductRepository ProductRepository { get; }
public ICategoryRepository CategoryRepository { get; }

public IBookingProductRepository BookingProductRepository { get; }
public Task<int> Save();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Application.DTO.Identity.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Contracts.Identity
{
public interface IAuthService
{
Task<UserDataDTO> GetUserProfile(string userId);
Task<AuthResponseDTO> Login(AuthRequestDTO request);
Task<RegistrationResponseDTO> Register(RegistrationRequestsDTO request);

Task<bool> Exists(string UserName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Application.DTO.Identity.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Contracts.Identity
{
public interface IUserService
{
Task<UserDataDTO?> GetProfile(string Id);

Task<UserDataDTO?> UpdateProfile(string Id, UpdateUserProfileDTO userData);

Task<bool> ChangePassword(string Id, ChangePasswordDTO changePasswordDTO);



}
}
13 changes: 13 additions & 0 deletions backend/BackendAssessment/Application/CustomClaimTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application
{
public static class CustomClaimTypes
{
public const string Uid = "uid";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DTO.BookingProduct.DTO
{
public class BookProductDTO
{
public int Quantity { get; set; }

public int ProductId { get; set; }

public DateTime StartDate { get; set; }

public DateTime EndDate { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Application.Contracts;
using Application.DTO.BookingProduct.DTO;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DTO.BookingProduct.Validation
{
public class BookingValidation : AbstractValidator<BookProductDTO>
{
private readonly IUnitOfWork _unitOfWork;

public BookingValidation(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;



RuleFor(x => x.ProductId)
.NotEmpty().WithMessage("ProductId is required")
.GreaterThan(0).WithMessage("ProductId must be greater than 0")
.MustAsync(async (ProductId, cancellation) =>
{
return await _unitOfWork.ProductRepository.Exists(ProductId);
// chek if it exists
}).WithMessage("Product with this Id doesn't exist");


RuleFor(x => x.Quantity)
.NotEmpty().WithMessage("Quantity is required")
.GreaterThan(0).WithMessage("Quantity must be greater than 0");

RuleFor(x => x.StartDate).NotEmpty().WithMessage("StartDate is required");
RuleFor(x => x.EndDate).NotEmpty().WithMessage("EndDate is required");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DTO.Category.DTO
{
public class CategoryCreateDTO : ICategoryDTO
{
public string Name { get; set; }

public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DTO.Category.DTO
{
public class CategoryResponseDTO
{
public int Id { get; set; }

public string Name { get; set; }

public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DTO.Category.DTO
{
public class CategoryUpdateDTO : ICategoryDTO
{
public int Id { get; set; }

public string Name { get; set; }

public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DTO.Category.DTO
{
public interface ICategoryDTO
{
public string Name { get; set; }

public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Application.DTO.Category.DTO;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DTO.Category.Validations
{
public class BaseCategoryValidation : AbstractValidator<ICategoryDTO>
{
public BaseCategoryValidation()
{

RuleFor(x => x.Name)
.NotEmpty().WithMessage("Name is required")
.MaximumLength(50).WithMessage("Name must be less than 50 characters");

RuleFor(x => x.Description)
.NotEmpty().WithMessage("Description is required")
.MaximumLength(500).WithMessage("Description must be less than 500 characters");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Application.DTO.Category.DTO;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DTO.Category.Validations
{
public class CategoryCreateValidation :AbstractValidator<CategoryCreateDTO>
{
public CategoryCreateValidation()
{
Include(new BaseCategoryValidation());
}
}
}
Loading