-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublicController.cs
More file actions
91 lines (82 loc) · 3 KB
/
PublicController.cs
File metadata and controls
91 lines (82 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using Backend.Data;
using Backend.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace Backend.Controllers;
[ApiController]
[Route("api/public")]
public class PublicController(AppDbContext db) : ControllerBase
{
[HttpGet("safehouses")]
[AllowAnonymous]
public async Task<IActionResult> GetPublicSafehouses()
{
var safehouses = await db.Safehouses
.Select(s => new
{
safehouseId = s.SafehouseId,
safehouseCode = s.SafehouseCode,
name = s.Name,
region = s.Region,
city = s.City,
province = s.Province,
status = s.Status,
capacityGirls = s.CapacityGirls,
currentOccupancy = s.CurrentOccupancy,
openDate = s.OpenDate,
notes = s.Notes
})
.ToListAsync();
return Ok(safehouses);
}
[HttpGet("safehouses/occupancy")]
[AllowAnonymous]
public async Task<IActionResult> GetPublicSafehouseOccupancy()
{
var data = await db.Safehouses
.Select(s => new
{
safehouseId = s.SafehouseId,
name = s.Name,
region = s.Region,
capacityGirls = s.CapacityGirls,
currentOccupancy = s.CurrentOccupancy
})
.ToListAsync();
return Ok(data);
}
[HttpGet("impact-snapshots")]
[AllowAnonymous]
public async Task<IActionResult> GetImpactSnapshots()
{
var snapshots = await db.PublicImpactSnapshots
.Where(s => s.IsPublished == true)
.OrderByDescending(s => s.SnapshotDate)
.ToListAsync();
return Ok(snapshots);
}
[HttpGet("impact-stats")]
[AllowAnonymous]
public async Task<IActionResult> GetImpactStats()
{
var totalResidents = await db.Residents.CountAsync();
var reintegrationRate = totalResidents > 0
? (double)await db.Residents.CountAsync(r =>
r.ReintegrationType != null && r.ReintegrationStatus == "Completed")
/ totalResidents * 100
: 0;
return Ok(new
{
girlsServed = totalResidents,
activeResidents = await db.Residents.CountAsync(r => r.CaseStatus == "Active"),
safehousesOperating = await db.Safehouses.CountAsync(s => s.Status == "Active"),
regionsServed = await db.Safehouses.Select(s => s.Region).Distinct().CountAsync(),
totalCounselingSessions = await db.ProcessRecordings.CountAsync(),
totalHomeVisitations = await db.HomeVisitations.CountAsync(),
reintegrationRate = Math.Round(reintegrationRate, 2),
totalDonationAmount = await db.Donations.Where(d => d.Amount != null).SumAsync(d => d.Amount),
totalDonors = await db.Donations.Select(d => d.SupporterId).Distinct().CountAsync()
});
}
}