Skip to content

Commit

Permalink
move LinkEditModel
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed Nov 16, 2023
1 parent 14a2019 commit 3849912
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/API/Features/CreateLinkCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Elf.Api.Data;
using Elf.Api.TokenGenerator;
using Elf.Shared;
using Microsoft.EntityFrameworkCore;

namespace Elf.Api.Features;
Expand Down
1 change: 1 addition & 0 deletions src/API/Features/EditLinkCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Elf.Api.Data;
using Elf.Shared;
using Microsoft.EntityFrameworkCore;

namespace Elf.Api.Features;
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/Components/Pages/EditLinkDialog.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@implements IDialogContentComponent<LinkEditModel>
@implements IDialogContentComponent<LinkEditModelUI>
@inject HttpClient Http
@inject IMessageService MessageService

Expand Down Expand Up @@ -40,7 +40,7 @@

@code {
[Parameter]
public LinkEditModel Content { get; set; } = default!;
public LinkEditModelUI Content { get; set; } = default!;

[CascadingParameter]
public FluentDialog Dialog { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions src/Admin/Components/Pages/Links.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ private async Task New()
PreventScroll = true
};

var editModel = new LinkEditModel() { IsEnabled = true, TTL = 3600 };
var editModel = new LinkEditModelUI { IsEnabled = true, TTL = 3600 };

IDialogReference dialog = await DialogService.ShowDialogAsync<EditLinkDialog>(editModel, parameters);
DialogResult result = await dialog.Result;

if (!result.Cancelled && result.Data is not null)
{
var diagResult = result.Data as LinkEditModel;
var diagResult = result.Data as LinkEditModelUI;

IsBusy = true;

Expand Down Expand Up @@ -259,7 +259,7 @@ private async Task Edit(LinkModel link)
PreventScroll = true
};

var editModel = new LinkEditModel()
var editModel = new LinkEditModelUI
{
OriginUrl = link.OriginUrl,
Note = link.Note,
Expand All @@ -275,7 +275,7 @@ private async Task Edit(LinkModel link)

if (!result.Cancelled && result.Data is not null)
{
var diagResult = result.Data as LinkEditModel;
var diagResult = result.Data as LinkEditModelUI;

IsBusy = true;

Expand Down
28 changes: 1 addition & 27 deletions src/Admin/Models/LinkModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,8 @@ public class LinkModel
public int Hits { get; set; }
}

public class LinkEditModel
public class LinkEditModelUI : LinkEditModel
{
[Required]
[MinLength(1)]
[MaxLength(256)]
[DataType(DataType.Url)]
[Display(Name = "Origin Url")]
public string OriginUrl { get; set; }

[Display(Name = "Note")]
public string Note { get; set; }

[Display(Name = "Aka")]
[MaxLength(32)]
[RegularExpression("(?!-)([a-z0-9-]+)",
ErrorMessage = "Aka can only accept lower case English letters (a-z) and numbers (0-9) with/out hyphen (-) in middle.")]
public string AkaName { get; set; }

[Required]
[Display(Name = "Enable")]
public bool IsEnabled { get; set; }

[Display(Name = "TTL (seconds)")]
[Range(0, 24 * 60 * 60)]
public int TTL { get; set; }

public string[] Tags { get; set; }

[JsonIgnore]
public IEnumerable<Tag> SelectedTags { get; set; } = Array.Empty<Tag>();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace Elf.Api.Models;
namespace Elf.Shared;

public class LinkEditModel
{
Expand Down

0 comments on commit 3849912

Please sign in to comment.