Headless CMS and Content Managment Hub
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.
 
 
 
 
 

61 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;
namespace Squidex.Web
{
public abstract class Resource
{
[JsonProperty("_links")]
[Required]
[Display(Description = "The 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 };
}
}
}