1
0
Fork 0
mirror of https://github.com/miawinter98/just-short-it.git synced 2024-11-22 16:29:53 +00:00

Added Inspect Page

This commit is contained in:
Mia Rose Winter 2023-04-19 16:10:49 +02:00
parent f944ea4236
commit 89cce362f6
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
3 changed files with 85 additions and 0 deletions

View file

@ -5,6 +5,7 @@
### Added ### Added
- Page Titles to Login, Logout and Urls Page - Page Titles to Login, Logout and Urls Page
- Added Inspect Page, which displays information about a URL and allows to delete it
## [1.1.0] - 2023-04-17 ## [1.1.0] - 2023-04-17

38
Pages/Inspect.cshtml Normal file
View file

@ -0,0 +1,38 @@
@page
@using JustShortIt.Model
@model JustShortIt.Pages.InspectModel
@{
ViewData["Title"] = "Inspect";
}
<div class="columns is-centered is-multiline my-6 px-4">
@if (Model.UrlRedirect is null) {
@if (!string.IsNullOrEmpty(Model.Message)) {
<div class="column is-half-desktop is-two-thirds-tablet is-full-mobile notification is-info">
<button class="delete" onclick="this.parentElement.remove()"></button>
@Html.Raw(Model.Message)
</div>
} else {
<div class="column is-full has-text-centered">
<h1 class="title is-2 has-text-danger">URL not found</h1>
<h2 class="subtitle is-4">The given ID does not exist, it may have expired or been deleted.</h2>
<a class="button is-primary is-medium" asp-page="Urls">Back to URLs</a>
</div>
}
} else {
<div class="column is-half-desktop is-two-thirds-tablet is-full-mobile">
<dl class="">
<dt>ID</dt>
<dd>@Model.UrlRedirect.Id</dd>
<dt>URL-Target</dt>
<dd>@Model.UrlRedirect.Target</dd>
</dl>
<form class="buttons" method="post">
<input type="hidden" asp-for="Id" />
<button type="submit" class="button is-danger">Delete</button>
</form>
</div>
}
</div>

46
Pages/Inspect.cshtml.cs Normal file
View file

@ -0,0 +1,46 @@
using JustShortIt.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Caching.Distributed;
namespace JustShortIt.Pages;
[Authorize]
public class InspectModel : PageModel {
[BindProperty(Name = "id", SupportsGet = true)]
public string? Id { get; set; } = string.Empty;
[BindProperty(Name="message")]
public string? Message { get; set; }
public UrlRedirect? UrlRedirect { get; set; }
private IDistributedCache Db { get; }
public InspectModel(IDistributedCache db) {
Db = db;
}
public async Task<IActionResult> OnPostAsync() {
if (Id == null) return await OnGet(null, $"Delete request without ID, aborted.");
await Db.RemoveAsync(Id);
return await OnGet(null, $"ID '{Id}' successfully deleted.");
}
public async Task<IActionResult> OnGet(string? id, string? message) {
if (id is null && message is null) return RedirectToPage("Urls");
Id = id;
Message = message;
if (Id is not null) {
string? url = await Db.GetStringAsync(Id);
if (url is not null)
UrlRedirect = new UrlRedirect(Id, url, string.Empty);
}
return Page();
}
}