Skip to content
Snippets Groups Projects
Commit cad12ae7 authored by Radek Puš's avatar Radek Puš
Browse files

loading files in import controller

parent a77f1422
No related branches found
No related tags found
No related merge requests found
......@@ -27,10 +27,27 @@ namespace Core.Controllers
}
 
// GET: api/Import/5
[HttpGet("{id}", Name = "GetImport")]
/*[HttpGet("{id}", Name = "GetImport")]
[Authorize(Policy = "RequireLoggedIn")]
public string Get(int id)
{
return "value";
}*/
// GET: api/Import
[HttpGet(Name = "GetImport")]
[Authorize(Policy = "RequireLoggedIn")]
public IActionResult Get()
{
Claim userJwtID = User.Claims.First(c => c.Type == "UserID");
long userID = long.Parse(userJwtID.Value);
var imports = Context.Files
.Where(file => file.UserID==userID)
.Select(f => new { id = f.ID, name = f.Name})
.ToList();
return Ok(imports);
}
 
// POST: api/Import
......@@ -81,8 +98,21 @@ namespace Core.Controllers
 
// DELETE: api/ApiWithActions/5
[HttpDelete("{id}")]
public void Delete(int id)
[Authorize(Policy = "RequireLoggedIn")]
public IActionResult Delete(int id)
{
Claim userJwtID = User.Claims.First(c => c.Type == "UserID");
long userID = long.Parse(userJwtID.Value);
Models.File file = Context.Files.FirstOrDefault(f => f.ID == id && f.UserID == userID);
if(file==null)
return Unauthorized(new { message = "file not found" });
Context.Remove(file);
Context.SaveChanges();
return Ok();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment