Removed more unnecessary files from cache
- Updated `.gitignore` - Added `README.md` file
This commit is contained in:
parent
a57ee1918e
commit
fccd30a223
10 changed files with 656 additions and 119 deletions
|
|
@ -12,7 +12,7 @@
|
|||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchBrowser": false,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7001;http://localhost:5257",
|
||||
"environmentVariables": {
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchBrowser": false,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7118;http://localhost:5257",
|
||||
"environmentVariables": {
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchBrowser": false,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using QrScanner.Models;
|
||||
|
||||
namespace server.Controllers;
|
||||
|
|
@ -9,8 +11,10 @@ public class QrScannerController : ControllerBase
|
|||
{
|
||||
const string db_connection_url = @"mongodb://localhost:27017";
|
||||
const string db_name = @"qr_scanner";
|
||||
const string col_codes = @"codes";
|
||||
const string col_codes = @"scans";
|
||||
const string col_info = @"info";
|
||||
MongoClient client;
|
||||
IMongoDatabase db;
|
||||
|
||||
public QrScannerController(){
|
||||
client = new MongoClient(db_connection_url);
|
||||
|
|
@ -32,15 +36,27 @@ public class QrScannerController : ControllerBase
|
|||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("scan")]
|
||||
public async Task<IActionResult> scan(string code){
|
||||
Console.WriteLine(code);
|
||||
return Ok();
|
||||
return await _store_code(code);
|
||||
}
|
||||
|
||||
[HttpGet("codes")]
|
||||
public async Task<ActionResult<List<QrCode>>> get_codes(){
|
||||
return await _fetch_all_codes();
|
||||
}
|
||||
|
||||
|
||||
public async Task<IActionResult> _store_cost(string code){
|
||||
|
||||
public async Task<IActionResult> _store_code(string code){
|
||||
Console.WriteLine(code);
|
||||
QrCode qr_code = new();
|
||||
qr_code.id = Guid.NewGuid().ToString();
|
||||
// qr_code.timestamp = DateTime.Now;
|
||||
qr_code.data = code;
|
||||
var col = db.GetCollection<QrCode>(col_codes);
|
||||
await col.InsertOneAsync(qr_code);
|
||||
return Ok(code);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -55,12 +71,12 @@ public class QrScannerController : ControllerBase
|
|||
Console.WriteLine($"_fetch_code(): Fetching QR code from '{db_name}.{col_codes}'");
|
||||
var col = db.GetCollection<QrCode>(col_codes);
|
||||
var filter = Builders<QrCode>.Filter.Eq(field, value);
|
||||
return await Ok(col.Find(filter).FirstOrDefaultAsync());
|
||||
return Ok(await col.Find(filter).FirstOrDefaultAsync());
|
||||
}
|
||||
|
||||
|
||||
public async Task<ActionResult<List<QrCodes>>> _fetch_all_codes(){
|
||||
var col = db.GetCollection<SurveyInfo>(col_info);
|
||||
return await col.Find(new BsonDocument{}).ToListAsync();
|
||||
public async Task<ActionResult<List<QrCode>>> _fetch_all_codes(){
|
||||
var col = db.GetCollection<QrCode>(col_codes);
|
||||
return await col.Find(f => true).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ namespace QrScanner.Models;
|
|||
[BsonIgnoreExtraElements]
|
||||
public class QrCode
|
||||
{
|
||||
[BsonId]
|
||||
public ObjectId _id { get; set; }
|
||||
public string data { get; set; }
|
||||
public string? id { get; set; }
|
||||
// public DateTime timestamp { get; set; }
|
||||
public string? data { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
|
||||
<PackageReference Include="MongoDB.Bson" Version="2.18.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
|
||||
<PackageReference Include="MongoDB.Driver.Core" Version="2.18.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue