Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

New Controller #37

Merged
merged 9 commits into from
Oct 5, 2023
Merged
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
Binary file modified Script.sql
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ public class Staff : BaseEntity

public ApplicationUser ApplicationUser { get; set; }

//public List<Staff_Trip> Staff_Trips { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Contract.Repository.Interface;

public interface ICustomerRepository : IRepository<Customer>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Contract.Repository.Interface;

public interface IOrderHistoryRepository : IRepository<OrderHistory>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Contract.Repository.Interface;

public interface IOrderRepository : IRepository<Order>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Contract.Repository.Interface;

public interface IPaymentRepository : IRepository<Payment>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Contract.Repository.Interface;

public interface IStaffRepository : IRepository<Staff>
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using SWD_Laundry_Backend.Core.Models;

namespace SWD_Laundry_Backend.Contract.Service.Interface;
public interface IBuidingService : ICreateAble<BuildingModel, string>, IGetAble<Building, string>, IUpdateAble<BuildingModel, string>, IDeleteAble<string>
public interface IBuidingService :
ICreateAble<BuildingModel, string>,
IGetAble<Building, string>,
IUpdateAble<BuildingModel, string>,
IDeleteAble<string>
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Service.Base_Service_Interface;
using SWD_Laundry_Backend.Core.Models;

namespace SWD_Laundry_Backend.Contract.Service.Interface;

public interface ICustomerService :
ICreateAble<CustomerModel, string>,
IGetAble<Customer, string>,
IUpdateAble<CustomerModel, string>,
IDeleteAble<string>
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace SWD_Laundry_Backend.Contract.Service.Interface;

public interface ILaundryStoreService : ICreateAble<LaundryStoreModel, string>, IGetAble<LaundryStore, string>, IUpdateAble<LaundryStoreModel, string>, IDeleteAble<string>
public interface ILaundryStoreService :
ICreateAble<LaundryStoreModel, string>,
IGetAble<LaundryStore, string>,
IUpdateAble<LaundryStoreModel, string>,
IDeleteAble<string>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Service.Base_Service_Interface;
using SWD_Laundry_Backend.Core.Models;

namespace SWD_Laundry_Backend.Contract.Service.Interface;

public interface IOrderHistoryService :
ICreateAble<OrderHistoryModel, string>,
IGetAble<OrderHistory, string>,
IUpdateAble<OrderHistoryModel, string>,
IDeleteAble<string>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Service.Base_Service_Interface;
using SWD_Laundry_Backend.Core.Models;

namespace SWD_Laundry_Backend.Contract.Service.Interface;

public interface IOrderService :
ICreateAble<OrderModel, string>,
IGetAble<Order, string>,
IUpdateAble<OrderModel, string>,
IDeleteAble<string>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Service.Base_Service_Interface;
using SWD_Laundry_Backend.Core.Models;

namespace SWD_Laundry_Backend.Contract.Service.Interface;

public interface IPaymentService :
ICreateAble<PaymentModel, string>,
IGetAble<Payment, string>,
IUpdateAble<PaymentModel, string>,
IDeleteAble<string>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using SWD_Laundry_Backend.Contract.Service.Base_Service_Interface;
using SWD_Laundry_Backend.Core.Models;

namespace SWD_Laundry_Backend.Contract.Service.Interface;

public interface IStaffService :
ICreateAble<StaffModel, string>,
IGetAble<Staff, string>,
IUpdateAble<StaffModel, string>,
IDeleteAble<string>
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace SWD_Laundry_Backend.Contract.Service.Interface;
public interface ITransactionService :
ICreateAble<TransactionModel, string>,
IGetAble<Transaction, string>,
IUpdateAble<TransactionModel, string>
IUpdateAble<TransactionModel, string>,
IDeleteAble<string>
{
}
7 changes: 7 additions & 0 deletions src/SWD-Laundry-Backend.Core/Models/CustomerModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SWD_Laundry_Backend.Core.Models;

