-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New - Ajout d'une property HasProducts aux producteurs pour affiner l…
…a map landing (#10) * New - Ajout d'une property HasProducts aux producteurs pour affiner la map du site landing * Fix - Correction SQL
- Loading branch information
1 parent
562c5dc
commit ad2a7f0
Showing
15 changed files
with
3,777 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Sheaft.Application/Producer/Commands/UpdateProducerAvailabilityCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json; | ||
using Sheaft.Application.Common; | ||
using Sheaft.Application.Common.Handlers; | ||
using Sheaft.Application.Common.Interfaces; | ||
using Sheaft.Application.Common.Interfaces.Services; | ||
using Sheaft.Application.Common.Models; | ||
using Sheaft.Application.Common.Options; | ||
using Sheaft.Application.Legal.Commands; | ||
using Sheaft.Application.Wallet.Commands; | ||
using Sheaft.Domain; | ||
using Sheaft.Domain.Enum; | ||
|
||
namespace Sheaft.Application.Producer.Commands | ||
{ | ||
public class UpdateProducerAvailabilityCommand : Command | ||
{ | ||
[JsonConstructor] | ||
public UpdateProducerAvailabilityCommand(RequestUser requestUser) : base(requestUser) | ||
{ | ||
} | ||
|
||
public Guid ProducerId { get; set; } | ||
} | ||
|
||
public class UpdateProducerAvailabilityCommandHandler : CommandsHandler, | ||
IRequestHandler<UpdateProducerAvailabilityCommand, Result> | ||
{ | ||
public UpdateProducerAvailabilityCommandHandler( | ||
IAppDbContext context, | ||
ISheaftMediatr mediatr, | ||
ILogger<UpdateProducerAvailabilityCommandHandler> logger) | ||
: base(mediatr, context, logger) | ||
{ | ||
} | ||
|
||
public async Task<Result> Handle(UpdateProducerAvailabilityCommand request, CancellationToken token) | ||
{ | ||
var producer = await _context.FindByIdAsync<Domain.Producer>(request.ProducerId, token); | ||
producer.CanDirectSell = await _context.DeliveryModes.AnyAsync( | ||
c => !c.RemovedOn.HasValue && c.Producer.Id == producer.Id && | ||
(c.Kind == DeliveryKind.Collective || c.Kind == DeliveryKind.Farm || | ||
c.Kind == DeliveryKind.Market), token); | ||
|
||
await _context.SaveChangesAsync(token); | ||
return Success(); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
Sheaft.Application/Producer/Commands/UpdateProducerProductsCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json; | ||
using Sheaft.Application.Common; | ||
using Sheaft.Application.Common.Handlers; | ||
using Sheaft.Application.Common.Interfaces; | ||
using Sheaft.Application.Common.Interfaces.Services; | ||
using Sheaft.Application.Common.Models; | ||
using Sheaft.Application.Common.Options; | ||
using Sheaft.Application.Legal.Commands; | ||
using Sheaft.Application.Wallet.Commands; | ||
using Sheaft.Domain; | ||
using Sheaft.Domain.Enum; | ||
|
||
namespace Sheaft.Application.Producer.Commands | ||
{ | ||
public class UpdateProducerProductsCommand : Command | ||
{ | ||
[JsonConstructor] | ||
public UpdateProducerProductsCommand(RequestUser requestUser) : base(requestUser) | ||
{ | ||
} | ||
|
||
public Guid ProducerId { get; set; } | ||
} | ||
|
||
public class UpdateProducerProductsCommandHandler : CommandsHandler, | ||
IRequestHandler<UpdateProducerProductsCommand, Result> | ||
{ | ||
public UpdateProducerProductsCommandHandler( | ||
IAppDbContext context, | ||
ISheaftMediatr mediatr, | ||
ILogger<UpdateProducerProductsCommandHandler> logger) | ||
: base(mediatr, context, logger) | ||
{ | ||
} | ||
|
||
public async Task<Result> Handle(UpdateProducerProductsCommand request, CancellationToken token) | ||
{ | ||
var producer = await _context.FindByIdAsync<Domain.Producer>(request.ProducerId, token); | ||
producer.HasProducts = await _context.Products.AnyAsync(p => p.Producer.Id == producer.Id, token); | ||
|
||
await _context.SaveChangesAsync(token); | ||
return Success(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.