I have an ASP.NET Core Web API communicating with a flutter mobile app.
The feature I am adding is a notification service. The issue is I have more than one notification type.
Here is the code:
public class NotificationSuper
{
public string Title { get; set; }
public string Body { get; set; }
public string Token { get; set; }
public string Type { get; set; }
}
public class UnitNotification :NotificationSuper
{
public String Renter_Key { get; set; }
public String Owner_Key { get; set; }
public String Building_Key { get; set; }
public String Unit_Key { get; set; }
}
public class MaintenanceNotification : UnitNotification
{
public DateTime RequestData { get; set; }
}
and so on.
I wrote a controller for the notification using a super generic type in its params
[HttpPost]
public async Task<IActionResult> Post([FromBody] NotificationSuper notification)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
bool success = await Notify.Send(notification);
if (success)
{
return Ok();
}
return StatusCode(500);
}
The problem is when I retrieve the JSON data from the flutter app, I only get the properties of the NotificationSuper class which are:
public String Renter_Key { get; set; }
public String Owner_Key { get; set; }
public String Building_Key { get; set; }
I want to have a flexible way to get every property if I passed UnitNotification or MaintenanceNotification. Should I have multiple controllers, one for each type of notification?
Thanks in advance
