aboutsummaryrefslogtreecommitdiff
path: root/backend/api
diff options
context:
space:
mode:
authorDESKTOP-S0O2C44\ROG <ivan996sk@gmail.com>2022-04-06 23:25:32 +0200
committerDESKTOP-S0O2C44\ROG <ivan996sk@gmail.com>2022-04-06 23:25:32 +0200
commit50ded629f0d85b8e998780aef8adf09f09d6d232 (patch)
tree1b8adc35b445c69b7abd62b2de0ef12ee020d8f6 /backend/api
parent364e0c668dc6cd2a2ace7ed90adbc543c5128716 (diff)
Ocitan csv na beku i vracen odredjeni broj redova
Diffstat (limited to 'backend/api')
-rw-r--r--backend/api/api/Controllers/FileController.cs48
1 files changed, 47 insertions, 1 deletions
diff --git a/backend/api/api/Controllers/FileController.cs b/backend/api/api/Controllers/FileController.cs
index d29c5676..ead9ee9a 100644
--- a/backend/api/api/Controllers/FileController.cs
+++ b/backend/api/api/Controllers/FileController.cs
@@ -4,6 +4,10 @@ using api.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
+using CsvHelper;
+using System.IO;
+using System.Globalization;
+using System.Linq;
namespace api.Controllers
{
@@ -14,6 +18,7 @@ namespace api.Controllers
private string[] permittedExtensions = { ".csv" };
private string[] permittedExtensionsH5 = { ".h5" };//niz da bi dodali h4 itd
private readonly IConfiguration _configuration;
+ private readonly IFileService _fileService;
private IJwtToken _token;
private IFileService _fileservice;
public FileController(IConfiguration configuration,IFileService fileService,IJwtToken token)
@@ -95,6 +100,37 @@ namespace api.Controllers
return Ok(fileModel);
}
+ [HttpGet("csvread/{hasheader}/{fileid}")]
+ [Authorize(Roles = "User,Guest")]
+ public ActionResult<List<string>> CsvRead(bool hasHeader, string fileId)
+ {
+
+ string uploaderId;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ uploaderId = _token.TokenToId(parameter);
+ if (uploaderId == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ //String csvContent = System.IO.File.ReadAllText(fileModel.path);
+ string filePath = _fileService.GetFilePath(fileId, uploaderId);
+
+
+
+ if(hasHeader)
+ return System.IO.File.ReadLines(filePath).Take(11).ToList();
+ else
+ return System.IO.File.ReadLines(filePath).Take(10).ToList();
+ }
+
+
[HttpPost("Csv")]
[Authorize(Roles = "User,Guest")]
@@ -159,9 +195,19 @@ namespace api.Controllers
fileModel.uploaderId= uploaderId;
fileModel.date = DateTime.Now.ToUniversalTime();
fileModel =_fileservice.Create(fileModel);
+
+ /*
+ using (var streamReader = new StreamReader(fullPath))
+ {
+ using(var csvReader=new CsvReader(streamReader, CultureInfo.InvariantCulture))
+ {
+ var records = csvReader.GetRecords<dynamic>().ToList();
+ }
+ }
+ */
- return Ok(fileModel);
+ return Ok(fileModel);
}