Skip to content

Commit

Permalink
Merge pull request #41 from SWD392-Domus/feature/quotations-management
Browse files Browse the repository at this point in the history
Feature/quotations management
  • Loading branch information
duykasama authored Feb 14, 2024
2 parents fff38ab + 25a4cfc commit 7159eff
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Articles;

public class DtoArticle
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Articles;

public class DtoArticleCategory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Articles;

public class DtoArticleImage
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Articles;

public class DtoArticleWithoutCategory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Products;

public class DtoProduct
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Products;

public class DtoProductAttributeValue
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Products;

public class DtoProductCategory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Products;

public class DtoProductDetail
{
Expand Down
16 changes: 16 additions & 0 deletions Domus.Domain/Dtos/Products/DtoProductDetailQuotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Domus.Domain.Dtos.Products;

public class DtoProductDetailQuotation
{
public string ProductName { get; set; } = null!;

public double Price { get; set; }

public string MonetaryUnit { get; set; } = null!;

public double Quantity { get; set; }

public string QuantityType { get; set; } = null!;

public DtoProductDetail Detail { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Products;

public class DtoProductImage
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Products;

public class DtoProductWithoutCategory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Products;

public class DtoProductWithoutCategoryAndDetails
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Quotations;

public class DtoNegotiationMessage
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Quotations;

public class DtoQuotation
{
Expand Down
23 changes: 23 additions & 0 deletions Domus.Domain/Dtos/Quotations/DtoQuotationFullDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Text.Json.Serialization;
using Domus.Domain.Dtos.Products;

namespace Domus.Domain.Dtos.Quotations;

public class DtoQuotationFullDetails
{
public string Id { get; set; } = null!;

public DtoDomusUser Customer { get; set; } = null!;

public DtoDomusUser Staff { get; set; } = null!;

public string Status { get; set; } = null!;

public DateTime? ExpireAt { get; set; }

[JsonPropertyName("products")]
public ICollection<DtoProductDetailQuotation> ProductDetailQuotations { get; set; } = new List<DtoProductDetailQuotation>();

[JsonPropertyName("negotiationLog")]
public DtoQuotationNegotiationLog QuotationNegotiationLog { get; set; } = null!;
}
15 changes: 15 additions & 0 deletions Domus.Domain/Dtos/Quotations/DtoQuotationNegotationLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;

namespace Domus.Domain.Dtos.Quotations;

public class DtoQuotationNegotiationLog
{
public bool? IsClosed { get; set; }

public DateTime StartAt { get; set; }

public DateTime? CloseAt { get; set; }

[JsonPropertyName("messages")]
public ICollection<DtoNegotiationMessage> NegotiationMessages { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Domus.Domain.Dtos;
namespace Domus.Domain.Dtos.Quotations;

public class DtoQuotationNegotiationLogWithoutMessages
{
Expand Down
7 changes: 7 additions & 0 deletions Domus.Service/AutoMappings/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using AutoMapper;
using Domus.Domain.Dtos;
using Domus.Domain.Dtos.Articles;
using Domus.Domain.Dtos.Products;
using Domus.Domain.Dtos.Quotations;
using Domus.Domain.Entities;
using Domus.Service.Models.Requests.Articles;
using Domus.Service.Models.Requests.Authentication;
Expand Down Expand Up @@ -53,6 +56,8 @@ private static void CreateProductMaps(IMapperConfigurationExpression mapper)
mapper.CreateMap<Product, DtoProductWithoutCategoryAndDetails>();
mapper.CreateMap<CreateProductRequest, Product>();
mapper.CreateMap<ProductCategory, DtoProductCategory>();
mapper.CreateMap<ProductDetailQuotation, DtoProductDetailQuotation>()
.ForMember(dest => dest.ProductName, opt => opt.MapFrom(src => src.ProductDetail.Product.ProductName));
mapper.CreateMap<ProductDetail, DtoProductDetail>()
.ForMember(dest => dest.DisplayPrice, opt => opt.MapFrom(src => Math.Round(src.DisplayPrice, 2)))
.ForMember(dest => dest.ProductAttributeValues, opt => opt.MapFrom((src) => src.ProductAttributeValues.Select(pav => new DtoProductAttributeValue { Name = pav.ProductAttribute.AttributeName, Value = pav.Value, ValueType = pav.ValueType })));
Expand All @@ -74,6 +79,8 @@ private static void CreateQuotationMaps(IMapperConfigurationExpression mapper)
mapper.CreateMap<Quotation, DtoQuotation>()
.ForMember(dest => dest.CustomerName, opt => opt.MapFrom(src => src.Customer.UserName))
.ForMember(dest => dest.StaffName, opt => opt.MapFrom(src => src.Staff.UserName));
mapper.CreateMap<Quotation, DtoQuotationFullDetails>();
mapper.CreateMap<QuotationNegotiationLog, DtoQuotationNegotiationLog>();
mapper.CreateMap<QuotationNegotiationLog, DtoQuotationNegotiationLogWithoutMessages>();
mapper.CreateMap<CreateNegotiationMessageRequest, NegotiationMessage>()
.ForMember(dest => dest.SentAt, opt => opt.MapFrom(src => DateTime.Now));
Expand Down
2 changes: 1 addition & 1 deletion Domus.Service/Implementations/ArticleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using AutoMapper.QueryableExtensions;
using Domus.Common.Helpers;
using Domus.DAL.Interfaces;
using Domus.Domain.Dtos;
using Domus.Domain.Dtos.Articles;
using Domus.Domain.Entities;
using Domus.Service.Exceptions;
using Domus.Service.Interfaces;
Expand Down
2 changes: 1 addition & 1 deletion Domus.Service/Implementations/ProductDetailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using AutoMapper.QueryableExtensions;
using Domus.Common.Helpers;
using Domus.DAL.Interfaces;
using Domus.Domain.Dtos;
using Domus.Domain.Dtos.Products;
using Domus.Domain.Entities;
using Domus.Service.Exceptions;
using Domus.Service.Interfaces;
Expand Down
2 changes: 1 addition & 1 deletion Domus.Service/Implementations/ProductService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Domus.Common.Exceptions;
using Domus.Common.Helpers;
using Domus.DAL.Interfaces;
using Domus.Domain.Dtos;
using Domus.Domain.Dtos.Products;
using Domus.Domain.Entities;
using Domus.Service.Exceptions;
using Domus.Service.Interfaces;
Expand Down
10 changes: 6 additions & 4 deletions Domus.Service/Implementations/QuotationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Domus.Common.Helpers;
using Domus.DAL.Interfaces;
using Domus.Domain.Dtos;
using Domus.Domain.Dtos.Quotations;
using Domus.Domain.Entities;
using Domus.Service.Constants;
using Domus.Service.Exceptions;
Expand Down Expand Up @@ -177,11 +178,12 @@ public async Task<ServiceActionResult> GetPaginatedQuotations(BasePaginatedReque

public async Task<ServiceActionResult> GetQuotationById(Guid id)
{
var quotation = await _quotationRepository.GetAsync(q => q.Id == id);
if (quotation == null)
throw new QuotationNotFoundException();
var quotation = (await _quotationRepository.GetAllAsync())
.Where(q => q.Id == id)
.ProjectTo<DtoQuotationFullDetails>(_mapper.ConfigurationProvider)
.FirstOrDefault() ?? throw new QuotationNotFoundException();

return new ServiceActionResult(true) { Data = _mapper.Map<DtoQuotation>(quotation) };
return new ServiceActionResult(true) { Data = quotation };
}

public async Task<ServiceActionResult> UpdateQuotation(UpdateQuotationRequest request, Guid id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Domus.Domain.Dtos;
using Domus.Domain.Dtos.Articles;

namespace Domus.Service.Models.Requests.Articles;

Expand Down

0 comments on commit 7159eff

Please sign in to comment.