Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohirjon-Odilov committed Mar 3, 2024
2 parents fafac9f + f474105 commit c3dfd64
Show file tree
Hide file tree
Showing 61 changed files with 1,381 additions and 90 deletions.
6 changes: 4 additions & 2 deletions Exam.StockManagement.API/Controllers/CategoryController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Exam.StockManagement.API.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize]
public class CategoryController : ControllerBase
{
[HttpGet]
[HttpPost]
public async Task<IActionResult> GetById(int id)
{
return Ok("Salom");
Expand Down
6 changes: 0 additions & 6 deletions Exam.StockManagement.API/Controllers/ICategoryService.cs

This file was deleted.

37 changes: 33 additions & 4 deletions Exam.StockManagement.API/Controllers/Identity/AuthController.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
using Exam.StockManagement.Application.Abstractions.IServices;
using Exam.StockManagement.Domain.Entities.DTOs;
using Exam.StockManagement.Domain.Exceptions;
using Microsoft.AspNetCore.Mvc;

namespace Exam.StockManagement.API.Controllers.Identity
{
[Route("api/[controller]")]
[Route("api/[controller]/[action]")]
[ApiController]
public class AuthController : ControllerBase
{
private readonly IEmailSenderService _emailSenderService;
private readonly IAuthService _authService;
private readonly IWebHostEnvironment _webHostEnvironment;

public AuthController(IAuthService authService)

public AuthController(IAuthService authService,
IEmailSenderService emailSenderService,
IWebHostEnvironment webHostEnvironment)
{
_emailSenderService = emailSenderService;
_authService = authService;
_webHostEnvironment = webHostEnvironment;
}

[HttpPost]
public async Task<IActionResult> SignUp(RequestSignUp model)
{
var result = await _authService.RegisterUser(model);
return Ok(result);
}

[HttpPost]
public async Task<ActionResult<ResponseLogin>> Login(RequestLogin model)
public async Task<IActionResult> Login(RequestLogin model)
{
var result = await _authService.GenerateToken(model);
var result = await _authService.UserExist(model);
if (result)
{
string path = Path.Combine(_webHostEnvironment.WebRootPath, "code.txt");

await _emailSenderService.SendEmailAsync(model.Email, path);
return Ok(result);
}
throw new NotFoundException();
}

[HttpPost]
public async Task<IActionResult> AcceptUser(CheckEmail model)
{
string path = Path.Combine(_webHostEnvironment.WebRootPath, "code.txt");
var result = await _authService.GenerateToken(model, path);
return Ok(result.Token);
}
}
Expand Down
11 changes: 9 additions & 2 deletions Exam.StockManagement.API/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Exam.StockManagement.API.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ProductController
[Authorize]
public class ProductController : ControllerBase
{
[HttpPost]
public async Task<IActionResult> GetById(int id)
{
return Ok("Salom");
}
}
}
11 changes: 9 additions & 2 deletions Exam.StockManagement.API/Controllers/StatsController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Exam.StockManagement.API.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class StatsController
[Authorize]
public class StatsController : ControllerBase
{
[HttpPost]
public async Task<IActionResult> GetById(int id)
{
return Ok("Salom");
}
}
}
12 changes: 1 addition & 11 deletions Exam.StockManagement.API/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Exam.StockManagement.Application.Abstractions.IServices;
using Exam.StockManagement.Domain.Entities.DTOs;
using Exam.StockManagement.Domain.Entities.Models;
using Exam.StockManagement.Domain.Entities.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -9,7 +7,6 @@ namespace Exam.StockManagement.API.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize]
public class UsersController : ControllerBase
{
private readonly IUserService _userService;
Expand All @@ -20,19 +17,12 @@ public UsersController(IUserService userService)
}

[HttpGet]
[Authorize]
public async Task<ActionResult<IEnumerable<UserViewModel>>> GetAllUsers()
{
var result = await _userService.GetAll();

return Ok(result);
}

