Добавил офферы для фронта
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 19s
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 19s
This commit is contained in:
parent
839b945646
commit
abc6239174
@ -54,28 +54,6 @@ public class AdminController : ControllerBase
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// TODO: Переделать
|
||||
/// <summary>
|
||||
/// Добавление условия кредитования
|
||||
/// </summary>
|
||||
[HttpPost("banks/{bank_id}/loanterms")]
|
||||
public async Task<ActionResult> AddLoanTerm(long bank_id, [FromBody] LoanTerm loanTerm)
|
||||
{
|
||||
await _adminService.AddLoanTerm(loanTerm);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление ВСЕХ условий кредитования
|
||||
/// </summary>
|
||||
/// <response code="400">Банк не найден</response>
|
||||
[HttpDelete("banks/{bank_id}/loanterms")]
|
||||
public async Task<ActionResult> AddLoanTerm(long bankId)
|
||||
{
|
||||
var result = await _adminService.RemoveAllLoanTermsByBankId(bankId);
|
||||
return result == "OK" ? Ok() : BadRequest(result);
|
||||
}
|
||||
|
||||
// -------------------------------------| Университеты |-------------------------------------
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,4 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PaydayBackend.Models;
|
||||
using PaydayBackend.Services;
|
||||
|
||||
namespace PaydayBackend.Controllers;
|
||||
|
||||
@ -6,9 +8,35 @@ namespace PaydayBackend.Controllers;
|
||||
[ApiController]
|
||||
public class BankController : ControllerBase
|
||||
{
|
||||
private readonly IAdminService _adminService;
|
||||
|
||||
public BankController()
|
||||
public BankController(IAdminService adminService)
|
||||
{
|
||||
_adminService = adminService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление ВСЕХ условий кредитования
|
||||
/// </summary>
|
||||
/// <response code="400">Банк не найден</response>
|
||||
[HttpDelete("banks/{bank_id}/loanterms")]
|
||||
public async Task<ActionResult> AddLoanTerm(long bankId)
|
||||
{
|
||||
var result = await _adminService.RemoveAllLoanTermsByBankId(bankId);
|
||||
return result == "OK" ? Ok() : BadRequest(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление условия кредитования
|
||||
/// </summary>
|
||||
[HttpPost("banks/loanterms")]
|
||||
public async Task<ActionResult> AddLoanTerm([FromBody] LoanTerm loanTerm)
|
||||
{
|
||||
var result = await _adminService.AddLoanTerm(loanTerm);
|
||||
if (result != "OK")
|
||||
return BadRequest(result);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
}
|
@ -53,15 +53,30 @@ public class PublicController : ControllerBase
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение всех возможных условий кредитования банков по стоймости направления
|
||||
/// Получение одно направление по Id
|
||||
/// </summary>
|
||||
/// <response code="400">Направление не найдено</response>
|
||||
[HttpGet("credit/direction/{id}")]
|
||||
public async Task<ActionResult<IEnumerable<University>>> GetAllTermsWithDirection(long id)
|
||||
[HttpGet("direction/{id}")]
|
||||
public async Task<ActionResult<IEnumerable<UniversityDirectionDto>>> GetDirectionById(long id)
|
||||
{
|
||||
var result = await _publicService.GetAllLoansByDirectionCost(id);
|
||||
var result = await _publicService.GetDirectionById(id);
|
||||
|
||||
if (result == null)
|
||||
return BadRequest();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение всех возможных кредитов по стоймости направления от каждого банка по одному
|
||||
/// </summary>
|
||||
/// <response code="400">Направление не найдено</response>
|
||||
[HttpGet("credit/direction/{directionId}")]
|
||||
public async Task<ActionResult<IEnumerable<Offer>>> GetOffers(long directionId)
|
||||
{
|
||||
var result = await _publicService.GetOffers(directionId);
|
||||
|
||||
if (result == null)
|
||||
return BadRequest();
|
||||
|
@ -6,7 +6,7 @@ public class LoanTerm
|
||||
{
|
||||
[Key]
|
||||
public long Id { get; set; }
|
||||
public Bank Bank { get; set; }
|
||||
public long BankId { get; set; }
|
||||
[Range(0f, 360f)]
|
||||
public float InterestRate { get; set; }
|
||||
public int LoanTermInMonths { get; set; }
|
||||
|
10
PaydayBackend/Models/Offers.cs
Normal file
10
PaydayBackend/Models/Offers.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace PaydayBackend.Models;
|
||||
|
||||
public class Offer
|
||||
{
|
||||
public long DirectionId { get; set; }
|
||||
public string BankIconUrl { get; set; }
|
||||
public string BankName { get; set; }
|
||||
public float BankPercent { get; set; }
|
||||
public long BankId { get; set; }
|
||||
}
|
@ -10,7 +10,7 @@ public interface IAdminService
|
||||
// Bank
|
||||
public Task<string> AddBank(string bankName, IFormFile file);
|
||||
public Task<IEnumerable<Bank>> GetAllBanks();
|
||||
public Task AddLoanTerm(LoanTerm loanTerm);
|
||||
public Task<string> AddLoanTerm(LoanTerm loanTerm);
|
||||
public Task<string> RemoveAllLoanTermsByBankId(long bankId);
|
||||
public Task<IEnumerable<LoanTerm>?> GetAllLoanTermsByBankId(long bankId);
|
||||
// University
|
||||
@ -84,10 +84,16 @@ public class AdminService : IAdminService
|
||||
return await _databaseContext.Banks.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task AddLoanTerm(LoanTerm loanTerm)
|
||||
public async Task<string> AddLoanTerm(LoanTerm loanTerm)
|
||||
{
|
||||
var bank = await _databaseContext.Banks.Where(x => x.Id == loanTerm.BankId).FirstOrDefaultAsync();
|
||||
if (bank == null)
|
||||
return "Bank not found";
|
||||
|
||||
await _databaseContext.LoanTerms.AddAsync(loanTerm);
|
||||
await _databaseContext.SaveChangesAsync();
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
public async Task<string> RemoveAllLoanTermsByBankId(long bankId)
|
||||
@ -95,7 +101,7 @@ public class AdminService : IAdminService
|
||||
if (await BankIsExist(bankId))
|
||||
return "Bank not found";
|
||||
|
||||
var result = await _databaseContext.LoanTerms.Where(x => x.Bank.Id == bankId).ToListAsync();
|
||||
var result = await _databaseContext.LoanTerms.Where(x => x.BankId == bankId).ToListAsync();
|
||||
_databaseContext.LoanTerms.RemoveRange(result);
|
||||
|
||||
return "OK";
|
||||
@ -106,7 +112,7 @@ public class AdminService : IAdminService
|
||||
if (await BankIsExist(bankId))
|
||||
return null;
|
||||
|
||||
return await _databaseContext.LoanTerms.Where(x => x.Bank.Id == bankId).ToListAsync();
|
||||
return await _databaseContext.LoanTerms.Where(x => x.BankId == bankId).ToListAsync();
|
||||
}
|
||||
|
||||
// -------------------------------------| Университеты |-------------------------------------
|
||||
|
@ -7,9 +7,11 @@ public interface IPublicService
|
||||
{
|
||||
public Task<IEnumerable<UniversityDto>> GetAllUniversity();
|
||||
public Task<IEnumerable<UniversityDirectionDto>?> GetAllUniversityDirectionByUniversityId(long universityId);
|
||||
public Task<UniversityDirectionDto?> GetDirectionById(long directionId);
|
||||
public Task<IEnumerable<LoanTerm>?> GetAllLoansByDirectionCost(long universityDirectionId);
|
||||
public Task<long> GetMinPlaceCostByUniversityId(long universityId);
|
||||
public Task<UniversityDto?> GetAllUniversityById(long universityId);
|
||||
public Task<IEnumerable<Offer>?> GetOffers(long directionId);
|
||||
}
|
||||
|
||||
public class PublicService : IPublicService
|
||||
@ -52,6 +54,15 @@ public class PublicService : IPublicService
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<UniversityDirectionDto?> GetDirectionById(long directionId)
|
||||
{
|
||||
var result = await _databaseContext.UniversityDirections.Where(x => x.Id == directionId).FirstAsync();
|
||||
if (result == null)
|
||||
return null;
|
||||
|
||||
return new UniversityDirectionDto(result.Id, result.UniversityId, result.Code, result.Name, result.Url, result.PlaceCost);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<LoanTerm>?> GetAllLoansByDirectionCost(long universityDirectionId)
|
||||
{
|
||||
var universityDirection = await _databaseContext.UniversityDirections.Where(x => x.Id == universityDirectionId).FirstOrDefaultAsync();
|
||||
@ -85,4 +96,39 @@ public class PublicService : IPublicService
|
||||
|
||||
return new UniversityDto(university.Id, university.Name, university.FullName, university.ImageUrl);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Offer>?> GetOffers(long directionId)
|
||||
{
|
||||
var universityDirection = await _databaseContext.UniversityDirections.Where(x => x.Id == directionId).FirstOrDefaultAsync();
|
||||
if (universityDirection == null)
|
||||
return null;
|
||||
|
||||
/////
|
||||
var banks = _databaseContext.Banks.ToList();
|
||||
List<Offer> offers = new List<Offer>();
|
||||
foreach (var bank in banks)
|
||||
{
|
||||
var offer = new Offer();
|
||||
offer.DirectionId = directionId;
|
||||
offer.BankName = bank.Name;
|
||||
offer.BankIconUrl = bank.ImageUrl;
|
||||
offer.BankId = bank.Id;
|
||||
try
|
||||
{
|
||||
var percente = await _databaseContext.LoanTerms.OrderBy(x => x.InterestRate).Where(x => x.BankId == bank.Id).FirstAsync();
|
||||
if (percente == null)
|
||||
offer.BankPercent = 5;
|
||||
else
|
||||
offer.BankPercent = percente.InterestRate;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
offer.BankPercent = 5;
|
||||
}
|
||||
|
||||
offers.Add(offer);
|
||||
}
|
||||
|
||||
return offers;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user