Skip to content

Commit

Permalink
complete category
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohirjon-Odilov committed Mar 3, 2024
1 parent e5bb1b7 commit f51bf53
Show file tree
Hide file tree
Showing 19 changed files with 554 additions and 73 deletions.
27 changes: 21 additions & 6 deletions Exam.StockManagement.API/Controllers/CategoryController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Exam.StockManagement.Application.Abstractions.IServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Exam.StockManagement.API.Controllers
Expand All @@ -8,28 +9,42 @@ namespace Exam.StockManagement.API.Controllers
[Authorize]
public class CategoryController : ControllerBase
{
private readonly ICategoryService _categoryService;

public CategoryController(ICategoryService categoryService)
{
_categoryService = categoryService;
}

[HttpPost]
public async Task<IActionResult> Create(string name)
{
return Ok();
var result = await _categoryService.Create(name);

return Ok(result);
}

[HttpGet]
public async Task<IActionResult> GetAll()
{
return Ok();
var result = await _categoryService.GetAll();

return Ok(result);
}

[HttpPut]
public async Task<IActionResult> Update(int id)
public async Task<IActionResult> Update(int id, string name)
{
return Ok();
var result = await _categoryService.Update(id, name);

return Ok(result);
}

[HttpDelete]
public async Task<IActionResult> Delete(int id)
{
return Ok();
var restult = await _categoryService.Delete(id);
return Ok("Deleted");
}
}
}
2 changes: 1 addition & 1 deletion Exam.StockManagement.API/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ProductController : ControllerBase
[HttpPost]
public async Task<IActionResult> Create(int id)
{
return Ok("Salom");
return Ok();
}

