Skip to content

Commit a4f1e15

Browse files
committed
Add DPD to list of available couriers - part 2
1 parent 93e62dd commit a4f1e15

54 files changed

Lines changed: 2339 additions & 177 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Ecommerce/src/Bootstrapper/Ecommerce.Bootstrapper/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"Format": "A4",
5858
"OutputType": "BIC3",
5959
"Variant": "Standard",
60-
"OrganizationFID": "1495",
60+
"OrganizationFID": 1495,
6161
"Content": "Goods"
6262
},
6363
"Mail": {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Asp.Versioning;
2+
using Ecommerce.Modules.Carts.Core.DTO;
3+
using Ecommerce.Modules.Carts.Core.Services;
4+
using Ecommerce.Shared.Abstractions.Api;
5+
using Microsoft.AspNetCore.Authorization;
6+
using Microsoft.AspNetCore.Http;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Swashbuckle.AspNetCore.Annotations;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
using System.Text;
13+
using System.Threading.Tasks;
14+
15+
namespace Ecommerce.Modules.Carts.Api.Controllers
16+
{
17+
[Authorize(Roles = "Admin, Manager, Employee")]
18+
[ApiVersion(1)]
19+
internal class DeliveryServiceController : BaseController
20+
{
21+
private readonly IDeliveryServiceService _deliveryServiceService;
22+
23+
public DeliveryServiceController(IDeliveryServiceService deliveryServiceService)
24+
{
25+
_deliveryServiceService = deliveryServiceService;
26+
}
27+
28+
[AllowAnonymous]
29+
[SwaggerOperation("Gets available delivery services")]
30+
[SwaggerResponse(StatusCodes.Status200OK, "Returns available delivery services.", typeof(ApiResponse<IEnumerable<DeliveryServiceDto>>))]
31+
[SwaggerResponse(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
32+
[SwaggerResponse(StatusCodes.Status403Forbidden, "Access is forbidden for this user")]
33+
[SwaggerResponse(StatusCodes.Status401Unauthorized, "User not authorized")]
34+
[HttpGet("available")]
35+
public async Task<ActionResult<ApiResponse<IEnumerable<DeliveryServiceDto>>>> GetAllAvailableDeliveryServices(CancellationToken cancellationToken)
36+
=> Ok(new ApiResponse<IEnumerable<DeliveryServiceDto>>(System.Net.HttpStatusCode.OK, await _deliveryServiceService.GetAllAsync(true, cancellationToken)));
37+
38+
[SwaggerOperation("Gets delivery services")]
39+
[SwaggerResponse(StatusCodes.Status200OK, "Returns delivery services.", typeof(ApiResponse<IEnumerable<DeliveryServiceDto>>))]
40+
[SwaggerResponse(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
41+
[SwaggerResponse(StatusCodes.Status403Forbidden, "Access is forbidden for this user")]
42+
[SwaggerResponse(StatusCodes.Status401Unauthorized, "User not authorized")]
43+
[HttpGet]
44+
public async Task<ActionResult<ApiResponse<IEnumerable<DeliveryServiceDto>>>> GetAllDeliveryServices(CancellationToken cancellationToken)
45+
=> Ok(new ApiResponse<IEnumerable<DeliveryServiceDto>>(System.Net.HttpStatusCode.OK, await _deliveryServiceService.GetAllAsync(null, cancellationToken)));
46+
47+
[SwaggerOperation("Set delivery service status")]
48+
[SwaggerResponse(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
49+
[SwaggerResponse(StatusCodes.Status403Forbidden, "Access is forbidden for this user")]
50+
[SwaggerResponse(StatusCodes.Status401Unauthorized, "User not authorized")]
51+
[HttpPatch("{deliveryServiceId:int}/active/{isActive:bool}")]
52+
public async Task<ActionResult> SetActiveAsync(int deliveryServiceId, bool isActive, CancellationToken cancellationToken)
53+
{
54+
await _deliveryServiceService.SetActiveAsync(deliveryServiceId, isActive, cancellationToken);
55+
return NoContent();
56+
}
57+
}
58+
}

Ecommerce/src/Modules/Carts/Ecommerce.Modules.Carts.Core/DAL/CartsDbContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal class CartsDbContext : DbContext, ICartsDbContext
2323
public DbSet<Product> Products { get; set; }
2424
public DbSet<Payment> Payments { get; set; }
2525
public DbSet<Discount> Discounts { get; set; }
26-
26+
public DbSet<DeliveryService> DeliveryServices { get; set; }
2727
private const string _schema = "carts";
2828
private readonly TimeProvider _timeProvider;
2929

Ecommerce/src/Modules/Carts/Ecommerce.Modules.Carts.Core/DAL/Configurations/CheckoutCartConfiguration.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public void Configure(EntityTypeBuilder<CheckoutCart> builder)
2121
s.Property(s => s.StreetNumber).IsRequired().HasMaxLength(8);
2222
s.Property(s => s.AparmentNumber).HasMaxLength(8);
2323
s.Property(s => s.Country).IsRequired().HasMaxLength(64);
24+
25+
s.HasOne(s => s.DeliveryService)
26+
.WithMany()
27+
.HasForeignKey(s => s.DeliveryServiceId);
2428
});
2529
builder.OwnsOne(cc => cc.Customer, c =>
2630
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Ecommerce.Modules.Carts.Core.Entities;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Ecommerce.Modules.Carts.Core.DAL.Configurations
11+
{
12+
internal class DeliveryServiceConfiguration : IEntityTypeConfiguration<DeliveryService>
13+
{
14+
public void Configure(EntityTypeBuilder<DeliveryService> builder)
15+
{
16+
builder.HasData(
17+
new DeliveryService(1, Entities.Enums.Courier.InPost, "Kurier InPost", 3),
18+
new DeliveryService(2, Entities.Enums.Courier.DPD, "Kurier DPD", 3.5m)
19+
);
20+
21+
builder.ToTable(ds =>
22+
{
23+
ds.HasCheckConstraint("CK_DeliveryService_Price", "\"Price\" >= 0");
24+
});
25+
}
26+
}
27+
}

Ecommerce/src/Modules/Carts/Ecommerce.Modules.Carts.Core/DAL/ICartsDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public interface ICartsDbContext
2020
DbSet<Product> Products { get; set; }
2121
DbSet<Payment> Payments { get; set; }
2222
DbSet<Discount> Discounts { get; set; }
23+
DbSet<DeliveryService> DeliveryServices { get; set; }
2324
Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default);
2425
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
2526
}

Ecommerce/src/Modules/Carts/Ecommerce.Modules.Carts.Core/DAL/Mappings/MappingExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static ShipmentDto AsDto(this Shipment shipment)
6161
StreetName = shipment.StreetName,
6262
StreetNumber = shipment.StreetNumber,
6363
AparmentNumber = shipment.AparmentNumber,
64-
ShipmentPrice = shipment.Price
64+
ShipmentPrice = shipment.DeliveryService.Price
6565
};
6666
public static CustomerDto AsDto(this Customer customer)
6767
=> new()
@@ -88,5 +88,14 @@ public static PaymentDto AsDto(this Payment payment)
8888
PaymentMethod = payment.PaymentMethod.ToString(),
8989
IsActived = payment.IsActive
9090
};
91+
92+
public static DeliveryServiceDto AsDto(this DeliveryService deliveryService)
93+
=> new()
94+
{
95+
Id = deliveryService.Id,
96+
Name = deliveryService.Name,
97+
Courier = deliveryService.Courier.ToString(),
98+
Price = deliveryService.Price,
99+
};
91100
}
92101
}

0 commit comments

Comments
 (0)