public class CustomerModel
{
public string? BuildingId { get; set; }
public string? ApplicationUserId { get; set; }
}
11 changes: 5 additions & 6 deletions src/SWD-Laundry-Backend.Core/Models/OrderModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ public class OrderModel
public DateTime OrderDate { get; set; }
public TimeFrame DeliveryTimeFrame { get; set; }
public DateTime ExpectedFinishDate { get; set; }
public OrderType OrderType { get; set; }
public PaymentType PaymentType { get; set; }
public string? Address { get; set; }
public short Amount { get; set; }
public double TotalPrice { get; set; }

public string? CustomerName { get; set; }
public string? StaffName { get; set; }
public string? LaundryStoreName { get; set; }

public int OrderType { get; set; }
public int PaymentType { get; set; }
public string? CustomerId { get; set; }
public string? StaffId { get; set; }
public string? LaundryStoreId { get; set; }
}
12 changes: 3 additions & 9 deletions src/SWD-Laundry-Backend.Core/Models/StaffModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SWD_Laundry_Backend.Core.Models;

namespace SWD_Laundry_Backend.Core.Models;
public class StaffModel
{
public string? Name { get; set; }
public string? WalletBalance { get; set; }
}
public string? ApplicationUserId { get; set; }
}
6 changes: 3 additions & 3 deletions src/SWD-Laundry-Backend.Core/Utils/CoreHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace SWD_Laundry_Backend.Core.Utils;
public static class CoreHelper
{
private static IHttpContextAccessor? _contextAccessor;
public static HttpContext CurrentHttpContext => Current;
private static readonly IHttpContextAccessor? _contextAccessor;
public static HttpContext? CurrentHttpContext => Current;

public static TimeZoneInfo SystemTimeZoneInfo => GetTimeZoneInfo(Formattings.TimeZone);

Expand Down Expand Up @@ -45,6 +45,6 @@ public static Dictionary<string, EnumObject[]> GetAllEnums()
.Where(t => t.IsEnum)
.ToDictionary(t => t.Name, t =>
System.Enum.GetNames(t)
.Zip(System.Enum.GetValues(t).Cast<int>(), (Key, Value) => new EnumObject(Key, value: Value, ToSentenceCase(Key))).ToArray());
.Zip(System.Enum.GetValues(t).Cast<int>(), (Key, Value) => new EnumObject(Key, Value, ToSentenceCase(Key))).ToArray());
}
}
8 changes: 4 additions & 4 deletions src/SWD-Laundry-Backend.Core/ValueObject/EnumObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
public record EnumObject
{

public EnumObject(string key, int value, string v)
public EnumObject(string _key, int _value, string _displayName)
{
name = key;
value = value;
displayName = v;
name = _key;
value = _value;
displayName = _displayName;
}

public string name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Invedia.DI.Attributes;
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;
using SWD_Laundry_Backend.Contract.Repository.Interface;
using SWD_Laundry_Backend.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Repository.Repository;

[ScopedDependency(ServiceType = typeof(ICustomerRepository))]
public class CustomerRepository : Repository<Customer>, ICustomerRepository
{
public CustomerRepository(AppDbContext dbContext, ICacheLayer<Customer> cacheLayer) : base(dbContext, cacheLayer)

{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Invedia.DI.Attributes;
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;
using SWD_Laundry_Backend.Contract.Repository.Interface;
using SWD_Laundry_Backend.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Repository.Repository;

[ScopedDependency(ServiceType = typeof(IOrderHistoryRepository))]
public class OrderHistoryRepository : Repository<OrderHistory>, IOrderHistoryRepository
{
public OrderHistoryRepository(AppDbContext dbContext, ICacheLayer<OrderHistory> cacheLayer) : base(dbContext, cacheLayer)
{
}
}
15 changes: 15 additions & 0 deletions src/SWD-Laundry-Backend.Repository/Repository/OrderRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Invedia.DI.Attributes;
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;
using SWD_Laundry_Backend.Contract.Repository.Interface;
using SWD_Laundry_Backend.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Repository.Repository;

[ScopedDependency(ServiceType = typeof(IOrderRepository))]
public class OrderRepository : Repository<Order>, IOrderRepository
{
public OrderRepository(AppDbContext dbContext, ICacheLayer<Order> cacheLayer) : base(dbContext, cacheLayer)
{
}
}
15 changes: 15 additions & 0 deletions src/SWD-Laundry-Backend.Repository/Repository/PaymentRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Invedia.DI.Attributes;
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;
using SWD_Laundry_Backend.Contract.Repository.Interface;
using SWD_Laundry_Backend.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Repository.Repository;

[ScopedDependency(ServiceType = typeof(IPaymentRepository))]
public class PaymentRepository : Repository<Payment>, IPaymentRepository
{
public PaymentRepository(AppDbContext dbContext, ICacheLayer<Payment> cacheLayer) : base(dbContext, cacheLayer)
{
}
}
14 changes: 14 additions & 0 deletions src/SWD-Laundry-Backend.Repository/Repository/StaffRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Invedia.DI.Attributes;
using SWD_Laundry_Backend.Contract.Repository.Infrastructure;
using SWD_Laundry_Backend.Contract.Repository.Interface;
using SWD_Laundry_Backend.Repository.Infrastructure;

namespace SWD_Laundry_Backend.Repository.Repository;

[ScopedDependency(ServiceType = typeof(IStaffRepository))]
public class StaffRepository : Repository<Staff>, IStaffRepository
{
public StaffRepository(AppDbContext dbContext, ICacheLayer<Staff> cacheLayer) : base(dbContext, cacheLayer)
{
}
}
59 changes: 59 additions & 0 deletions src/SWD-Laundry-Backend.Service/Services/CustomerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using AutoMapper;
using Invedia.DI.Attributes;
using Microsoft.EntityFrameworkCore;
using SWD_Laundry_Backend.Contract.Repository.Entity;
using SWD_Laundry_Backend.Contract.Repository.Interface;
using SWD_Laundry_Backend.Contract.Service.Interface;
using SWD_Laundry_Backend.Core.Models;

namespace SWD_Laundry_Backend.Service.Services;

[ScopedDependency(ServiceType = typeof(ICustomerService))]
public class CustomerService : ICustomerService
{
private readonly ICustomerRepository _repository;
private readonly IMapper _mapper;

public CustomerService(ICustomerRepository repository, IMapper mapper)
{
_repository = repository;
_mapper = mapper;
}

public async Task<string> CreateAsync(CustomerModel model, CancellationToken cancellationToken = default)
{
var query = await _repository.AddAsync(_mapper.Map<Customer>(model), cancellationToken);
var objectId = query.Id;
return objectId;
}

public async Task<int> DeleteAsync(string id, CancellationToken cancellationToken = default)
{
var numberOfRows = await _repository.DeleteAsync(x => x.Id == id, cancellationToken: cancellationToken);
return numberOfRows;
}

public async Task<ICollection<Customer>> GetAllAsync(CancellationToken cancellationToken = default)
{
var list = await _repository.GetAsync(cancellationToken: cancellationToken);
return await list.ToListAsync(cancellationToken);
}

public async Task<Customer?> GetByIdAsync(string id, CancellationToken cancellationToken = default)
{
var query = await _repository.GetAsync(c => c.Id == id, cancellationToken);
var obj = await query.FirstOrDefaultAsync(cancellationToken: cancellationToken);
return obj;
}

public async Task<int> UpdateAsync(string id, CustomerModel model, CancellationToken cancellationToken = default)
{
var numberOfRows = await _repository.UpdateAsync(x => x.Id == id,
x => x
.SetProperty(x => x.BuildingID, model.BuildingId)
.SetProperty(x => x.ApplicationUserID, model.ApplicationUserId)
, cancellationToken);

return numberOfRows;
}
}
Loading
Loading