mercredi 25 janvier 2017

How to design an internal Web Api using ASP.NET Web API

I am totally stuck. After searching for days, I finally decided to put my problem in front of you guys.

I need to develop a web api (using ASP.NET Web API 2) that would be used internally by a phone app and a web site. But I don't know how to design these specific cases:

1) Budget:

Budget Object:

public class Budget
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal TotalAmount { get; set; }
    public decimal PendingAmount { get; set; }
    public decimal ApprovedAmount { get; set; }
    public decimal PaidAmount { get; set; }

    public List<DepartmentBasicInfo> AvailableToDepartments { get; set; }

    public string CurrencyCode { get; set; }

}

Budget Api controller:

public IHttpActionResult Get([FromUri]Models.BudgetModels.BudgetQueryModel query) {

    return Ok(budgets);
}

The problem is all the Amount fields are calculated (not present in the database). The budgets need to return these when listed on the web page.

Then there are other web pages that would need a drop down list where it need to show budget name and currency and I do not want to calculate the budget amounts as this is a huge overhead in this case.

so the questions are:

1) As this is an internal web api, would this make sense to create two separate actions where one will return the whole Budget object and the other will return a thin Budget object (without Amounts and AvailableToDepartments properties) where calculations are not required, if yes what should be the route url?

2) Is there any clean way to able to use the same Budget class both for create and update in API because I am thnking that calculated fields do not belong to these operations.

3) Is it a good idea to pass a parameter to the Get method so it does not calculate budgets?

What is the cleanest way to handle these kind of cases? Please keep in mind that this is for an internal use api.

Thanks!

Iffi




Aucun commentaire:

Enregistrer un commentaire