[HttpPost]
public async Task<ActionResult<IEnumerable<User>>> CreateUser(UserDTO model)
{
var result = await _userService.Create(model);

return Ok(result);
}
}
}
4 changes: 4 additions & 0 deletions Exam.StockManagement.API/Exam.StockManagement.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
<ProjectReference Include="..\Exam.StockManagement.Infrastructure\Exam.StockManagement.Infrastructure.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions Exam.StockManagement.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@
"ValidIssuer": "127.0.0.1",
"Secret": "TohirjonOdilovImtihonUchunTayyorlaganSecretKey03.02.2024",
"ExpireDate": "1000"
},
"EmailSettings": {
"MailServer": "smtp.gmail.com",
"MailPort": 587,
"SenderName": "Najot Ta'lim",
"Sender": "[email protected]",
"Password": "wcyz cueo vuiv tcku"
}
}
1 change: 1 addition & 0 deletions Exam.StockManagement.API/wwwroot/code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9430
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq.Expressions;

using System.Linq.Expressions;

namespace Exam.StockManagement.Application.Abstractions
namespace Exam.StockManagement.Application.Abstractions.IRepository
{
public interface IBaseRepository<T> where T : class
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Exam.StockManagement.Domain.Entities.Models;

namespace Exam.StockManagement.Application.Abstractions.IRepository
{
public interface ICategoryRepository : IBaseRepository<Category>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Exam.StockManagement.Domain.Entities.Models;

namespace Exam.StockManagement.Application.Abstractions.IRepository
{
public interface IProductRepository : IBaseRepository<Product>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Exam.StockManagement.Domain.Entities.Models;

namespace Exam.StockManagement.Application.Abstractions.IRepository
{
public interface IStatsService : IBaseRepository<Stats>
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Exam.StockManagement.Domain.Entities.Models;

namespace Exam.StockManagement.Application.Abstractions
namespace Exam.StockManagement.Application.Abstractions.IRepository
{
public interface IUserRepository : IBaseRepository<User>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using Exam.StockManagement.Domain.Entities.DTOs;
using Exam.StockManagement.Domain.Entities.Models;

namespace Exam.StockManagement.Application.Abstractions.IServices
{
public interface IAuthService
{
public Task<ResponseLogin> GenerateToken(RequestLogin user);
public Task<ResponseLogin> GenerateToken(CheckEmail model, string path);
public Task<bool> UserExist(RequestLogin user);
public Task<string> CorrectEmail(RegisterLogin user);
public Task<User> RegisterUser(RequestSignUp signUp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exam.StockManagement.Application.Abstractions.IServices
{
public interface ICategoryService
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Exam.StockManagement.Application.Abstractions.IServices
{
public interface IEmailSenderService
{
public Task<string> SendEmailAsync(string email, string path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Exam.StockManagement.Domain.Entities.DTOs;
using Exam.StockManagement.Domain.Entities.Models;
using Exam.StockManagement.Domain.Entities.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Exam.StockManagement.Application.Abstractions.IServices
{
public interface IProductService
{
public Task<Product> Create(ProductDTO userDTO);
public Task<Product> GetByName(string name);
public Task<Product> GetById(int Id);
public Task<Product> GetByEmail(string email);
public Task<Product> GetByLogin(string email);
public Task<IEnumerable<ProductViewModel>> GetAll();
public Task<bool> Delete(Expression<Func<Product, bool>> expression);
public Task<Product> Update(int Id, ProductDTO userDTO);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exam.StockManagement.Application.Abstractions.IServices
{
public interface IStatsService
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Exam.StockManagement.Application.Abstractions.IServices
{
public interface IUserService
{
public Task<User> Create(UserDTO userDTO);
public Task<User> Create(RequestSignUp signUp);
public Task<User> GetByName(string name);
public Task<User> GetById(int Id);
public Task<User> GetByEmail(string email);
Expand Down
4 changes: 3 additions & 1 deletion Exam.StockManagement.Application/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Exam.StockManagement.Application.Abstractions.IServices;
using Exam.StockManagement.Application.Services;
using Exam.StockManagement.Application.Services.AuthServices;
using Exam.StockManagement.Application.Services.UserServices;
using Microsoft.Extensions.DependencyInjection;

namespace Exam.StockManagement.Application
Expand All @@ -11,6 +11,8 @@ public static IServiceCollection AddApplication(this IServiceCollection services
{
services.AddScoped<IUserService, UserService>();
services.AddScoped<IAuthService, AuthService>();
services.AddScoped<IEmailSenderService, EmailSenderService>();


return services;
}
Expand Down
Loading

0 comments on commit c3dfd64

Please sign in to comment.