Skip to content

Commit a316011

Browse files
committed
-- Fix for the send point function
1 parent 5ed6d1e commit a316011

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

API.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.IO;
34
using System.Net;
@@ -51,5 +52,32 @@ public async Task<HttpResponseData> AddPoints([HttpTrigger(AuthorizationLevel.Fu
5152

5253
return response;
5354
}
55+
56+
[Function("SendRandomPoints")]
57+
public async Task<HttpResponseData> SendRandomPoints([HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req)
58+
{
59+
_logger.LogInformation("Sending random 3D points.");
60+
61+
var random = new Random();
62+
var points = new List<Point3D>();
63+
64+
for (int i = 0; i < 10; i++)
65+
{
66+
points.Add(new Point3D
67+
{
68+
X = random.Next(-100, 100),
69+
Y = random.Next(-100, 100),
70+
Z = random.Next(-100, 100)
71+
});
72+
}
73+
74+
await _databaseHandler.AddPointsAsync(points);
75+
76+
var response = req.CreateResponse(HttpStatusCode.OK);
77+
response.Headers.Add("Content-Type", "application/json; charset=utf-8");
78+
await response.WriteStringAsync(JsonSerializer.Serialize(points));
79+
80+
return response;
81+
}
5482
}
5583
}

DatabaseHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ public async Task AddPointsAsync(List<Point3D> points)
5050
await conn.OpenAsync();
5151
foreach (var point in points)
5252
{
53-
var query = "INSERT INTO Pontos3D (Id, x, y, z) VALUES (@Id, @x, @y, @z)";
53+
var query = "INSERT INTO Pontos3D (x, y, z) VALUES (@x, @y, @z)";
5454
using (SqlCommand cmd = new SqlCommand(query, conn))
5555
{
56-
cmd.Parameters.AddWithValue("@Id", point.ID);
5756
cmd.Parameters.AddWithValue("@x", point.X);
5857
cmd.Parameters.AddWithValue("@y", point.Y);
5958
cmd.Parameters.AddWithValue("@z", point.Z);

host.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"version": "2.0",
3-
"isDefaultHostConfig": true,
43
"extensionBundle": {
54
"id": "Microsoft.Azure.Functions.ExtensionBundle",
65
"version": "[4.*, 5.0.0)"

0 commit comments

Comments
 (0)