From e859227a3722f28f858d6bb4cedfdd7b868680ff Mon Sep 17 00:00:00 2001 From: Ivan Ljubisavljevic Date: Tue, 26 Apr 2022 20:47:04 +0200 Subject: Dodat api za prikaz odredjenih redova u csv-u --- backend/api/api/Controllers/FileController.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'backend') diff --git a/backend/api/api/Controllers/FileController.cs b/backend/api/api/Controllers/FileController.cs index 68d2ebed..0e9f9b97 100644 --- a/backend/api/api/Controllers/FileController.cs +++ b/backend/api/api/Controllers/FileController.cs @@ -115,6 +115,26 @@ namespace api.Controllers return String.Join("\n", System.IO.File.ReadLines(filePath).Take(10)); } + [HttpGet("csvread/{hasHeader}/{fileId}/{skipRows}/{takeRows}")] + [Authorize(Roles = "User,Guest")] + public ActionResult CsvRead(bool hasHeader, string fileId, int skipRows, int takeRows) + { + + string uploaderId = getUserId(); + + if (uploaderId == null) + return BadRequest(); + + //String csvContent = System.IO.File.ReadAllText(fileModel.path); + string filePath = _fileservice.GetFilePath(fileId, uploaderId); + + + + if (hasHeader) + return String.Join("\n", System.IO.File.ReadLines(filePath).Skip(skipRows+1).Take(takeRows)); + else + return String.Join("\n", System.IO.File.ReadLines(filePath).Skip(skipRows).Take(takeRows)); + } [HttpPost("Csv")] -- cgit v1.2.3