-
Notifications
You must be signed in to change notification settings - Fork 2
/
GetRatings.cs
67 lines (56 loc) · 2.13 KB
/
GetRatings.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
58
59
60
61
62
63
64
65
66
67
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 GetRatings
{
[FunctionName("GetRatings")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "GetRatings/{userId}")]
HttpRequest req,
[CosmosDB(
databaseName: "icecream",
collectionName: "ratings",
ConnectionStringSetting = "COSMOS_CONNECTION_STRING",
SqlQuery = "SELECT * FROM ratings r where r.userId={userId}")] IEnumerable<Rating> ratings,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
if (ratings is null)
{
return new NotFoundResult();
}
return new OkObjectResult(ratings);
/*
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);
*/
}
}
public class Rating
{
public string id { get; set; }
public string userId { get; set; }
public string productId { get; set; }
public string timestamp { get; set; }
public string locationName { get; set; }
public string rating { get; set; }
public string userNotes { get; set; }
}
}