-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertigo_query.cs
78 lines (73 loc) · 2.82 KB
/
vertigo_query.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
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Table;
using Newtonsoft.Json;
namespace uploader
{
public static class vertigo_query
{
[FunctionName("vertigo_query")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req,
[Table("Files", Connection = "AzureWebJobsStorage")]CloudTable tableBinding,
TraceWriter log)
{
try
{
string queryString = TableQuery.GenerateFilterConditionForBool("Approved", QueryComparisons.Equal, true);
TableQuery<TableFile> query = new TableQuery<TableFile>();
query.FilterString = queryString;
IEnumerable<TableFile> files = tableBinding.ExecuteQuery(query);
IEnumerable<File> filteredFiles = files.Select(tf => new File(tf));
HttpResponseMessage response = req.CreateResponse(HttpStatusCode.OK, filteredFiles, MediaTypeHeaderValue.Parse("application/json"));
response.Headers.Add("Access-Control-Allow-Credentials", "true");
response.Headers.Add("Access-Control-Allow-Origin", "*");
response.Headers.Add("Access-Control-Allow-Methods", "GET, OPTIONS");
return response;
}catch (Exception e)
{
return req.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
}
}
public class TableFile : TableEntity
{
public TableFile()
{
this.PartitionKey = "Data";
this.Timestamp = DateTime.Now;
}
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Video_Url { get; set; }
public string File_Url { get; set; }
}
public class File
{
public File(TableFile file)
{
Name = file.Name;
Title = file.Title;
Description = file.Description;
Video_Url = file.Video_Url;
File_Url = file.File_Url;
}
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Video_Url { get; set; }
public string File_Url { get; set; }
}
}
}