[HttpGet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Exam.StockManagement.Application.Abstractions.IRepository
{
public interface IStatsService : IBaseRepository<Stats>
public interface IStatsRepository : IBaseRepository<Stats>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Exam.StockManagement.Application.Abstractions.IServices
{
public interface ICategoryService
{
public Task<string> Create();
public Task<Category> Create(string name);
public Task<List<Category>> GetAll();
public Task<string> Update();
public Task<string> Delete();
public Task<Category> Update(int id, string name);
public Task<Category> Delete(int id);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Exam.StockManagement.Domain.Entities.DTOs;
using Exam.StockManagement.Domain.Entities.Models;

namespace Exam.StockManagement.Application.Abstractions.IServices
{
public interface IProductService
{
public Task<string> Create();
public Task<List<Category>> GetAll();
public Task<string> Update();
public Task<string> Delete();
public Task<Product> Create(ProductDTO product);
public Task<List<Product>> GetAll();
public Task<string> Update(Product product);
public Task<string> Delete(int Id);
}
}
4 changes: 3 additions & 1 deletion Exam.StockManagement.Application/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public static IServiceCollection AddApplication(this IServiceCollection services
services.AddScoped<IUserService, UserService>();
services.AddScoped<IAuthService, AuthService>();
services.AddScoped<IEmailSenderService, EmailSenderService>();

services.AddScoped<ICategoryService, CategoryService>();
services.AddScoped<IProductService, ProductService>();
services.AddScoped<IStatsService, StatsService>();

return services;
}
Expand Down
51 changes: 36 additions & 15 deletions Exam.StockManagement.Application/Services/CategoryService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Exam.StockManagement.Application.Abstractions.IRepository;
using Exam.StockManagement.Application.Abstractions.IServices;
using Exam.StockManagement.Domain.Entities.Models;
using System.Linq.Expressions;

namespace Exam.StockManagement.Application.Services
{
public class CategoryService : ICategoryRepository

public class CategoryService : ICategoryService
{
private readonly ICategoryRepository _categoryRepository;

Expand All @@ -14,29 +13,51 @@ public CategoryService(ICategoryRepository categoryRepository)
_categoryRepository = categoryRepository;
}

public Task<Category> Create(Category entity)
public async Task<Category> Create(string name)
{
throw new NotImplementedException();
}
if (name == null)
{
throw new ArgumentNullException("name");
}
var result = await _categoryRepository.Create(new Category { CategoryName = name });

public Task<bool> Delete(Expression<Func<Category, bool>> expression)
{
throw new NotImplementedException();
return result;
}

public Task<IEnumerable<Category>> GetAll()
public async Task<Category> Delete(int id)
{
throw new NotImplementedException();
if (id <= 0)
{
throw new ArgumentNullException("id");
}

var result = await _categoryRepository.Delete(x => x.CategoryId == id);

if (result)
{
return new Category { CategoryName = "Deleted" };
} else
{
return new Category { CategoryName = "Not Delete" };
}


}

public Task<Category> GetByAny(Expression<Func<Category, bool>> expression)
public async Task<List<Category>> GetAll()
{
throw new NotImplementedException();
var result = await _categoryRepository.GetAll();

return result.ToList();
}

public Task<Category> Update(Category entity)
public async Task<Category> Update(int id, string name)
{
throw new NotImplementedException();
var entity = new Category { CategoryId = id, CategoryName = name };

var result = await _categoryRepository.Update(entity);

return result;
}
}
}
61 changes: 49 additions & 12 deletions Exam.StockManagement.Application/Services/ProductService.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,71 @@
using Exam.StockManagement.Application.Abstractions.IRepository;
using Exam.StockManagement.Application.Abstractions.IServices;
using Exam.StockManagement.Domain.Entities.DTOs;
using Exam.StockManagement.Domain.Entities.Models;
using System.Linq.Expressions;

namespace Exam.StockManagement.Application.Services
{
public class ProductService : IProductRepository
public class ProductService : IProductService
{
public Task<Product> Create(Product entity)
private readonly IProductRepository productRepository;

public ProductService(IProductRepository productRepository)
{
throw new NotImplementedException();
this.productRepository = productRepository;
}

public Task<bool> Delete(Expression<Func<Product, bool>> expression)
public Task<Product> Create(ProductDTO product)
{
throw new NotImplementedException();
ArgumentNullException.ThrowIfNull(product);

var entity = new Product()
{
CategoryId = product.CategoryId,
ProductDescription = product.ProductDescription,
ProductName = product.ProductName,
ProductPrice = product.ProductPrice,
ProductPicture = product.ProductPicture
};

var result = productRepository.Create(entity);

return result;
}

public Task<IEnumerable<Product>> GetAll()
public async Task<List<Product>> GetAll()
{
throw new NotImplementedException();
ArgumentNullException.ThrowIfNull(productRepository);
var result = await productRepository.GetAll();
return result.ToList();
}

public Task<Product> GetByAny(Expression<Func<Product, bool>> expression)
public async Task<string> Update(Product product)
{
throw new NotImplementedException();
ArgumentNullException.ThrowIfNull(productRepository);

var entity = new Product()
{
CategoryId = product.CategoryId,
ProductDescription = product.ProductDescription,
ProductName = product.ProductName,
ProductPrice = product.ProductPrice,
ProductPicture = product.ProductPicture
};

await productRepository.Update(entity);

return "Ma'lumot yangilandi";
}

public Task<Product> Update(Product entity)
public async Task<string> Delete(int Id)
{
throw new NotImplementedException();
ArgumentNullException.ThrowIfNull(Id);

var result = await productRepository.Delete(x => x.Id == Id);

ArgumentNullException.ThrowIfNull(result);

return "Qo'shildi";
}
}
}
16 changes: 5 additions & 11 deletions Exam.StockManagement.Application/Services/StatsService.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
using Exam.StockManagement.Application.Abstractions.IRepository;
using Exam.StockManagement.Application.Abstractions.IServices;
using Exam.StockManagement.Domain.Entities.Models;
using System.Linq.Expressions;

namespace Exam.StockManagement.Application.Services
{
public class StatsService : IStatsService
{
public Task<Stats> Create(Stats entity)
public Task<string> Create()
{
throw new NotImplementedException();
}

public Task<bool> Delete(Expression<Func<Stats, bool>> expression)
public Task<string> Delete()
{
throw new NotImplementedException();
}

public Task<IEnumerable<Stats>> GetAll()
public Task<List<Category>> GetAll()
{
throw new NotImplementedException();
}

public Task<Stats> GetByAny(Expression<Func<Stats, bool>> expression)
{
throw new NotImplementedException();
}

public Task<Stats> Update(Stats entity)
public Task<string> Update()
{
throw new NotImplementedException();
}
Expand Down
1 change: 0 additions & 1 deletion Exam.StockManagement.Domain/Entities/Common/Auditable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ namespace Exam.StockManagement.Domain.Entities.Common
public abstract class Auditable : BaseEntity
{
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
}
}
11 changes: 5 additions & 6 deletions Exam.StockManagement.Domain/Entities/DTOs/ProductDTO.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exam.StockManagement.Domain.Entities.DTOs
{
public class ProductDTO
{
public string ProductName { get; set; }
public int CategoryId { get; set; }
public int ProductPrice { get; set; }
public string ProductDescription { get; set; }
public string ProductPicture { get; set; }
}
}
2 changes: 1 addition & 1 deletion Exam.StockManagement.Domain/Entities/Models/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ namespace Exam.StockManagement.Domain.Entities.Models
public class Category
{
public int CategoryId { get; set; }
public int CategoryName { get; set; }
public string CategoryName { get; set; }

Check warning on line 6 in Exam.StockManagement.Domain/Entities/Models/Category.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'CategoryName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Exam.StockManagement.Infrastructure.BaseRepositories
{
public class StatsRepository : BaseRepository<Stats>, IStatsService
public class StatsRepository : BaseRepository<Stats>, IStatsRepository
{
public StatsRepository(StockManagementDbContext context) : base(context)
{
Expand Down
7 changes: 5 additions & 2 deletions Exam.StockManagement.Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Exam.StockManagement.Application.Abstractions.IRepository;
using Exam.StockManagement.Application.Abstractions.IServices;
using Exam.StockManagement.Application.Services;
using Exam.StockManagement.Infrastructure.BaseRepositories;
using Exam.StockManagement.Infrastructure.Persistance;
using Microsoft.EntityFrameworkCore;
Expand All @@ -20,7 +18,12 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi
});

services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IProductRepository, ProductRepository>();
services.AddScoped<IStatsRepository, StatsRepository>();
services.AddScoped<ICategoryRepository, CategoryRepository>();


//services.AddScoped<IUserRepository, UserRepository>();
//services.AddScoped<IBaseRepository<User>, BaseRepository<User>>();
return services;
}
Expand Down
Loading

0 comments on commit f51bf53

Please sign in to comment.