aboutsummaryrefslogtreecommitdiffstats
path: root/src/Pages/Read.cshtml.cs
blob: 16a1055391d0d3fa7f96a86ba9e86484f482f814 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace I2R.LightNews.Pages;

public class ReadModel : PageModel
{
    private readonly GrabberService _grabber;

    public NewsArticle Source { get; set; }

    public ReadModel(GrabberService grabber) {
        _grabber = grabber;
    }

    public async Task<ActionResult> OnGet([FromRoute] string site, [FromQuery] string url) {
        Source = site switch {
            "nrk" => await _grabber.GrabNrkArticleAsync(url),
            _ => default
        };
        if (Source == default) return Redirect("/");
        return Page();
    }
}