Skip to content

Commit

Permalink
Merge pull request #18 from OlimjonovOzodbek/master
Browse files Browse the repository at this point in the history
payment
  • Loading branch information
OlimjonovOzodbek authored Sep 16, 2024
2 parents 2e28e22 + 1813eae commit 76e800b
Show file tree
Hide file tree
Showing 14 changed files with 747 additions and 3 deletions.
46 changes: 46 additions & 0 deletions UrphaCapital.API/Controllers/PaymentController.cs
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;
}
}
}
2 changes: 2 additions & 0 deletions UrphaCapital.API/UrphaCapital.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
<Folder Include="wwwroot\" />
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties apsettings_1json__JsonSchema="https://alec016.github.io/Custom-Machinery/Json%20Schema/src/main/resources/schemas/custom_machinery_machine.json" /></VisualStudio></ProjectExtensions>

</Project>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IApplicationDbContext
public DbSet<Student> Students { get; set; }
public DbSet<Homeworks> Homeworks { get; set; }
public DbSet<Help> Helps { get; set; }
public DbSet <Payment> Paymentss { get; set; }

ValueTask<int> SaveChangesAsync(CancellationToken cancellationToken = default!);
}
Expand Down
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; }
}
}
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
};
}
}
}
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; }
}
}
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);
}
}
}
2 changes: 1 addition & 1 deletion UrphaCapital.Domain/Entities/Payment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class Payment
public long StudentId { get; set; }
public Guid CourseId { get; set; }
public decimal Amount { get; set; }
public string PaymentStatus { get; set; }

public DateTimeOffset PaymentDate = DateTimeOffset.UtcNow;
public string PaymentStatus { get; set; }
public Student Student { get; set; }
public Course Course { get; set; }
}
Expand Down
Loading

0 comments on commit 76e800b

Please sign in to comment.