-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from OlimjonovOzodbek/master
payment
- Loading branch information
Showing
14 changed files
with
747 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using UrphaCapital.Application.UseCases.Admins.Commands; | ||
using UrphaCapital.Application.UseCases.Admins.Queries; | ||
using UrphaCapital.Application.UseCases.Payments.Commands; | ||
using UrphaCapital.Application.UseCases.Payments.Queries; | ||
using UrphaCapital.Application.ViewModels; | ||
using UrphaCapital.Domain.Entities; | ||
using UrphaCapital.Domain.Entities.Auth; | ||
|
||
namespace UrphaCapital.API.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class PaymentController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public PaymentController(IMediator mediator) | ||
{ | ||
_mediator = mediator; | ||
} | ||
|
||
[HttpPost] | ||
public async Task<ResponseModel> PostPayment([FromBody] CreatePaymentCommand command, CancellationToken cancellation) | ||
{ | ||
var response = await _mediator.Send(command, cancellation); | ||
|
||
return response; | ||
} | ||
[HttpGet("{index}/{count}")] | ||
public async Task<IEnumerable<Payment>> GetPayments(int index, int count, CancellationToken cancellation) | ||
{ | ||
var query = new GetAllPaymentsQuery() | ||
{ | ||
Index = index, | ||
Count = count | ||
}; | ||
|
||
var response = await _mediator.Send(query, cancellation); | ||
|
||
return response; | ||
} | ||
} | ||
} |
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
Binary file added
BIN
+10 KB
UrphaCapital.API/wwwroot/CoursesPictures/b517aa80-242b-49f4-9f4e-81baa681e56a.jfif
Binary file not shown.
Binary file added
BIN
+10 KB
UrphaCapital.API/wwwroot/MentorsPictures/667d9b39-e7f1-4579-bf16-519e4a9c56b7.jfif
Binary file not shown.
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
18 changes: 18 additions & 0 deletions
18
UrphaCapital.Application/UseCases/Payments/Commands/CreatePaymentCommand.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,18 @@ | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UrphaCapital.Application.ViewModels; | ||
|
||
namespace UrphaCapital.Application.UseCases.Payments.Commands | ||
{ | ||
public class CreatePaymentCommand: IRequest<ResponseModel> | ||
{ | ||
public long StudentId { get; set; } | ||
public Guid CourseId { get; set; } | ||
public decimal Amount { get; set; } | ||
public string PaymentStatus { get; set; } | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
UrphaCapital.Application/UseCases/Payments/Handlers/CreatePaymentCommandHandler.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,45 @@ | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UrphaCapital.Application.Abstractions; | ||
using UrphaCapital.Application.UseCases.Payments.Commands; | ||
using UrphaCapital.Application.ViewModels; | ||
using UrphaCapital.Domain.Entities; | ||
using UrphaCapital.Domain.Entities.Auth; | ||
|
||
namespace UrphaCapital.Application.UseCases.Payments.Handlers | ||
{ | ||
public class CreatePaymentCommandHandler : IRequestHandler<CreatePaymentCommand, ResponseModel> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
|
||
public CreatePaymentCommandHandler(IApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<ResponseModel> Handle(CreatePaymentCommand request, CancellationToken cancellationToken) | ||
{ | ||
var payment = new Payment() | ||
{ | ||
StudentId = request.StudentId, | ||
CourseId = request.CourseId, | ||
Amount = request.Amount, | ||
PaymentStatus = request.PaymentStatus, | ||
}; | ||
|
||
await _context.Paymentss.AddAsync(payment); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
|
||
return new ResponseModel() | ||
{ | ||
Message = "Created", | ||
StatusCode = 200, | ||
IsSuccess = true | ||
}; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
UrphaCapital.Application/UseCases/Payments/Queries/GetAllPaymentsQuery.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,16 @@ | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UrphaCapital.Domain.Entities; | ||
|
||
namespace UrphaCapital.Application.UseCases.Payments.Queries | ||
{ | ||
public class GetAllPaymentsQuery: IRequest<IEnumerable<Payment>> | ||
{ | ||
public int Index { get; set; } | ||
public int Count { get; set; } | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
UrphaCapital.Application/UseCases/Payments/QueriesHandler/GetAllPaymentsQueryHandler.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,29 @@ | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UrphaCapital.Application.Abstractions; | ||
using UrphaCapital.Application.UseCases.Payments.Queries; | ||
using UrphaCapital.Domain.Entities; | ||
|
||
namespace UrphaCapital.Application.UseCases.Payments.QueriesHandler | ||
{ | ||
public class GetAllPaymentsQueryHandler : IRequestHandler<GetAllPaymentsQuery, IEnumerable<Payment>> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
|
||
public GetAllPaymentsQueryHandler(IApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<IEnumerable<Payment>> Handle(GetAllPaymentsQuery request, CancellationToken cancellationToken) | ||
{ | ||
return await _context.Paymentss.ToListAsync(cancellationToken); | ||
} | ||
} | ||
} |
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.