public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); if (!int.TryParse(req.Query["paged"], out var page)) { page = 1; } var repository = PostsRepositoryFactory.Create(); var feed = await repository.GetPagedFeed(page, Config.PostAuthorName); return(new RssResult(feed)); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); var ok = int.TryParse(req.Query["page"], out var page); ok &= int.TryParse(req.Query["qtd"], out var qtd); if (!ok) { return(new BadRequestObjectResult("Something went wrong, really really wrong")); } var repository = PostsRepositoryFactory.Create(); var posts = await repository.GetPagedPosts(page, qtd, Config.PostAuthorName); return(new OkObjectResult(posts.Select(p => new PostViewModel(p)))); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); var value = req.Query["id"]; if (!value.Any()) { return(new BadRequestObjectResult("Bad id")); } var someId = value.ToString(); Option <Post> somePost; var repository = PostsRepositoryFactory.Create(); somePost = int.TryParse(someId, out var id) ? await repository.GetPost(id) : await repository.GetPost(someId); return(somePost .Some(p => (IActionResult) new OkObjectResult(p)) .None(() => new BadRequestObjectResult("Post not found"))); }