endpointy zwracające wykaz transakcji/wydatków zawartych w raporcie

This commit is contained in:
Kamil Ryżek 2024-06-10 00:09:40 +02:00
parent 207ee08330
commit a25a1a3d23
2 changed files with 51 additions and 3 deletions

View File

@ -96,9 +96,6 @@ namespace FirmTracker_Server.Controllers
return BadRequest(ex.Message); return BadRequest(ex.Message);
} }
} }
[HttpGet("{id}")] [HttpGet("{id}")]
@ -119,6 +116,33 @@ namespace FirmTracker_Server.Controllers
return Ok(json); return Ok(json);
} }
[HttpGet("{id}/transactions")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public IActionResult GetReportTransactions(int reportId)
{
var transactions = _reportCRUD.GetReportTransactions(reportId);
if (transactions == null)
{
return NotFound();
}
return Ok(transactions);
}
[HttpGet("{id}/expenses")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public IActionResult GetReportExpenses(int reportId)
{
var expenses = _reportCRUD.GetReportExpenses(reportId);
if (expenses == null)
{
return NotFound();
}
return Ok(expenses);
}
[HttpGet] [HttpGet]
[ProducesResponseType(200)] [ProducesResponseType(200)]
[ProducesResponseType(404)] [ProducesResponseType(404)]

View File

@ -99,6 +99,30 @@ namespace FirmTracker_Server.nHibernate.Reports
} }
} }
public IList<nHibernate.Transactions.Transaction> GetReportTransactions(int reportId)
{
using (var session = SessionFactory.OpenSession())
{
return session.Query<ReportTransaction>()
.Where(rt => rt.Report.Id == reportId)
.Select(rt => rt.Transaction)
.Fetch(t => t.TransactionProducts)
.ToList();
}
}
public IList<Expense> GetReportExpenses(int reportId)
{
using (var session = SessionFactory.OpenSession())
{
return session.Query<ReportExpense>()
.Where(re => re.Report.Id == reportId)
.Select(re => re.Expense)
.ToList();
}
}
public Report UpdateReport(Report report, IList<nHibernate.Transactions.Transaction> transactions, IList<Expense> expenses) public Report UpdateReport(Report report, IList<nHibernate.Transactions.Transaction> transactions, IList<Expense> expenses)
{ {
using (var session = SessionFactory.OpenSession()) using (var session = SessionFactory.OpenSession())