implemented basic API for getting documents
This commit is contained in:
parent
afbb814fef
commit
49a13a412f
4 changed files with 39 additions and 2 deletions
36
Controllers/DocumentController.cs
Normal file
36
Controllers/DocumentController.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace Snootalogue {
|
|||
// });
|
||||
|
||||
endpoints.MapRazorPages();
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue