Добавил минимальную сумму курсов вуза
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 18s
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 18s
This commit is contained in:
parent
9b0636beb7
commit
3260da9b78
@ -58,12 +58,12 @@ public class AdminController : ControllerBase
|
||||
/// <summary>
|
||||
/// Добавление условия кредитования
|
||||
/// </summary>
|
||||
// [HttpPost("banks/{bank_id}/loanterms")]
|
||||
// public async Task<ActionResult> AddLoanTerm(long bank_id, [FromBody] LoanTerm loanTerm)
|
||||
// {
|
||||
// await _adminService.AddLoanTerm(loanTerm);
|
||||
// return Ok();
|
||||
// }
|
||||
[HttpPost("banks/{bank_id}/loanterms")]
|
||||
public async Task<ActionResult> AddLoanTerm(long bank_id, [FromBody] LoanTerm loanTerm)
|
||||
{
|
||||
await _adminService.AddLoanTerm(loanTerm);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление ВСЕХ условий кредитования
|
||||
@ -78,6 +78,15 @@ public class AdminController : ControllerBase
|
||||
|
||||
// -------------------------------------| Университеты |-------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Получение всех университетов
|
||||
/// </summary>
|
||||
[HttpGet("universities")]
|
||||
public async Task<IEnumerable<University>> GetUniversity()
|
||||
{
|
||||
return await _adminService.GetAllUniversity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление университета
|
||||
/// </summary>
|
||||
|
@ -19,7 +19,7 @@ public class PublicController : ControllerBase
|
||||
/// Получение всех университетов
|
||||
/// </summary>
|
||||
[HttpGet("university")]
|
||||
public async Task<IEnumerable<University>> GetAllUniversity()
|
||||
public async Task<IEnumerable<UniversityDto>> GetAllUniversity()
|
||||
{
|
||||
return await _publicService.GetAllUniversity();
|
||||
}
|
||||
@ -29,7 +29,7 @@ public class PublicController : ControllerBase
|
||||
/// </summary>
|
||||
/// <response code="400">Университет не найден</response>
|
||||
[HttpGet("university/{id}/direction")]
|
||||
public async Task<ActionResult<IEnumerable<University>>> GetAllUniversityDirectionByUniversityId(long id)
|
||||
public async Task<ActionResult<IEnumerable<UniversityDto>>> GetAllUniversityDirectionByUniversityId(long id)
|
||||
{
|
||||
var result = await _publicService.GetAllUniversityDirectionByUniversityId(id);
|
||||
|
||||
@ -38,4 +38,19 @@ public class PublicController : ControllerBase
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение всех возможных условий кредитования банков по стоймости направления
|
||||
/// </summary>
|
||||
/// <response code="400">Направление не найдено</response>
|
||||
[HttpGet("credit/direction/{id}")]
|
||||
public async Task<ActionResult<IEnumerable<University>>> GetAllTermsWithDirection(long id)
|
||||
{
|
||||
var result = await _publicService.GetAllLoansByDirectionCost(id);
|
||||
|
||||
if (result == null)
|
||||
return BadRequest();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
@ -11,5 +11,6 @@ public class LoanTerm
|
||||
public float InterestRate { get; set; }
|
||||
public int LoanTermInMonths { get; set; }
|
||||
public string Documents { get; set; }
|
||||
public long MaxCost { get; set; }
|
||||
|
||||
}
|
@ -9,4 +9,5 @@ public class University
|
||||
public string Name { get; set; }
|
||||
public string FullName { get; set; }
|
||||
public string ImageUrl { get; set; }
|
||||
public List<UniversityDirection> Directions { get; set; } = null;
|
||||
}
|
18
PaydayBackend/Models/UniversityDTO.cs
Normal file
18
PaydayBackend/Models/UniversityDTO.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace PaydayBackend.Models;
|
||||
|
||||
public class UniversityDto
|
||||
{
|
||||
public UniversityDto(long id, string name, string fullName, string imageUrl)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
FullName = fullName;
|
||||
ImageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string FullName { get; set; }
|
||||
public string ImageUrl { get; set; }
|
||||
public long MinPlaceCost { get; set; }
|
||||
}
|
@ -1,12 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PaydayBackend.Models;
|
||||
|
||||
public class UniversityDirection
|
||||
{
|
||||
[Key]
|
||||
public long Id { get; set; }
|
||||
public University University { get; set; }
|
||||
[ForeignKey("University")]
|
||||
public long UniversityId { get; set; }
|
||||
public string Code { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int BudgetPlaces { get; set; }
|
||||
public int PlaceCost { get; set; }
|
||||
}
|
@ -12,6 +12,7 @@ public interface IAdminService
|
||||
public Task AddLoanTerm(LoanTerm loanTerm);
|
||||
public Task<string> RemoveAllLoanTermsByBankId(long bankId);
|
||||
public Task<IEnumerable<LoanTerm>?> GetAllLoanTermsByBankId(long bankId);
|
||||
public Task<IEnumerable<University>> GetAllUniversity();
|
||||
public Task<string> AddUniversity(string shortName, string fullName, IFormFile file);
|
||||
public Task AddUniversityDirection(UniversityDirection universityDirection);
|
||||
}
|
||||
@ -99,6 +100,11 @@ public class AdminService : IAdminService
|
||||
|
||||
// -------------------------------------| Университеты |-------------------------------------
|
||||
|
||||
public async Task<IEnumerable<University>> GetAllUniversity()
|
||||
{
|
||||
return await _databaseContext.Universities.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<string> AddUniversity(string shortName, string fullName, IFormFile file)
|
||||
{
|
||||
string sizeValidator = FileHelper.ValidateMaxFileSize(file, 5, new []{".png"});
|
||||
|
@ -5,9 +5,10 @@ namespace PaydayBackend.Services;
|
||||
|
||||
public interface IPublicService
|
||||
{
|
||||
public Task<IEnumerable<University>> GetAllUniversity();
|
||||
public Task<IEnumerable<UniversityDto>> GetAllUniversity();
|
||||
public Task<IEnumerable<UniversityDirection>?> GetAllUniversityDirectionByUniversityId(long universityId);
|
||||
// public Task<IEnumerable<LoanTerm> GetAllLoansByDirectionCost();
|
||||
public Task<IEnumerable<LoanTerm>?> GetAllLoansByDirectionCost(long universityDirectionId);
|
||||
public Task<long> GetMinPlaceCostByUniversityId(long universityId);
|
||||
}
|
||||
|
||||
public class PublicService : IPublicService
|
||||
@ -19,9 +20,21 @@ public class PublicService : IPublicService
|
||||
_databaseContext = databaseContext;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<University>> GetAllUniversity()
|
||||
|
||||
|
||||
public async Task<IEnumerable<UniversityDto>> GetAllUniversity()
|
||||
{
|
||||
return await _databaseContext.Universities.ToListAsync();
|
||||
var result = await _databaseContext.Universities.ToListAsync();
|
||||
|
||||
List<UniversityDto> dtos = new List<UniversityDto>();
|
||||
foreach (var item in result)
|
||||
{
|
||||
UniversityDto dto = new UniversityDto(item.Id, item.Name, item.FullName, item.ImageUrl);
|
||||
dto.MinPlaceCost = await GetMinPlaceCostByUniversityId(item.Id);
|
||||
dtos.Add(dto);
|
||||
}
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<UniversityDirection>?> GetAllUniversityDirectionByUniversityId(long universityId)
|
||||
@ -32,4 +45,28 @@ public class PublicService : IPublicService
|
||||
return await _databaseContext.UniversityDirections.Where(x => x.UniversityId == universityId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<LoanTerm>?> GetAllLoansByDirectionCost(long universityDirectionId)
|
||||
{
|
||||
var universityDirection = await _databaseContext.UniversityDirections.Where(x => x.Id == universityDirectionId).FirstOrDefaultAsync();
|
||||
if (universityDirection == null)
|
||||
return null;
|
||||
|
||||
List<LoanTerm> loanTerms = await _databaseContext.LoanTerms.Where(x => x.MaxCost >= universityDirection.PlaceCost).ToListAsync();
|
||||
return loanTerms;
|
||||
}
|
||||
|
||||
public async Task<long> GetMinPlaceCostByUniversityId(long universityId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var universityDirection = await _databaseContext.UniversityDirections.OrderByDescending(x => x.PlaceCost).Where(x => x.UniversityId == universityId).FirstAsync();
|
||||
if (universityDirection == null)
|
||||
return 0;
|
||||
return universityDirection.PlaceCost;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user