From 61422d93f2cfbf11067927816a25875aed1caf5e Mon Sep 17 00:00:00 2001 From: jessikitty Date: Wed, 20 May 2026 15:15:07 +1000 Subject: [PATCH] =?UTF-8?q?v1.0.0:=20DisplayController=20=E2=80=94=20displ?= =?UTF-8?q?ay=20frontend=20+=20playlist=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/DisplayController.cs | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Controllers/DisplayController.cs diff --git a/Controllers/DisplayController.cs b/Controllers/DisplayController.cs new file mode 100644 index 0000000..f969da3 --- /dev/null +++ b/Controllers/DisplayController.cs @@ -0,0 +1,71 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using NoticeBoard.Data; + +namespace NoticeBoard.Controllers; + +public class DisplayController : Controller +{ + private readonly AppDbContext _db; + + public DisplayController(AppDbContext db) + { + _db = db; + } + + public async Task Show(string slug) + { + var device = await _db.Devices + .Include(d => d.DeviceSlides.Where(ds => ds.Enabled).OrderBy(ds => ds.DisplayOrder)) + .ThenInclude(ds => ds.Slide) + .FirstOrDefaultAsync(d => d.Slug == slug.ToLower()); + + if (device == null) + { + var devices = await _db.Devices.OrderBy(d => d.Name).ToListAsync(); + return View("NotFound", devices); + } + + return View(device); + } + + [HttpGet] + [Route("api/playlist/{slug}")] + public async Task GetPlaylist(string slug) + { + var device = await _db.Devices + .Include(d => d.DeviceSlides.Where(ds => ds.Enabled).OrderBy(ds => ds.DisplayOrder)) + .ThenInclude(ds => ds.Slide) + .FirstOrDefaultAsync(d => d.Slug == slug.ToLower()); + + if (device == null) return NotFound(); + + var playlist = device.DeviceSlides.Select(ds => new + { + id = ds.Slide.Id, + name = ds.Slide.Name, + type = ds.Slide.SlideType.ToString().ToLower(), + content = ds.Slide.Content, + embedUrl = ds.Slide.EmbedUrl, + icsSource = ds.Slide.IcsSource, + backgroundColor = ds.Slide.BackgroundColor, + backgroundImage = ds.Slide.BackgroundImage, + customCss = ds.Slide.CustomCss, + duration = ds.DurationSeconds, + updatedAt = ds.Slide.UpdatedAt + }); + + return Json(new + { + device = new + { + name = device.Name, + slug = device.Slug, + width = device.ResolutionWidth, + height = device.ResolutionHeight, + transition = device.Transition + }, + slides = playlist + }); + } +}