implemented basic API for getting documents

This commit is contained in:
Lynne Megido 2020-09-16 12:55:32 +10:00
parent afbb814fef
commit 49a13a412f
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
4 changed files with 39 additions and 2 deletions

View file

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Snootalogue.Models;
using Snootalogue.Data;
namespace Snootalogue.Controllers {
[Route("/api/[controller]")]
[ApiController]
public class DocumentController : ControllerBase {
private readonly SnootalogueContext _context;
public DocumentController(SnootalogueContext context) {
_context = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<Document>>> GetDocuments() {
return await _context.Document.Take(25).ToListAsync();
}
[HttpGet("{id}")]
public async Task<ActionResult<Document>> GetDocumentById(int id) {
var document = await _context.Document.FindAsync(id);
if (document == null) {
return NotFound();
}
return document;
}
}
}

View file

@ -35,6 +35,6 @@
<div class="centred">
<a class="button block" href='/'>Return to documents</a>
<br>
<a class="button block" href='#'>View as JSON</a>
<a class="button block" href='/api/Document/@Model.Document.ID'>View as JSON</a>
</div>

View file

@ -10,7 +10,7 @@
<body>
<nav>
<div id="nav-links">Snootalogue - Link 1 - Link 2</div>
<div id="nav-links">Snootalogue</div>
<div id="nav-controls">
<input id="nav-search" type="search" placeholder="Search...">
<a class="button inverted" href="#">Help</a>

View file

@ -42,6 +42,7 @@ namespace Snootalogue {
// });
endpoints.MapRazorPages();
endpoints.MapControllers();
});
}
}