-
Notifications
You must be signed in to change notification settings - Fork 2
/
GetRating.cs
57 lines (47 loc) · 1.8 KB
/
GetRating.cs
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
using System;
using System.IO;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace icecream.Rating
{
public static class GetRating
{
[FunctionName("GetRating")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "GetRating/{ratingId}")]
HttpRequest req,
[CosmosDB(
databaseName: "icecream",
collectionName: "ratings",
ConnectionStringSetting = "COSMOS_CONNECTION_STRING",
SqlQuery = "SELECT * FROM ratings r where r.id={ratingId}")] IEnumerable<Rating> rating,
ILogger log)
{
// Log
log.LogInformation("C# HTTP trigger function processed a request.");
if (rating is null)
{
return new NotFoundResult();
}
return new OkObjectResult(rating);
/*
string userId = req.Query["userId"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
userId = userId ?? data?.userId;
// Connect to Cosmos DB
*/
/*
string responseMessage = string.IsNullOrEmpty(userId)
? "This HTTP triggered function executed successfully. Pass a userId in the query string or in the request body for a personalized response." : "";
return new OkObjectResult(responseMessage);
*/
}
}
}