1using Microsoft.AspNetCore.Mvc;
2using Microsoft.AspNetCore.Authorization;
3using hollow_build.Models;
4using hollow_build.Services;
5
6namespace hollow_build.Controllers
7{
8 [ApiController]
9 [Route("api/[controller]")]
10 [Authorize]
11 public class EntriesController : ControllerBase
12 {
13 private readonly IEntryService _entryService;
14
15 public EntriesController(IEntryService entryService)
16 {
17 _entryService = entryService;
18 }
19
20 // GET: api/entries
21 [HttpGet]
22 public async Task<ActionResult<IEnumerable<Entry>>> GetEntries()
23 {
24 var entries = await _entryService.GetAllAsync();
25 return Ok(entries);
26 }
27
28 // POST: api/entries
29 [HttpPost]
30 public async Task<ActionResult<Entry>> CreateEntry([FromBody] EntryDto dto)
31 {
32 if (!ModelState.IsValid) return BadRequest(ModelState);
33 var created = await _entryService.CreateAsync(dto);
34 return CreatedAtAction(nameof(GetEntries), new { id = created.Id }, created);
35 }
36
37 // PUT: api/entries/5
38 [HttpPut("{id}")]
39 public async Task<IActionResult> UpdateEntry(int id, [FromBody] EntryDto dto)
40 {
41 var updated = await _entryService.UpdateAsync(id, dto);
42 if (updated == null) return NotFound();
43 return NoContent();
44 }
45
46 // DELETE: api/entries/5
47 [HttpDelete("{id}")]
48 public async Task<IActionResult> DeleteEntry(int id)
49 {
50 var success = await _entryService.DeleteAsync(id);
51 if (!success) return NotFound();
52 return NoContent();
53 }
54 }
55}
56
No comments yet. Be the first!