mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.0 KiB
62 lines
2.0 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using Newtonsoft.Json;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.Validation;
|
|
|
|
namespace Squidex.Web
|
|
{
|
|
public abstract class Resource
|
|
{
|
|
[LocalizedRequired]
|
|
[Display(Description = "The links.")]
|
|
[JsonProperty("_links")]
|
|
public Dictionary<string, ResourceLink> Links { get; } = new Dictionary<string, ResourceLink>();
|
|
|
|
public void AddSelfLink(string href)
|
|
{
|
|
AddGetLink("self", href);
|
|
}
|
|
|
|
public void AddGetLink(string rel, string href, string? metadata = null)
|
|
{
|
|
AddLink(rel, "GET", href, metadata);
|
|
}
|
|
|
|
public void AddPatchLink(string rel, string href, string? metadata = null)
|
|
{
|
|
AddLink(rel, "PATCH", href, metadata);
|
|
}
|
|
|
|
public void AddPostLink(string rel, string href, string? metadata = null)
|
|
{
|
|
AddLink(rel, "POST", href, metadata);
|
|
}
|
|
|
|
public void AddPutLink(string rel, string href, string? metadata = null)
|
|
{
|
|
AddLink(rel, "PUT", href, metadata);
|
|
}
|
|
|
|
public void AddDeleteLink(string rel, string href, string? metadata = null)
|
|
{
|
|
AddLink(rel, "DELETE", href, metadata);
|
|
}
|
|
|
|
public void AddLink(string rel, string method, string href, string? metadata = null)
|
|
{
|
|
Guard.NotNullOrEmpty(rel, nameof(rel));
|
|
Guard.NotNullOrEmpty(href, nameof(href));
|
|
Guard.NotNullOrEmpty(method, nameof(method));
|
|
|
|
Links[rel] = new ResourceLink { Href = href, Method = method, Metadata = metadata };
|
|
}
|
|
}
|
|
}
|
|
|