public async Task <IActionResult> Weekly([FromRoute] string symbol, [FromRoute] int year, [FromRoute][Range(1, 54)] int week) { if (!IsWeekOfYearValid(week)) { return(BadRequest()); } var price = await _analyticsService.GetWeeklyAsync(symbol, year, week); if (price == null) { return(NotFound()); } var result = new WeeklyModel() { Symbol = symbol, Year = year, Week = week, Price = Map(price) }; return(Ok(result)); }
public async Task <IActionResult> Weekly([FromRoute] string symbol, [FromRoute] int year, [FromRoute] int week) { // TODO: Add implementation for the weekly summary var result = new WeeklyModel() { Symbol = symbol, Year = year, Week = week, Price = Map(new AnalyticsPrice()) }; return(Ok(result)); }
public async Task <IActionResult> Weekly([FromRoute] string symbol, [FromRoute] int year, [FromRoute] int week) { var analyticsPrice = await _analyticsService.GetWeeklyAsync(symbol, year, week); var result = new WeeklyModel() { Symbol = symbol, Year = year, Week = week, Price = Map(analyticsPrice) }; return(Ok(result)); }
public async Task <IActionResult> Weekly([FromRoute] string symbol, [FromRoute] int year, [FromRoute] int week) { var result = await _analyticsService.GetWeeklyAsync(symbol, year, week); if (result != null) { var weeklyresult = new WeeklyModel() { Symbol = symbol, Year = year, Week = week, Price = Map(result) }; return(Ok(result)); } else { return(NotFound()); } }
public async Task <IActionResult> Weekly([FromRoute] string symbol, [FromRoute] int year, [FromRoute] int week) { // TODO: Add implementation for the weekly summary //validate route values if (symbol.Length > 3 || symbol.Length < 3) { return(BadRequest("Symbol characters exceeded or below")); } if (year < 1000) { return(BadRequest("The year value is less")); } if (!Enumerable.Range(1, 52).Contains(week)) { return(BadRequest("Incorrect Week Value")); } AnalyticsPrice weekAnalyticPrice = new AnalyticsPrice(); try { weekAnalyticPrice = await _analyticsService.GetWeeklyAsync(symbol, year, week); } catch (Exception e) { return(NotFound(e.Message)); } var result = new WeeklyModel() { Symbol = symbol, Year = year, Week = week, Price = Map(weekAnalyticPrice) }; return(Ok(result)); }
public async Task <IActionResult> Weekly([FromRoute] string symbol, [FromRoute] int year, [FromRoute] int week) { try { var result = new WeeklyModel() { Symbol = symbol, Year = year, Week = week, Price = Map(await _analyticsService.GetWeeklyAsync(symbol, year, week)) }; return(Ok(result)); } //This can be removed [Managing in exception middleware] //- Keeping this, to validate test case catch (ApplicationException exp) { if (exp.Message.Contains("NotFound:")) { return(NotFound(exp.Message)); } return(BadRequest(exp.Message)); } }