Browse Source

implemented basic API for getting documents

master
Lynne Megido 1 month ago
parent
commit
49a13a412f
Signed by: lynnesbian GPG Key ID: F0A184B5213D9F90
4 changed files with 39 additions and 2 deletions
  1. +36
    -0
      Controllers/DocumentController.cs
  2. +1
    -1
      Pages/Documents/Details.cshtml
  3. +1
    -1
      Pages/Shared/_Layout.cshtml
  4. +1
    -0
      Startup.cs

+ 36
- 0
Controllers/DocumentController.cs 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;
}
}
}

+ 1
- 1
Pages/Documents/Details.cshtml 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>

+ 1
- 1
Pages/Shared/_Layout.cshtml 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>

+ 1
- 0
Startup.cs View File

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

Loading…
Cancel
Save