diff --git a/.gitignore b/.gitignore index 7740e22..797424d 100644 --- a/.gitignore +++ b/.gitignore @@ -237,5 +237,7 @@ _Pvt_Extensions /.mfractor src/WebUI/ClientApp/package-lock.json /src/WebUI/appsettings.json + /src/SWD-Laundry-Backend/appsettings.Development.json /src/SWD-Laundry-Backend/appsettings.Production.json + diff --git a/Script.sql b/Script.sql index 4202993..bfae506 100644 Binary files a/Script.sql and b/Script.sql differ diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Building.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Building.cs index 9b769ef..51bed1f 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Building.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Building.cs @@ -6,9 +6,4 @@ public class Building : BaseEntity public string Name { get; set; } public string Address { get; set; } public string Description { get; set; } - - #region Relationship - public List Customers { get; set; } - public List Staff_Trips { get; set; } - #endregion } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Customer.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Customer.cs index 317f843..24b2928 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Customer.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Customer.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations.Schema; -using SWD_Laundry_Backend.Contract.Repository.Entity; using SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels; namespace SWD_Laundry_Backend.Contract.Repository.Entity; @@ -8,27 +7,15 @@ namespace SWD_Laundry_Backend.Contract.Repository.Entity; public class Customer : BaseEntity { - //public string Name { get; set; } - //public string Address { get; set; } - - #region Relationship - [ForeignKey("Building")] public string BuildingID { get; set; } [ForeignKey("ApplicationUser")] public string ApplicationUserID { get; set; } + ////=========================== public Building Building { get; set; } public ApplicationUser ApplicationUser { get; set; } - public virtual List Order { get; set; } - - #endregion Relationship - - #region Special Attribute - - - - #endregion Special Attribute + //public virtual List Order { get; set; } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/LaundryStore.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/LaundryStore.cs index 27fed5b..1282675 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/LaundryStore.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/LaundryStore.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations.Schema; -using SWD_Laundry_Backend.Contract.Repository.Entity; using SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels; namespace SWD_Laundry_Backend.Contract.Repository.Entity; @@ -14,14 +13,11 @@ public class LaundryStore : BaseEntity public DateTime EndTime { get; set; } public bool Status { get; set; } - #region Relationship - + ////=========================== [ForeignKey("ApplicationUser")] public string ApplicationUserID { get; set; } public ApplicationUser ApplicationUser { get; set; } - public List Orders{ get; set; } - - #endregion Relationship + //public List Orders { get; set; } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Order.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Order.cs index 6cb3ee9..232e1e5 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Order.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Order.cs @@ -9,14 +9,17 @@ public class Order : BaseEntity 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; } // Address = Customer's building location public short Amount { get; set; } public double TotalPrice { get; set; } - #region Relationship - - [ForeignKey("Customer")] + ////=========================== + [ForeignKey(nameof(Customer))] public string CustomerID { get; set; } [ForeignKey(nameof(LaundryStore))] @@ -31,15 +34,6 @@ public class Order : BaseEntity public Staff Staff { get; set; } public LaundryStore LaundryStore { get; set; } - public List Payments { get; set; } - public List OrderHistories { get; set; } - - #endregion Relationship - - #region Special Attribute - - public OrderType OrderType { get; set; } - public PaymentType PaymentType { get; set; } - - #endregion Special Attribute + //public List Payments { get; set; } + //public List OrderHistories { get; set; } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/OrderHistory.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/OrderHistory.cs index 2f68205..1e41b38 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/OrderHistory.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/OrderHistory.cs @@ -9,20 +9,13 @@ public class OrderHistory : BaseEntity public string Title { get; set; } public string Message { get; set; } - #region Relationship + public OrderStatus OrderStatus { get; set; } + public DeliveryStatus DeliveryStatus { get; set; } + public LaundryStatus LaundryStatus { get; set; } + ////=========================== [ForeignKey("Order")] public string OrderID { get; set; } public Order Order { get; set; } - - #endregion Relationship - - #region Special attributes - - public OrderStatus OrderStatus { get; set; } - public DeliveryStatus DeliveryStatus { get; set; } - public LaundryStatus LaundryStatus { get; set; } - - #endregion Special attributes } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Payment.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Payment.cs index cc1ace4..2cbba7c 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Payment.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Payment.cs @@ -7,13 +7,9 @@ public class Payment : BaseEntity { public double Price { get; set; } - #region Relationship - + ////=========================== [ForeignKey(nameof(Order))] public string OrderId { get; set; } - public Transaction Transaction { get; set; } public Order Orders { get; set; } - - #endregion Relationship } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Staff.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Staff.cs index 8c7fea3..2a4d649 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Staff.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Staff.cs @@ -2,24 +2,14 @@ using SWD_Laundry_Backend.Contract.Repository.Entity; using SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels; - - #nullable disable public class Staff : BaseEntity { - //public DateTime Dob { get; set; } - //public string Address { get; set; } - //public double Salary { get; set; } - - #region Relationship - [ForeignKey("ApplicationUser")] public string ApplicationUserID { get; set; } public ApplicationUser ApplicationUser { get; set; } - public List Staff_Trips { get; set; } - - #endregion Relationship + //public List Staff_Trips { get; set; } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Staff_Trip.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Staff_Trip.cs index db749de..0dcda0b 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Staff_Trip.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Staff_Trip.cs @@ -9,8 +9,9 @@ public class Staff_Trip : BaseEntity { public int TripCollect { get; set; } = 0; - #region Relationship + public TripType TripType { get; set; } + ////=========================== [ForeignKey("Staff")] public string StaffID { get; set; } @@ -20,15 +21,9 @@ public class Staff_Trip : BaseEntity [ForeignKey("Building")] public string BuildingID { get; set; } + ////=========================== + public Building Building { get; set; } public Staff Staff { get; set; } public TimeSchedule TimeSchedule { get; set; } - - #endregion Relationship - - #region Special Attribute - - public TripType TripType { get; set; } - - #endregion Special Attribute } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/TimeSchedule.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/TimeSchedule.cs index b5ebd26..67d696b 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/TimeSchedule.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/TimeSchedule.cs @@ -1,6 +1,6 @@ -using SWD_Laundry_Backend.Contract.Repository.Entity; -using SWD_Laundry_Backend.Core.Enum; +using SWD_Laundry_Backend.Core.Enum; +namespace SWD_Laundry_Backend.Contract.Repository.Entity; #nullable disable public class TimeSchedule : BaseEntity @@ -8,11 +8,7 @@ public class TimeSchedule : BaseEntity public DateTime StartTime { get; set; } public DateTime EndTime { get; set; } - #region Special Attribute - public DayOfWeek DayOfWeek { get; set; } public TimeFrame TimeFrame { get; set; } - public List Staff_Trip { get; set; } - - #endregion Special Attribute + //public virtual List Staff_Trip { get; set; } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Transaction.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Transaction.cs index 6f01340..9ae6dff 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Transaction.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Transaction.cs @@ -9,20 +9,16 @@ public class Transaction : BaseEntity public string PaymentMethod { get; set; } public int Amount { get; set; } public string Description { get; set; } + public AllowedTransactionType TransactionType { get; set; } - #region Relationship - + ////=========================== [ForeignKey(nameof(Wallet))] public string WalletID { get; set; } public Wallet Wallet { get; set; } - public List Payments { get; set; } - - #endregion Relationship - - #region Special Attribute - - public AllowedTransactionType TransactionType { get; set; } - #endregion Special Attribute + [ForeignKey(nameof(Payment))] + public string PaymentID { get; set; } + public Payment Payment { get; set; } + //public List Payments { get; set; } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Wallet.cs b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Wallet.cs index 09b0e5a..6d8ee2c 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Entity/Wallet.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Entity/Wallet.cs @@ -1,5 +1,4 @@ -using SWD_Laundry_Backend.Contract.Repository.Entity; -using SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels; +using SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels; namespace SWD_Laundry_Backend.Contract.Repository.Entity; #nullable disable @@ -8,11 +7,6 @@ public class Wallet : BaseEntity { public double Balance { get; set; } - #region Relationship - - public List Transactions { get; set; } - public ApplicationUser ApplicationUser { get; set; } - - #endregion Relationship + //public List Transactions { get; set; } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Interface/ILaundryStoreRepository.cs b/src/SWD-Laundry-Backend.Contract.Repository/Interface/ILaundryStoreRepository.cs new file mode 100644 index 0000000..76ea065 --- /dev/null +++ b/src/SWD-Laundry-Backend.Contract.Repository/Interface/ILaundryStoreRepository.cs @@ -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 ILaundryStoreRepository : IRepository +{ +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Interface/IStaffTripRepository.cs b/src/SWD-Laundry-Backend.Contract.Repository/Interface/IStaffTripRepository.cs new file mode 100644 index 0000000..484012f --- /dev/null +++ b/src/SWD-Laundry-Backend.Contract.Repository/Interface/IStaffTripRepository.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SWD_Laundry_Backend.Contract.Repository.Entity; +using SWD_Laundry_Backend.Contract.Repository.Infrastructure; + +namespace SWD_Laundry_Backend.Contract.Repository.Interface; +public interface IStaffTripRepository : IRepository +{ +} diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Interface/ITimeScheduleRepository.cs b/src/SWD-Laundry-Backend.Contract.Repository/Interface/ITimeScheduleRepository.cs index 69c5674..a7f4370 100644 --- a/src/SWD-Laundry-Backend.Contract.Repository/Interface/ITimeScheduleRepository.cs +++ b/src/SWD-Laundry-Backend.Contract.Repository/Interface/ITimeScheduleRepository.cs @@ -1,4 +1,5 @@ -using SWD_Laundry_Backend.Contract.Repository.Infrastructure; +using SWD_Laundry_Backend.Contract.Repository.Entity; +using SWD_Laundry_Backend.Contract.Repository.Infrastructure; namespace SWD_Laundry_Backend.Contract.Repository.Interface; diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Interface/ITransactionRepository.cs b/src/SWD-Laundry-Backend.Contract.Repository/Interface/ITransactionRepository.cs new file mode 100644 index 0000000..e24ebcc --- /dev/null +++ b/src/SWD-Laundry-Backend.Contract.Repository/Interface/ITransactionRepository.cs @@ -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 ITransactionRepository : IRepository +{ +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Repository/Interface/IWalletRepository.cs b/src/SWD-Laundry-Backend.Contract.Repository/Interface/IWalletRepository.cs new file mode 100644 index 0000000..482b7be --- /dev/null +++ b/src/SWD-Laundry-Backend.Contract.Repository/Interface/IWalletRepository.cs @@ -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 IWalletRepository : IRepository +{ +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Service/Interface/ILaundryStoreService.cs b/src/SWD-Laundry-Backend.Contract.Service/Interface/ILaundryStoreService.cs new file mode 100644 index 0000000..239b68a --- /dev/null +++ b/src/SWD-Laundry-Backend.Contract.Service/Interface/ILaundryStoreService.cs @@ -0,0 +1,9 @@ +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 ILaundryStoreService : ICreateAble, IGetAble, IUpdateAble, IDeleteAble +{ +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Service/Interface/IStaffTripService.cs b/src/SWD-Laundry-Backend.Contract.Service/Interface/IStaffTripService.cs new file mode 100644 index 0000000..8897283 --- /dev/null +++ b/src/SWD-Laundry-Backend.Contract.Service/Interface/IStaffTripService.cs @@ -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 IStaffTripService : + ICreateAble, + IGetAble, + IUpdateAble, + IDeleteAble +{ +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Service/Interface/ITimeScheduleService.cs b/src/SWD-Laundry-Backend.Contract.Service/Interface/ITimeScheduleService.cs index 2d2c4ae..9b55115 100644 --- a/src/SWD-Laundry-Backend.Contract.Service/Interface/ITimeScheduleService.cs +++ b/src/SWD-Laundry-Backend.Contract.Service/Interface/ITimeScheduleService.cs @@ -1,8 +1,13 @@ -using SWD_Laundry_Backend.Contract.Service.Base_Service_Interface; +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 ITimeScheduleService : ICreateAble, IGetAble, IUpdateAble, IDeleteAble +public interface ITimeScheduleService : + ICreateAble, + IGetAble, + IUpdateAble, + IDeleteAble { } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Service/Interface/ITransactionService.cs b/src/SWD-Laundry-Backend.Contract.Service/Interface/ITransactionService.cs new file mode 100644 index 0000000..0d830a0 --- /dev/null +++ b/src/SWD-Laundry-Backend.Contract.Service/Interface/ITransactionService.cs @@ -0,0 +1,12 @@ +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 ITransactionService : + ICreateAble, + IGetAble, + IUpdateAble +{ +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Contract.Service/Interface/IWalletService.cs b/src/SWD-Laundry-Backend.Contract.Service/Interface/IWalletService.cs new file mode 100644 index 0000000..240b306 --- /dev/null +++ b/src/SWD-Laundry-Backend.Contract.Service/Interface/IWalletService.cs @@ -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 IWalletService : + ICreateAble, + IGetAble, + IDeleteAble, + IUpdateAble +{ +} diff --git a/src/SWD-Laundry-Backend.Core/Enum/AllowedTransactionType.cs b/src/SWD-Laundry-Backend.Core/Enum/AllowedTransactionType.cs index 4d2e176..febeabc 100644 --- a/src/SWD-Laundry-Backend.Core/Enum/AllowedTransactionType.cs +++ b/src/SWD-Laundry-Backend.Core/Enum/AllowedTransactionType.cs @@ -1,8 +1,8 @@ namespace SWD_Laundry_Backend.Core.Enum; public enum AllowedTransactionType { - Deposit = 1, - Withdraw = 2, - Debt = 3, - Paid = 4 + Deposit = 0, + Withdraw = 1, + Debt = 2, + Paid = 3 } diff --git a/src/SWD-Laundry-Backend.Core/Enum/OrderStatus.cs b/src/SWD-Laundry-Backend.Core/Enum/OrderStatus.cs index db7cc71..587fb7b 100644 --- a/src/SWD-Laundry-Backend.Core/Enum/OrderStatus.cs +++ b/src/SWD-Laundry-Backend.Core/Enum/OrderStatus.cs @@ -1,8 +1,8 @@ namespace SWD_Laundry_Backend.Core.Enum; public enum OrderStatus { - Preparing = 1, - Processing = 2, - Completed = 3, - Cancelled = 4 + Preparing = 0, + Processing = 1, + Completed = 2, + Cancelled = 3 } diff --git a/src/SWD-Laundry-Backend.Core/Enum/OrderType.cs b/src/SWD-Laundry-Backend.Core/Enum/OrderType.cs index c95ec26..c6e11cf 100644 --- a/src/SWD-Laundry-Backend.Core/Enum/OrderType.cs +++ b/src/SWD-Laundry-Backend.Core/Enum/OrderType.cs @@ -1,6 +1,6 @@ namespace SWD_Laundry_Backend.Core.Enum; public enum OrderType { - OneWay = 1, - TwoWay = 2 + OneWay = 0, + TwoWay = 1 } diff --git a/src/SWD-Laundry-Backend.Core/Enum/PaymentType.cs b/src/SWD-Laundry-Backend.Core/Enum/PaymentType.cs index 478b06d..d2d9e6f 100644 --- a/src/SWD-Laundry-Backend.Core/Enum/PaymentType.cs +++ b/src/SWD-Laundry-Backend.Core/Enum/PaymentType.cs @@ -1,8 +1,8 @@ namespace SWD_Laundry_Backend.Core.Enum; public enum PaymentType { - Cash = 1, - CreditCard = 2, - DebitCard = 3, - EWallet = 4 + Cash = 0, + CreditCard = 1, + DebitCard = 2, + EWallet = 3 } diff --git a/src/SWD-Laundry-Backend.Core/Enum/TripType.cs b/src/SWD-Laundry-Backend.Core/Enum/TripType.cs index b5075df..2a73ee1 100644 --- a/src/SWD-Laundry-Backend.Core/Enum/TripType.cs +++ b/src/SWD-Laundry-Backend.Core/Enum/TripType.cs @@ -1,7 +1,11 @@ -namespace SWD_Laundry_Backend.Core.Enum; +using Newtonsoft.Json; +using SWD_Laundry_Backend.Core.Utils; +namespace SWD_Laundry_Backend.Core.Enum; + +//[JsonConverter(typeof(EnumConverter))] public enum TripType { - Collect_From_Customer = 0, - Delivery_To_Customer = 1, + CollectFromCustomer = 0, + DeliveryToCustomer = 1, } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Core/Models/BaseResponseModels.cs b/src/SWD-Laundry-Backend.Core/Models/BaseResponseModels.cs index 2950328..9476fde 100644 --- a/src/SWD-Laundry-Backend.Core/Models/BaseResponseModels.cs +++ b/src/SWD-Laundry-Backend.Core/Models/BaseResponseModels.cs @@ -1,8 +1,12 @@ -namespace SWD_Laundry_Backend.Core.Models; +using SWD_Laundry_Backend.Core.Utils; +using SWD_Laundry_Backend.Core.ValueObject; + +namespace SWD_Laundry_Backend.Core.Models; public class BaseResponseModel { public T? Data { get; set; } public object? AdditionalData { get; set; } + public Dictionary EnumData { get; set; } = CoreHelper.GetAllEnums(); public string? Message { get; set; } public int StatusCode { get; set; } diff --git a/src/SWD-Laundry-Backend.Core/Models/StaffModel.cs b/src/SWD-Laundry-Backend.Core/Models/StaffModel.cs new file mode 100644 index 0000000..685b8d6 --- /dev/null +++ b/src/SWD-Laundry-Backend.Core/Models/StaffModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWD_Laundry_Backend.Core.Models; +public class StaffModel +{ + public string? Name { get; set; } + public string? WalletBalance { get; set; } +} diff --git a/src/SWD-Laundry-Backend.Core/Models/StaffTripModel.cs b/src/SWD-Laundry-Backend.Core/Models/StaffTripModel.cs index 4dffb42..0ae7873 100644 --- a/src/SWD-Laundry-Backend.Core/Models/StaffTripModel.cs +++ b/src/SWD-Laundry-Backend.Core/Models/StaffTripModel.cs @@ -5,9 +5,9 @@ namespace SWD_Laundry_Backend.Core.Models; public class StaffTripModel { public int TripCollect { get; set; } = 0; - - public BuildingModel? Building { get; set; } // Name of the associated building - public string? StaffName { get; set; } // Name of the associated staff - public TimeScheduleModel? TimeSchedule { get; set; } // Name of the associated time schedule + + public string? BuildingID { get; set; } + public string? TimeScheduleID { get; set; } + public string? StaffID { get; set; } public TripType TripType { get; set; } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Core/SWD-Laundry-Backend.Core.csproj b/src/SWD-Laundry-Backend.Core/SWD-Laundry-Backend.Core.csproj index 0828a68..191fd7a 100644 --- a/src/SWD-Laundry-Backend.Core/SWD-Laundry-Backend.Core.csproj +++ b/src/SWD-Laundry-Backend.Core/SWD-Laundry-Backend.Core.csproj @@ -14,6 +14,7 @@ + diff --git a/src/SWD-Laundry-Backend.Core/Utils/CoreHelper.cs b/src/SWD-Laundry-Backend.Core/Utils/CoreHelper.cs index b60efd4..0e275a7 100644 --- a/src/SWD-Laundry-Backend.Core/Utils/CoreHelper.cs +++ b/src/SWD-Laundry-Backend.Core/Utils/CoreHelper.cs @@ -1,5 +1,8 @@ -using Microsoft.AspNetCore.Http; +using System.Reflection; +using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; using SWD_Laundry_Backend.Core.Constant; +using SWD_Laundry_Backend.Core.ValueObject; using TimeZoneConverter; namespace SWD_Laundry_Backend.Core.Utils; @@ -29,4 +32,19 @@ public static TimeZoneInfo GetTimeZoneInfo(string timeZoneId) } public static HttpContext? Current => _contextAccessor?.HttpContext; + + public static string ToSentenceCase(this string str) + { + return Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1])); + } + + public static Dictionary GetAllEnums() + { + return Assembly.GetExecutingAssembly() + .GetTypes() + .Where(t => t.IsEnum) + .ToDictionary(t => t.Name, t => + System.Enum.GetNames(t) + .Zip(System.Enum.GetValues(t).Cast(), (Key, Value) => new EnumObject(Key, value: Value, ToSentenceCase(Key))).ToArray()); + } } diff --git a/src/SWD-Laundry-Backend.Core/Utils/EnumConverter.cs b/src/SWD-Laundry-Backend.Core/Utils/EnumConverter.cs new file mode 100644 index 0000000..fa25c27 --- /dev/null +++ b/src/SWD-Laundry-Backend.Core/Utils/EnumConverter.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; + +namespace SWD_Laundry_Backend.Core.Utils; +public class EnumConverter : JsonConverter where T : System.Enum +{ + public override T? ReadJson(JsonReader reader, Type objectType, T? existingValue, bool hasExistingValue, JsonSerializer serializer) + => throw new NotImplementedException(); + + public override void WriteJson(JsonWriter writer, T? value, JsonSerializer serializer) + { + var nameAndValue = new { + Name = value.ToString("g"), + Value = value.ToString("d"), + DisplayName = CoreHelper.ToSentenceCase(value.ToString("g")) + }; + var semiJson = JObject.FromObject(nameAndValue); + semiJson.WriteTo(writer); + } +} diff --git a/src/SWD-Laundry-Backend.Core/Utils/ObjHelper.cs b/src/SWD-Laundry-Backend.Core/Utils/ObjHelper.cs index ed7ca72..3489d01 100644 --- a/src/SWD-Laundry-Backend.Core/Utils/ObjHelper.cs +++ b/src/SWD-Laundry-Backend.Core/Utils/ObjHelper.cs @@ -9,10 +9,10 @@ public static string ToJsonString(object obj) JObject? jObject = obj as JObject; if (jObject != null) { - return jObject.ToString(Formatting.None); + return jObject.ToString(Formatting.Indented); } - return JsonConvert.SerializeObject(obj, Formatting.None); + return JsonConvert.SerializeObject(obj, Formatting.Indented); } public static T? Clone(T obj) diff --git a/src/SWD-Laundry-Backend.Core/ValueObject/EnumObject.cs b/src/SWD-Laundry-Backend.Core/ValueObject/EnumObject.cs new file mode 100644 index 0000000..5e47dd2 --- /dev/null +++ b/src/SWD-Laundry-Backend.Core/ValueObject/EnumObject.cs @@ -0,0 +1,15 @@ +namespace SWD_Laundry_Backend.Core.ValueObject; +public record EnumObject +{ + + public EnumObject(string key, int value, string v) + { + name = key; + value = value; + displayName = v; + } + + public string name { get; set; } + public int value { get; set; } + public string displayName { get; set; } +} diff --git a/src/SWD-Laundry-Backend.Mapper/BuildingMapperProfile.cs b/src/SWD-Laundry-Backend.Mapper/BuildingMapperProfile.cs index a4bad90..247219f 100644 --- a/src/SWD-Laundry-Backend.Mapper/BuildingMapperProfile.cs +++ b/src/SWD-Laundry-Backend.Mapper/BuildingMapperProfile.cs @@ -8,6 +8,6 @@ public class BuildingMapperProfile : Profile { public BuildingMapperProfile() { - CreateMap().ReverseMap(); + CreateMap().ForMember(x => x.Id, opt => opt.Ignore()).ReverseMap(); } } diff --git a/src/SWD-Laundry-Backend.Mapper/LaundryStoreMapperProfile.cs b/src/SWD-Laundry-Backend.Mapper/LaundryStoreMapperProfile.cs index 29bc761..3195614 100644 --- a/src/SWD-Laundry-Backend.Mapper/LaundryStoreMapperProfile.cs +++ b/src/SWD-Laundry-Backend.Mapper/LaundryStoreMapperProfile.cs @@ -8,6 +8,6 @@ public class LaundryStoreMapperProfile : Profile { public LaundryStoreMapperProfile() { - CreateMap().ReverseMap(); + CreateMap().ForMember(x => x.Id, opt => opt.Ignore()).ReverseMap(); } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Mapper/OrderHistoryMapperProfile.cs b/src/SWD-Laundry-Backend.Mapper/OrderHistoryMapperProfile.cs index 751fa5f..3281d59 100644 --- a/src/SWD-Laundry-Backend.Mapper/OrderHistoryMapperProfile.cs +++ b/src/SWD-Laundry-Backend.Mapper/OrderHistoryMapperProfile.cs @@ -8,6 +8,6 @@ public class OrderHistoryMapperProfile : Profile { public OrderHistoryMapperProfile() { - CreateMap().ReverseMap(); + CreateMap().ForMember(x => x.Id, opt => opt.Ignore()).ReverseMap(); } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Mapper/OrderMapperProfile.cs b/src/SWD-Laundry-Backend.Mapper/OrderMapperProfile.cs index bde1e6e..f6b24e9 100644 --- a/src/SWD-Laundry-Backend.Mapper/OrderMapperProfile.cs +++ b/src/SWD-Laundry-Backend.Mapper/OrderMapperProfile.cs @@ -8,6 +8,6 @@ public class OrderMapperProfile : Profile { public OrderMapperProfile() { - CreateMap().ReverseMap(); + CreateMap().ForMember(x => x.Id, opt => opt.Ignore()).ReverseMap(); } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Mapper/StaffTripMapperProfile.cs b/src/SWD-Laundry-Backend.Mapper/StaffTripMapperProfile.cs index a0cc3c5..341f7a1 100644 --- a/src/SWD-Laundry-Backend.Mapper/StaffTripMapperProfile.cs +++ b/src/SWD-Laundry-Backend.Mapper/StaffTripMapperProfile.cs @@ -8,6 +8,6 @@ public class StaffTripMapperProfile : Profile { public StaffTripMapperProfile() { - CreateMap().ReverseMap(); + CreateMap().ForMember(x => x.Id, opt => opt.Ignore()).ReverseMap(); } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Mapper/TimeScheduleMapperProfile.cs b/src/SWD-Laundry-Backend.Mapper/TimeScheduleMapperProfile.cs index fd305c3..e0fb90c 100644 --- a/src/SWD-Laundry-Backend.Mapper/TimeScheduleMapperProfile.cs +++ b/src/SWD-Laundry-Backend.Mapper/TimeScheduleMapperProfile.cs @@ -1,4 +1,5 @@ using AutoMapper; +using SWD_Laundry_Backend.Contract.Repository.Entity; using SWD_Laundry_Backend.Core.Models; namespace SWD_Laundry_Backend.Mapper; @@ -7,6 +8,6 @@ public class TimeScheduleMapperProfile : Profile { public TimeScheduleMapperProfile() { - CreateMap().ReverseMap(); + CreateMap().ForMember(x => x.Id, opt => opt.Ignore()).ReverseMap(); } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Mapper/TransactionMapperProfile.cs b/src/SWD-Laundry-Backend.Mapper/TransactionMapperProfile.cs index 23ed873..2d3aad7 100644 --- a/src/SWD-Laundry-Backend.Mapper/TransactionMapperProfile.cs +++ b/src/SWD-Laundry-Backend.Mapper/TransactionMapperProfile.cs @@ -8,6 +8,6 @@ public class TransactionMapperProfile : Profile { public TransactionMapperProfile() { - CreateMap().ReverseMap(); + CreateMap().ForMember(x => x.Id, opt => opt.Ignore()).ReverseMap(); } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Mapper/WalletMapperProfile.cs b/src/SWD-Laundry-Backend.Mapper/WalletMapperProfile.cs index b4d8b3e..e4e7b25 100644 --- a/src/SWD-Laundry-Backend.Mapper/WalletMapperProfile.cs +++ b/src/SWD-Laundry-Backend.Mapper/WalletMapperProfile.cs @@ -8,8 +8,6 @@ public class WalletMapperProfile : Profile { public WalletMapperProfile() { - CreateMap().ReverseMap(); + CreateMap().ForMember(x => x.Id, opt => opt.Ignore()).ReverseMap(); } - -} - +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Repository/Migrations/20231002072614_UpdateDatbase7.Designer.cs b/src/SWD-Laundry-Backend.Repository/Migrations/20231004172440_UpdateStaff.Designer.cs similarity index 98% rename from src/SWD-Laundry-Backend.Repository/Migrations/20231002072614_UpdateDatbase7.Designer.cs rename to src/SWD-Laundry-Backend.Repository/Migrations/20231004172440_UpdateStaff.Designer.cs index bac6672..80c85ab 100644 --- a/src/SWD-Laundry-Backend.Repository/Migrations/20231002072614_UpdateDatbase7.Designer.cs +++ b/src/SWD-Laundry-Backend.Repository/Migrations/20231004172440_UpdateStaff.Designer.cs @@ -12,8 +12,8 @@ namespace SWD_Laundry_Backend.Repository.Migrations { [DbContext(typeof(AppDbContext))] - [Migration("20231002072614_UpdateDatbase7")] - partial class UpdateDatbase7 + [Migration("20231004172440_UpdateStaff")] + partial class UpdateStaff { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -519,6 +519,40 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Staff_Trips"); }); + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.TimeSchedule", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("DayOfWeek") + .HasColumnType("int"); + + b.Property("EndTime") + .HasColumnType("datetime2"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("StartTime") + .HasColumnType("datetime2"); + + b.Property("TimeFrame") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("TimeSchedules"); + }); + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Transaction", b => { b.Property("Id") @@ -610,40 +644,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Staffs"); }); - modelBuilder.Entity("TimeSchedule", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("CreatedBy") - .HasColumnType("nvarchar(max)"); - - b.Property("CreatedTime") - .HasColumnType("datetimeoffset"); - - b.Property("DayOfWeek") - .HasColumnType("int"); - - b.Property("EndTime") - .HasColumnType("datetime2"); - - b.Property("LastUpdatedBy") - .HasColumnType("nvarchar(max)"); - - b.Property("LastUpdatedTime") - .HasColumnType("datetimeoffset"); - - b.Property("StartTime") - .HasColumnType("datetime2"); - - b.Property("TimeFrame") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("TimeSchedules"); - }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) @@ -783,8 +783,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .WithMany("Staff_Trips") .HasForeignKey("StaffID"); - b.HasOne("TimeSchedule", "TimeSchedule") - .WithMany("Staff_Trip") + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.TimeSchedule", "TimeSchedule") + .WithMany() .HasForeignKey("TimeScheduleID"); b.Navigation("Building"); @@ -852,11 +852,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Navigation("Staff_Trips"); }); - - modelBuilder.Entity("TimeSchedule", b => - { - b.Navigation("Staff_Trip"); - }); #pragma warning restore 612, 618 } } diff --git a/src/SWD-Laundry-Backend.Repository/Migrations/20231002072614_UpdateDatbase7.cs b/src/SWD-Laundry-Backend.Repository/Migrations/20231004172440_UpdateStaff.cs similarity index 96% rename from src/SWD-Laundry-Backend.Repository/Migrations/20231002072614_UpdateDatbase7.cs rename to src/SWD-Laundry-Backend.Repository/Migrations/20231004172440_UpdateStaff.cs index c34a2c0..98bfa96 100644 --- a/src/SWD-Laundry-Backend.Repository/Migrations/20231002072614_UpdateDatbase7.cs +++ b/src/SWD-Laundry-Backend.Repository/Migrations/20231004172440_UpdateStaff.cs @@ -6,7 +6,7 @@ namespace SWD_Laundry_Backend.Repository.Migrations { /// - public partial class UpdateDatbase7 : Migration + public partial class UpdateStaff : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/src/SWD-Laundry-Backend.Repository/Migrations/20231004174024_UpdateTransaction.Designer.cs b/src/SWD-Laundry-Backend.Repository/Migrations/20231004174024_UpdateTransaction.Designer.cs new file mode 100644 index 0000000..a69a51f --- /dev/null +++ b/src/SWD-Laundry-Backend.Repository/Migrations/20231004174024_UpdateTransaction.Designer.cs @@ -0,0 +1,822 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SWD_Laundry_Backend.Repository.Infrastructure; + +#nullable disable + +namespace SWD_Laundry_Backend.Repository.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20231004174024_UpdateTransaction")] + partial class UpdateTransaction + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Building", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Address") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Buildings"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Customer", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ApplicationUserID") + .HasColumnType("nvarchar(450)"); + + b.Property("BuildingID") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserID"); + + b.HasIndex("BuildingID"); + + b.ToTable("Customers"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("WalletID") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.HasIndex("WalletID") + .IsUnique() + .HasFilter("[WalletID] IS NOT NULL"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.LaundryStore", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Address") + .HasColumnType("nvarchar(max)"); + + b.Property("ApplicationUserID") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("EndTime") + .HasColumnType("datetime2"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("StartTime") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("bit"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserID"); + + b.ToTable("LaundryStores"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Order", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Address") + .HasColumnType("nvarchar(max)"); + + b.Property("Amount") + .HasColumnType("smallint"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("CustomerID") + .HasColumnType("nvarchar(450)"); + + b.Property("DeliveryTimeFrame") + .HasColumnType("int"); + + b.Property("ExpectedFinishDate") + .HasColumnType("datetime2"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("LaundryStoreID") + .HasColumnType("nvarchar(450)"); + + b.Property("OrderDate") + .HasColumnType("datetime2"); + + b.Property("OrderType") + .HasColumnType("int"); + + b.Property("PaymentType") + .HasColumnType("int"); + + b.Property("StaffID") + .HasColumnType("nvarchar(450)"); + + b.Property("TotalPrice") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("CustomerID"); + + b.HasIndex("LaundryStoreID"); + + b.HasIndex("StaffID"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.OrderHistory", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("DeliveryStatus") + .HasColumnType("int"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("LaundryStatus") + .HasColumnType("int"); + + b.Property("Message") + .HasColumnType("nvarchar(max)"); + + b.Property("OrderID") + .HasColumnType("nvarchar(450)"); + + b.Property("OrderStatus") + .HasColumnType("int"); + + b.Property("Title") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("OrderID"); + + b.ToTable("OrderHistories"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Payment", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("OrderId") + .HasColumnType("nvarchar(450)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("Payments"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Staff_Trip", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("BuildingID") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("StaffID") + .HasColumnType("nvarchar(450)"); + + b.Property("TimeScheduleID") + .HasColumnType("nvarchar(450)"); + + b.Property("TripCollect") + .HasColumnType("int"); + + b.Property("TripType") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BuildingID"); + + b.HasIndex("StaffID"); + + b.HasIndex("TimeScheduleID"); + + b.ToTable("Staff_Trips"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.TimeSchedule", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("DayOfWeek") + .HasColumnType("int"); + + b.Property("EndTime") + .HasColumnType("datetime2"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("StartTime") + .HasColumnType("datetime2"); + + b.Property("TimeFrame") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("TimeSchedules"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Transaction", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("PaymentID") + .HasColumnType("nvarchar(450)"); + + b.Property("PaymentMethod") + .HasColumnType("nvarchar(max)"); + + b.Property("TransactionType") + .HasColumnType("int"); + + b.Property("WalletID") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("PaymentID"); + + b.HasIndex("WalletID"); + + b.ToTable("Transaction"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Wallet", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Balance") + .HasColumnType("float"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.ToTable("Wallets"); + }); + + modelBuilder.Entity("Staff", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ApplicationUserID") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserID"); + + b.ToTable("Staffs"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Customer", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserID"); + + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Building", "Building") + .WithMany() + .HasForeignKey("BuildingID"); + + b.Navigation("ApplicationUser"); + + b.Navigation("Building"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Wallet", "Wallet") + .WithOne("ApplicationUser") + .HasForeignKey("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", "WalletID"); + + b.Navigation("Wallet"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.LaundryStore", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserID"); + + b.Navigation("ApplicationUser"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Order", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Customer", "Customer") + .WithMany() + .HasForeignKey("CustomerID"); + + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.LaundryStore", "LaundryStore") + .WithMany() + .HasForeignKey("LaundryStoreID"); + + b.HasOne("Staff", "Staff") + .WithMany() + .HasForeignKey("StaffID"); + + b.Navigation("Customer"); + + b.Navigation("LaundryStore"); + + b.Navigation("Staff"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.OrderHistory", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Order", "Order") + .WithMany() + .HasForeignKey("OrderID"); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Payment", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Order", "Orders") + .WithMany() + .HasForeignKey("OrderId"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Staff_Trip", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Building", "Building") + .WithMany() + .HasForeignKey("BuildingID"); + + b.HasOne("Staff", "Staff") + .WithMany() + .HasForeignKey("StaffID"); + + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.TimeSchedule", "TimeSchedule") + .WithMany() + .HasForeignKey("TimeScheduleID"); + + b.Navigation("Building"); + + b.Navigation("Staff"); + + b.Navigation("TimeSchedule"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Transaction", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Payment", "Payment") + .WithMany() + .HasForeignKey("PaymentID"); + + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Wallet", "Wallet") + .WithMany() + .HasForeignKey("WalletID"); + + b.Navigation("Payment"); + + b.Navigation("Wallet"); + }); + + modelBuilder.Entity("Staff", b => + { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserID"); + + b.Navigation("ApplicationUser"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Wallet", b => + { + b.Navigation("ApplicationUser"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/SWD-Laundry-Backend.Repository/Migrations/20231004174024_UpdateTransaction.cs b/src/SWD-Laundry-Backend.Repository/Migrations/20231004174024_UpdateTransaction.cs new file mode 100644 index 0000000..7605e82 --- /dev/null +++ b/src/SWD-Laundry-Backend.Repository/Migrations/20231004174024_UpdateTransaction.cs @@ -0,0 +1,78 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SWD_Laundry_Backend.Repository.Migrations +{ + /// + public partial class UpdateTransaction : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Payments_Transaction_TransactionId", + table: "Payments"); + + migrationBuilder.DropIndex( + name: "IX_Payments_TransactionId", + table: "Payments"); + + migrationBuilder.DropColumn( + name: "TransactionId", + table: "Payments"); + + migrationBuilder.AddColumn( + name: "PaymentID", + table: "Transaction", + type: "nvarchar(450)", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Transaction_PaymentID", + table: "Transaction", + column: "PaymentID"); + + migrationBuilder.AddForeignKey( + name: "FK_Transaction_Payments_PaymentID", + table: "Transaction", + column: "PaymentID", + principalTable: "Payments", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Transaction_Payments_PaymentID", + table: "Transaction"); + + migrationBuilder.DropIndex( + name: "IX_Transaction_PaymentID", + table: "Transaction"); + + migrationBuilder.DropColumn( + name: "PaymentID", + table: "Transaction"); + + migrationBuilder.AddColumn( + name: "TransactionId", + table: "Payments", + type: "nvarchar(450)", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Payments_TransactionId", + table: "Payments", + column: "TransactionId"); + + migrationBuilder.AddForeignKey( + name: "FK_Payments_Transaction_TransactionId", + table: "Payments", + column: "TransactionId", + principalTable: "Transaction", + principalColumn: "Id"); + } + } +} diff --git a/src/SWD-Laundry-Backend.Repository/Migrations/AppDbContextModelSnapshot.cs b/src/SWD-Laundry-Backend.Repository/Migrations/AppDbContextModelSnapshot.cs index d5d09ce..420dd39 100644 --- a/src/SWD-Laundry-Backend.Repository/Migrations/AppDbContextModelSnapshot.cs +++ b/src/SWD-Laundry-Backend.Repository/Migrations/AppDbContextModelSnapshot.cs @@ -183,7 +183,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.ToTable("Buildings", (string)null); + b.ToTable("Buildings"); }); modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Customer", b => @@ -215,7 +215,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("BuildingID"); - b.ToTable("Customers", (string)null); + b.ToTable("Customers"); }); modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels.ApplicationUser", b => @@ -332,7 +332,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("ApplicationUserID"); - b.ToTable("LaundryStores", (string)null); + b.ToTable("LaundryStores"); }); modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Order", b => @@ -393,7 +393,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("StaffID"); - b.ToTable("Orders", (string)null); + b.ToTable("Orders"); }); modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.OrderHistory", b => @@ -435,7 +435,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("OrderID"); - b.ToTable("OrderHistories", (string)null); + b.ToTable("OrderHistories"); }); modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Payment", b => @@ -461,16 +461,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Price") .HasColumnType("float"); - b.Property("TransactionId") - .HasColumnType("nvarchar(450)"); - b.HasKey("Id"); b.HasIndex("OrderId"); - b.HasIndex("TransactionId"); - - b.ToTable("Payments", (string)null); + b.ToTable("Payments"); }); modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Staff_Trip", b => @@ -513,7 +508,41 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("TimeScheduleID"); - b.ToTable("Staff_Trips", (string)null); + b.ToTable("Staff_Trips"); + }); + + modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.TimeSchedule", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("DayOfWeek") + .HasColumnType("int"); + + b.Property("EndTime") + .HasColumnType("datetime2"); + + b.Property("LastUpdatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastUpdatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("StartTime") + .HasColumnType("datetime2"); + + b.Property("TimeFrame") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("TimeSchedules"); }); modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Transaction", b => @@ -539,6 +568,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("LastUpdatedTime") .HasColumnType("datetimeoffset"); + b.Property("PaymentID") + .HasColumnType("nvarchar(450)"); + b.Property("PaymentMethod") .HasColumnType("nvarchar(max)"); @@ -550,9 +582,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("PaymentID"); + b.HasIndex("WalletID"); - b.ToTable("Transaction", (string)null); + b.ToTable("Transaction"); }); modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Wallet", b => @@ -577,7 +611,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.ToTable("Wallets", (string)null); + b.ToTable("Wallets"); }); modelBuilder.Entity("Staff", b => @@ -604,41 +638,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("ApplicationUserID"); - b.ToTable("Staffs", (string)null); - }); - - modelBuilder.Entity("TimeSchedule", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("CreatedBy") - .HasColumnType("nvarchar(max)"); - - b.Property("CreatedTime") - .HasColumnType("datetimeoffset"); - - b.Property("DayOfWeek") - .HasColumnType("int"); - - b.Property("EndTime") - .HasColumnType("datetime2"); - - b.Property("LastUpdatedBy") - .HasColumnType("nvarchar(max)"); - - b.Property("LastUpdatedTime") - .HasColumnType("datetimeoffset"); - - b.Property("StartTime") - .HasColumnType("datetime2"); - - b.Property("TimeFrame") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("TimeSchedules", (string)null); + b.ToTable("Staffs"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => @@ -699,7 +699,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasForeignKey("ApplicationUserID"); b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Building", "Building") - .WithMany("Customers") + .WithMany() .HasForeignKey("BuildingID"); b.Navigation("ApplicationUser"); @@ -728,11 +728,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Order", b => { b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Customer", "Customer") - .WithMany("Order") + .WithMany() .HasForeignKey("CustomerID"); b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.LaundryStore", "LaundryStore") - .WithMany("Orders") + .WithMany() .HasForeignKey("LaundryStoreID"); b.HasOne("Staff", "Staff") @@ -749,7 +749,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.OrderHistory", b => { b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Order", "Order") - .WithMany("OrderHistories") + .WithMany() .HasForeignKey("OrderID"); b.Navigation("Order"); @@ -758,30 +758,24 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Payment", b => { b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Order", "Orders") - .WithMany("Payments") + .WithMany() .HasForeignKey("OrderId"); - b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Transaction", "Transaction") - .WithMany("Payments") - .HasForeignKey("TransactionId"); - b.Navigation("Orders"); - - b.Navigation("Transaction"); }); modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Staff_Trip", b => { b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Building", "Building") - .WithMany("Staff_Trips") + .WithMany() .HasForeignKey("BuildingID"); b.HasOne("Staff", "Staff") - .WithMany("Staff_Trips") + .WithMany() .HasForeignKey("StaffID"); - b.HasOne("TimeSchedule", "TimeSchedule") - .WithMany("Staff_Trip") + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.TimeSchedule", "TimeSchedule") + .WithMany() .HasForeignKey("TimeScheduleID"); b.Navigation("Building"); @@ -793,10 +787,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Transaction", b => { + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Payment", "Payment") + .WithMany() + .HasForeignKey("PaymentID"); + b.HasOne("SWD_Laundry_Backend.Contract.Repository.Entity.Wallet", "Wallet") - .WithMany("Transactions") + .WithMany() .HasForeignKey("WalletID"); + b.Navigation("Payment"); + b.Navigation("Wallet"); }); @@ -809,50 +809,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("ApplicationUser"); }); - modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Building", b => - { - b.Navigation("Customers"); - - b.Navigation("Staff_Trips"); - }); - - modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Customer", b => - { - b.Navigation("Order"); - }); - - modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.LaundryStore", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Order", b => - { - b.Navigation("OrderHistories"); - - b.Navigation("Payments"); - }); - - modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Transaction", b => - { - b.Navigation("Payments"); - }); - modelBuilder.Entity("SWD_Laundry_Backend.Contract.Repository.Entity.Wallet", b => { b.Navigation("ApplicationUser"); - - b.Navigation("Transactions"); - }); - - modelBuilder.Entity("Staff", b => - { - b.Navigation("Staff_Trips"); - }); - - modelBuilder.Entity("TimeSchedule", b => - { - b.Navigation("Staff_Trip"); }); #pragma warning restore 612, 618 } diff --git a/src/SWD-Laundry-Backend.Repository/Repository/LaundryStoreRepository.cs b/src/SWD-Laundry-Backend.Repository/Repository/LaundryStoreRepository.cs new file mode 100644 index 0000000..e3a1acb --- /dev/null +++ b/src/SWD-Laundry-Backend.Repository/Repository/LaundryStoreRepository.cs @@ -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(ILaundryStoreRepository))] +public class LaundryStoreRepository : Repository, ILaundryStoreRepository +{ + public LaundryStoreRepository(AppDbContext dbContext, ICacheLayer cachelayer) : base(dbContext, cachelayer) + { + } +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Repository/Repository/StaffTripRepository.cs b/src/SWD-Laundry-Backend.Repository/Repository/StaffTripRepository.cs new file mode 100644 index 0000000..4764e7b --- /dev/null +++ b/src/SWD-Laundry-Backend.Repository/Repository/StaffTripRepository.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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(IStaffTripRepository))] +public class StaffTripRepository : Repository, IStaffTripRepository +{ + public StaffTripRepository(AppDbContext dbContext, ICacheLayer cacheLayer) : base(dbContext, cacheLayer) + { + } +} diff --git a/src/SWD-Laundry-Backend.Repository/Repository/TimeScheduleRepository.cs b/src/SWD-Laundry-Backend.Repository/Repository/TimeScheduleRepository.cs index 338aa6f..4f2a379 100644 --- a/src/SWD-Laundry-Backend.Repository/Repository/TimeScheduleRepository.cs +++ b/src/SWD-Laundry-Backend.Repository/Repository/TimeScheduleRepository.cs @@ -1,5 +1,9 @@ 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; diff --git a/src/SWD-Laundry-Backend.Repository/Repository/TransactionRepository.cs b/src/SWD-Laundry-Backend.Repository/Repository/TransactionRepository.cs new file mode 100644 index 0000000..d8c9b5b --- /dev/null +++ b/src/SWD-Laundry-Backend.Repository/Repository/TransactionRepository.cs @@ -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(ITransactionRepository))] +public class TransactionRepository : Repository, ITransactionRepository +{ + public TransactionRepository(AppDbContext dbContext, ICacheLayer cachelayer) : base(dbContext, cachelayer) + { + } +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Repository/Repository/WalletRepository.cs b/src/SWD-Laundry-Backend.Repository/Repository/WalletRepository.cs new file mode 100644 index 0000000..32c5288 --- /dev/null +++ b/src/SWD-Laundry-Backend.Repository/Repository/WalletRepository.cs @@ -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(IWalletRepository))] +public class WalletRepository : Repository, IWalletRepository +{ + public WalletRepository(AppDbContext dbContext, ICacheLayer cachelayer) : base(dbContext, cachelayer) + { + } +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Service/SWD-Laundry-Backend.Service.csproj b/src/SWD-Laundry-Backend.Service/SWD-Laundry-Backend.Service.csproj index a17de4e..27da04e 100644 --- a/src/SWD-Laundry-Backend.Service/SWD-Laundry-Backend.Service.csproj +++ b/src/SWD-Laundry-Backend.Service/SWD-Laundry-Backend.Service.csproj @@ -9,6 +9,7 @@ + diff --git a/src/SWD-Laundry-Backend.Service/Services/BuildingService.cs b/src/SWD-Laundry-Backend.Service/Services/BuildingService.cs index fcae9ba..2af976c 100644 --- a/src/SWD-Laundry-Backend.Service/Services/BuildingService.cs +++ b/src/SWD-Laundry-Backend.Service/Services/BuildingService.cs @@ -7,6 +7,7 @@ using SWD_Laundry_Backend.Core.Models; namespace SWD_Laundry_Backend.Service.Services; + [ScopedDependency(ServiceType = typeof(IBuidingService))] public class BuildingService : Base_Service.Service, IBuidingService { diff --git a/src/SWD-Laundry-Backend.Service/Services/LaundryStoreService.cs b/src/SWD-Laundry-Backend.Service/Services/LaundryStoreService.cs new file mode 100644 index 0000000..5890991 --- /dev/null +++ b/src/SWD-Laundry-Backend.Service/Services/LaundryStoreService.cs @@ -0,0 +1,61 @@ +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(ILaundryStoreService))] +public class LaundryStoreService : Base_Service.Service, ILaundryStoreService +{ + private readonly ILaundryStoreRepository _repository; + private readonly IMapper _mapper; + + public LaundryStoreService(ILaundryStoreRepository repository, IMapper mapper) + { + _repository = repository; + _mapper = mapper; + } + + public async Task CreateAsync(LaundryStoreModel model, CancellationToken cancellationToken = default) + { + var query = await _repository.AddAsync(_mapper.Map(model), cancellationToken); + var objectId = query.Id; + return objectId; + } + + public Task DeleteAsync(string id, CancellationToken cancellationToken = default) + { + throw new NotImplementedException(); + } + + public async Task> GetAllAsync(CancellationToken cancellationToken = default) + { + var list = await _repository.GetAsync(cancellationToken: cancellationToken, includes: x => x.ApplicationUser); + return await list.ToListAsync(cancellationToken); + } + + public async Task GetByIdAsync(string id, CancellationToken cancellationToken = default) + { + var query = await _repository.GetAsync(c => c.Id == id, cancellationToken, x => x.ApplicationUser); + var obj = await query.FirstOrDefaultAsync(); + return obj; + } + + public async Task UpdateAsync(string id, LaundryStoreModel model, CancellationToken cancellationToken = default) + { + var numberOfRows = await _repository.UpdateAsync(x => x.Id == id, + x => x + .SetProperty(x => x.StartTime, model.StartTime) + .SetProperty(x => x.EndTime, model.EndTime) + .SetProperty(x => x.Address, model.Address) + .SetProperty(x => x.Status, model.Status) + , cancellationToken); + + return numberOfRows; + } +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Service/Services/StaffTripService.cs b/src/SWD-Laundry-Backend.Service/Services/StaffTripService.cs new file mode 100644 index 0000000..0e68081 --- /dev/null +++ b/src/SWD-Laundry-Backend.Service/Services/StaffTripService.cs @@ -0,0 +1,76 @@ +using System.Linq.Expressions; +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(IStaffTripService))] +public class StaffTripService : Base_Service.Service, IStaffTripService +{ + private readonly Expression>[]? items = + { + p => p.Staff, + p => p.Building, + p => p.TimeSchedule + }; + + private readonly IStaffTripRepository _repository; + private readonly IMapper _mapper; + + public StaffTripService(IStaffTripRepository staffTripRepository, IMapper mapper) + { + _repository = staffTripRepository; + _mapper = mapper; + } + + public async Task CreateAsync(StaffTripModel model, CancellationToken cancellationToken = default) + { + var query = await _repository.AddAsync(_mapper.Map(model), cancellationToken); + var objectId = query.Id; + return objectId; + } + + public async Task DeleteAsync(string id, CancellationToken cancellationToken = default) + { + var numberOfRows = await _repository.DeleteAsync(x => x.Id == id, cancellationToken: cancellationToken); + return numberOfRows; + } + + public async Task> GetAllAsync(CancellationToken cancellationToken = default) + { + var list = await _repository.GetAsync( + cancellationToken: cancellationToken, + includes: items); + return await list.ToListAsync(cancellationToken); + } + + public async Task GetByIdAsync(string id, CancellationToken cancellationToken = default) + { + var query = await _repository.GetAsync( + c => c.Id == id, + cancellationToken: cancellationToken, + includes: items); + + var obj = await query.FirstOrDefaultAsync(cancellationToken: cancellationToken); + return obj; + } + + public async Task UpdateAsync(string id, StaffTripModel model, CancellationToken cancellationToken = default) + { + var numberOfRows = await _repository.UpdateAsync(x => x.Id == id, + x => x + .SetProperty(x => x.TripCollect, model.TripCollect) + .SetProperty(x => x.TripType, model.TripType) + .SetProperty(x => x.TimeScheduleID, model.TimeScheduleID) + .SetProperty(x => x.BuildingID, model.BuildingID) + .SetProperty(x => x.StaffID, model.StaffID) + , cancellationToken); + + return numberOfRows; + } +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend.Service/Services/TimeScheduleService.cs b/src/SWD-Laundry-Backend.Service/Services/TimeScheduleService.cs index a1d9c15..46fee3b 100644 --- a/src/SWD-Laundry-Backend.Service/Services/TimeScheduleService.cs +++ b/src/SWD-Laundry-Backend.Service/Services/TimeScheduleService.cs @@ -1,8 +1,7 @@ using AutoMapper; -using Invedia.Core.ObjUtils; 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; @@ -10,7 +9,7 @@ namespace SWD_Laundry_Backend.Service.Services; [ScopedDependency(ServiceType = typeof(ITimeScheduleService))] -internal class TimeScheduleService : Base_Service.Service, ITimeScheduleService +public class TimeScheduleService : Base_Service.Service, ITimeScheduleService { private readonly ITimeScheduleRepository _repository; private readonly IMapper _mapper; @@ -36,8 +35,8 @@ public async Task DeleteAsync(string id, CancellationToken cancellationToke public async Task> GetAllAsync(CancellationToken cancellationToken = default) { - var timescheduleList = await _repository.GetAsync( cancellationToken: cancellationToken); - return await timescheduleList.ToListAsync(cancellationToken); + var list = await _repository.GetAsync(cancellationToken: cancellationToken); + return await list.ToListAsync(cancellationToken); } public async Task GetByIdAsync(string id, CancellationToken cancellationToken = default) @@ -55,7 +54,7 @@ public async Task UpdateAsync(string id, TimeScheduleModel model, Cancellat .SetProperty(x => x.EndTime, model.EndTime) .SetProperty(x => x.DayOfWeek, model.DayOfWeek) .SetProperty(x => x.TimeFrame, model.TimeFrame) - ,cancellationToken); + , cancellationToken); return numberOfRows; } diff --git a/src/SWD-Laundry-Backend.Service/Services/TransactionService.cs b/src/SWD-Laundry-Backend.Service/Services/TransactionService.cs new file mode 100644 index 0000000..663f39f --- /dev/null +++ b/src/SWD-Laundry-Backend.Service/Services/TransactionService.cs @@ -0,0 +1,55 @@ +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(ITransactionService))] +public class TransactionService : Base_Service.Service, ITransactionService +{ + private readonly ITransactionRepository _repository; + private readonly IMapper _mapper; + + public TransactionService(ITransactionRepository repository, IMapper mapper) + { + _repository = repository; + _mapper = mapper; + } + + public async Task CreateAsync(TransactionModel model, CancellationToken cancellationToken = default) + { + var query = await _repository.AddAsync(_mapper.Map(model), cancellationToken); + var objectId = query.Id; + return objectId; + } + + public async Task> GetAllAsync(CancellationToken cancellationToken = default) + { + var list = await _repository.GetAsync(cancellationToken: cancellationToken); + return await list.ToListAsync(cancellationToken); + } + + public async Task GetByIdAsync(string id, CancellationToken cancellationToken = default) + { + var query = await _repository.GetAsync(c => c.Id == id, cancellationToken); + var obj = await query.FirstOrDefaultAsync(); + return obj; + } + + public async Task UpdateAsync(string id, TransactionModel model, CancellationToken cancellationToken = default) + { + var numberOfRows = await _repository.UpdateAsync(x => x.Id == id, + x => x + .SetProperty(x => x.Amount, model.Amount) + .SetProperty(x => x.TransactionType, model.TransactionType) + .SetProperty(x => x.PaymentMethod, model.PaymentMethod) + .SetProperty(x => x.Description, model.Description) + , cancellationToken); + + return numberOfRows; + } +} diff --git a/src/SWD-Laundry-Backend.Service/Services/WalletService.cs b/src/SWD-Laundry-Backend.Service/Services/WalletService.cs new file mode 100644 index 0000000..5056252 --- /dev/null +++ b/src/SWD-Laundry-Backend.Service/Services/WalletService.cs @@ -0,0 +1,58 @@ +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(IWalletService))] +public class WalletService : Base_Service.Service, IWalletService +{ + private readonly IWalletRepository _repository; + private readonly IMapper _mapper; + + public WalletService(IWalletRepository repository, IMapper mapper) + { + _repository = repository; + _mapper = mapper; + } + + public async Task CreateAsync(WalletModel model, CancellationToken cancellationToken = default) + { + var query = await _repository.AddAsync(_mapper.Map(model), cancellationToken); + var objectId = query.Id; + return objectId; + } + + public async Task DeleteAsync(string id, CancellationToken cancellationToken = default) + { + int i = await _repository.DeleteAsync(x => x.Id == id, cancellationToken: cancellationToken); + return i; + } + + public async Task> GetAllAsync(CancellationToken cancellationToken = default) + { + var list = await _repository.GetAsync(cancellationToken: cancellationToken); + return await list.ToListAsync(cancellationToken); + } + + public async Task GetByIdAsync(string id, CancellationToken cancellationToken = default) + { + var query = await _repository.GetAsync(c => c.Id == id, cancellationToken); + var obj = await query.FirstOrDefaultAsync(); + return obj; + } + + public async Task UpdateAsync(string id, WalletModel model, CancellationToken cancellationToken = default) + { + var numberOfRows = await _repository.UpdateAsync(x => x.Id == id, + x => x + .SetProperty(x => x.Balance, model.Balance) + , cancellationToken); + + return numberOfRows; + } +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend/Controllers/BuildingController.cs b/src/SWD-Laundry-Backend/Controllers/BuildingController.cs index a1b3184..ba787ee 100644 --- a/src/SWD-Laundry-Backend/Controllers/BuildingController.cs +++ b/src/SWD-Laundry-Backend/Controllers/BuildingController.cs @@ -4,6 +4,7 @@ using SWD_Laundry_Backend.Core.Models; namespace SWD_Laundry_Backend.Controllers; + [ApiController] public class BuildingController : ApiControllerBase { @@ -29,7 +30,6 @@ public async Task GetAll() { return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); } - } [HttpGet("{id}")] @@ -69,7 +69,6 @@ public async Task Create(BuildingModel model) { return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); } - } [HttpPut("{id}")] @@ -82,7 +81,7 @@ public async Task Update(string id, BuildingModel model) try { var result = await _buildingService.UpdateAsync(id, model); - if(result == 0) + if (result == 0) { return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); } @@ -92,7 +91,6 @@ public async Task Update(string id, BuildingModel model) { return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); } - } [HttpDelete("{id}")] @@ -116,5 +114,4 @@ public async Task Delete(string id) return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); } } - -} +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend/Controllers/LaundryStoreController.cs b/src/SWD-Laundry-Backend/Controllers/LaundryStoreController.cs new file mode 100644 index 0000000..1ed3bf3 --- /dev/null +++ b/src/SWD-Laundry-Backend/Controllers/LaundryStoreController.cs @@ -0,0 +1,119 @@ +using Microsoft.AspNetCore.Mvc; +using SWD_Laundry_Backend.Contract.Repository.Entity; +using SWD_Laundry_Backend.Contract.Service.Interface; +using SWD_Laundry_Backend.Core.Models; + +namespace SWD_Laundry_Backend.Controllers; + +[ApiController] +public class LaundryStoreController : ApiControllerBase +{ + private readonly ILaundryStoreService _service; + + public LaundryStoreController(ILaundryStoreService service) + { + _service = service; + } + + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task ViewLaundryStoreList() + { + try + { + var result = await _service.GetAllAsync(); + return Ok(new BaseResponseModel?>(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task ViewLaundryStoreInformation(string id) + { + try + { + var result = await _service.GetByIdAsync(id); + if (result == null) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpPost] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Create(LaundryStoreModel model) + { + try + { + var result = await _service.CreateAsync(model); + return Ok(new BaseResponseModel + (StatusCodes.Status201Created, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel + (StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpPut("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task EditLaundryStoreInformation(string id, LaundryStoreModel model) + { + try + { + var result = await _service.UpdateAsync(id, model); + if (result == 0) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpDelete("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Delete(string id) + { + try + { + var result = await _service.DeleteAsync(id); + if (result == 0) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } +} diff --git a/src/SWD-Laundry-Backend/Controllers/StaffTripController.cs b/src/SWD-Laundry-Backend/Controllers/StaffTripController.cs new file mode 100644 index 0000000..85e6316 --- /dev/null +++ b/src/SWD-Laundry-Backend/Controllers/StaffTripController.cs @@ -0,0 +1,119 @@ +using Microsoft.AspNetCore.Mvc; +using SWD_Laundry_Backend.Contract.Repository.Entity; +using SWD_Laundry_Backend.Contract.Service.Interface; +using SWD_Laundry_Backend.Core.Models; + +namespace SWD_Laundry_Backend.Controllers; + +[ApiController] +public class StaffTripController : ApiControllerBase +{ + private readonly IStaffTripService _service; + + public StaffTripController(IStaffTripService service) + { + _service = service; + } + + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task GetAll() + { + try + { + var result = await _service.GetAllAsync(); + return Ok(new BaseResponseModel?>(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task GetById(string id) + { + try + { + var result = await _service.GetByIdAsync(id); + if (result == null) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpPost] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Create(StaffTripModel model) + { + try + { + var result = await _service.CreateAsync(model); + return Ok(new BaseResponseModel + (StatusCodes.Status201Created, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel + (StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpPut("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Update(string id, StaffTripModel model) + { + try + { + var result = await _service.UpdateAsync(id, model); + if (result == 0) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpDelete("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Delete(string id) + { + try + { + var result = await _service.DeleteAsync(id); + if (result == 0) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } +} diff --git a/src/SWD-Laundry-Backend/Controllers/TimeScheduleController.cs b/src/SWD-Laundry-Backend/Controllers/TimeScheduleController.cs index 574b050..3c9ef5c 100644 --- a/src/SWD-Laundry-Backend/Controllers/TimeScheduleController.cs +++ b/src/SWD-Laundry-Backend/Controllers/TimeScheduleController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using SWD_Laundry_Backend.Contract.Repository.Entity; using SWD_Laundry_Backend.Contract.Service.Interface; using SWD_Laundry_Backend.Core.Models; @@ -71,4 +72,48 @@ public async Task Create(TimeScheduleModel model) (StatusCodes.Status500InternalServerError, e.Message)); } } + + [HttpPut("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Update(string id, TimeScheduleModel model) + { + try + { + var result = await _service.UpdateAsync(id, model); + if (result == 0) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpDelete("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Delete(string id) + { + try + { + var result = await _service.DeleteAsync(id); + if (result == 0) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } } \ No newline at end of file diff --git a/src/SWD-Laundry-Backend/Controllers/WalletController.cs b/src/SWD-Laundry-Backend/Controllers/WalletController.cs new file mode 100644 index 0000000..9dec75a --- /dev/null +++ b/src/SWD-Laundry-Backend/Controllers/WalletController.cs @@ -0,0 +1,119 @@ +using Microsoft.AspNetCore.Mvc; +using SWD_Laundry_Backend.Contract.Repository.Entity; +using SWD_Laundry_Backend.Contract.Service.Interface; +using SWD_Laundry_Backend.Core.Models; + +namespace SWD_Laundry_Backend.Controllers; + +[ApiController] +public class WalletController : ApiControllerBase +{ + private readonly IWalletService _service; + + public WalletController(IWalletService service) + { + _service = service; + } + + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task GetAll() + { + try + { + var result = await _service.GetAllAsync(); + return Ok(new BaseResponseModel?>(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task GetById(string id) + { + try + { + var result = await _service.GetByIdAsync(id); + if (result == null) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpPost] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Create(WalletModel model) + { + try + { + var result = await _service.CreateAsync(model); + return Ok(new BaseResponseModel + (StatusCodes.Status201Created, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel + (StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpPut("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Update(string id, WalletModel model) + { + try + { + var result = await _service.UpdateAsync(id, model ); + if (result == 0) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } + + [HttpDelete("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesDefaultResponseType] + public async Task Delete(string id) + { + try + { + var result = await _service.DeleteAsync(id); + if (result == 0) + { + return NotFound(new BaseResponseModel(StatusCodes.Status404NotFound, "Not Found")); + } + return Ok(new BaseResponseModel(StatusCodes.Status200OK, data: result)); + } + catch (Exception e) + { + return BadRequest(new BaseResponseModel(StatusCodes.Status500InternalServerError, e.Message)); + } + } +} diff --git a/src/SWD-Laundry-Backend/Controllers/WeatherForecastController.cs b/src/SWD-Laundry-Backend/Controllers/WeatherForecastController.cs deleted file mode 100644 index a37e97d..0000000 --- a/src/SWD-Laundry-Backend/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace SWD_Laundry_Backend.Controllers; -[ApiController] -public class WeatherForecastController : ApiControllerBase -{ - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } -} - diff --git a/src/SWD-Laundry-Backend/Extensions/AutoMapperExtension.cs b/src/SWD-Laundry-Backend/Extensions/AutoMapperExtension.cs index 0b9ca96..4d775ee 100644 --- a/src/SWD-Laundry-Backend/Extensions/AutoMapperExtension.cs +++ b/src/SWD-Laundry-Backend/Extensions/AutoMapperExtension.cs @@ -2,27 +2,21 @@ namespace SWD_Laundry_Backend.Extensions; - public static class AutoMapperExtension { public static IServiceCollection AddAutoMapperServices(this IServiceCollection services) { - services.AddAutoMapper(cfg => - { + services.AddAutoMapper(cfg => + { cfg.AddProfile(); - + cfg.AddProfile(); cfg.AddProfile(); cfg.AddProfile(); cfg.AddProfile(); cfg.AddProfile(); cfg.AddProfile(); cfg.AddProfile(); - - cfg.AddProfile(); }); return services; } -} - - - +} \ No newline at end of file diff --git a/src/SWD-Laundry-Backend/Program.cs b/src/SWD-Laundry-Backend/Program.cs index 00cdfd9..3b63476 100644 --- a/src/SWD-Laundry-Backend/Program.cs +++ b/src/SWD-Laundry-Backend/Program.cs @@ -1,3 +1,5 @@ +using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using Invedia.DI; using Microsoft.AspNetCore.Authentication.JwtBearer; @@ -6,12 +8,18 @@ using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; using Serilog; using SWD_Laundry_Backend.Contract.Repository.Entity.IdentityModels; using SWD_Laundry_Backend.Core.Config; +using SWD_Laundry_Backend.Core.Enum; +using SWD_Laundry_Backend.Core.Utils; using SWD_Laundry_Backend.Extensions; using SWD_Laundry_Backend.Repository.Infrastructure; + namespace SWD_Laundry_Backend; public class Program @@ -39,6 +47,9 @@ public static void Main(string[] args) builder.Services.AddControllers(options => { options.Conventions.Add(new RouteTokenTransformerConvention(new SlugifyParameterTransformer())); + }).AddNewtonsoftJson(options => + { + options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); diff --git a/src/SWD-Laundry-Backend/WeatherForecast.cs b/src/SWD-Laundry-Backend/WeatherForecast.cs deleted file mode 100644 index 205d2ab..0000000 --- a/src/SWD-Laundry-Backend/WeatherForecast.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace SWD_Laundry_Backend; - -public class WeatherForecast -{ - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } -}