Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions src/LinkAce.NET/Entites/CreateLinkRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using JetBrains.Annotations;

namespace LinkAce.NET.Entites;

/// <summary>
/// Represents a link entity with various properties such as URL, title, description, and status.
/// </summary>
[PublicAPI]
public class CreateLinkRequest
{
/// <summary>
/// Gets or sets a value indicating whether the link check is disabled.
/// </summary>
public bool CheckDisabled { get; set; }
/// <summary>
/// Gets or sets the date and time when the link was created.
/// </summary>
public DateTime CreatedAt { get; set; }
/// <summary>
/// Gets or sets the date and time when the link was deleted, if applicable.
/// </summary>
public DateTime? DeletedAt { get; set; }
/// <summary>
/// Gets or sets the description of the link.
/// </summary>
public string? Description { get; set; }
/// <summary>
/// Gets or sets the icon associated with the link.
/// </summary>
public string? Icon { get; set; }
/// <summary>
/// Gets or sets the unique identifier for the link.
/// </summary>
public int Id { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the link is private.
/// </summary>
public bool IsPrivate { get; set; }
/// <summary>
/// Gets or sets the status of the link.
/// </summary>
public int Status { get; set; }
/// <summary>
/// Gets or sets the tags associated with the link.
/// </summary>
public string[]? Tags { get; set; }
/// <summary>
/// Gets or sets the title of the link.
/// </summary>
public string? Title { get; set; }
/// <summary>
/// Gets or sets the date and time when the link was last updated.
/// </summary>
public DateTime UpdatedAt { get; set; }
/// <summary>
/// Gets or sets the URL of the link.
/// </summary>
public string Url { get; set; }
/// <summary>
/// Gets or sets the user identifier associated with the link.
/// </summary>
public int UserId { get; set; }

public static implicit operator CreateLinkRequest(Link link)
{
return new CreateLinkRequest
{
CheckDisabled = link.CheckDisabled,
CreatedAt = link.CreatedAt,
DeletedAt = link.DeletedAt,
Description = link.Description,
Icon = link.Icon,
Id = link.Id,
IsPrivate = link.IsPrivate,
Status = link.Status,
Tags = link.Tags?.Select(tag => tag.Name).ToArray(),
Title = link.Title,
UpdatedAt = link.UpdatedAt,
Url = link.Url,
UserId = link.UserId
};
}
}
2 changes: 1 addition & 1 deletion src/LinkAce.NET/LinkAce.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.3</Version>
Expand Down
11 changes: 7 additions & 4 deletions src/LinkAce.NET/LinkAceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class LinkAceClient
{
private static string? _apiUrl;
private static HttpClient _client;
private JsonSerializerOptions _serializationOptions = new(JsonSerializerDefaults.Web){
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
};
/// <summary>
/// Initializes a new instance of the <see cref="LinkAceClient" /> class with the specified URL and HTTP client.
/// </summary>
Expand Down Expand Up @@ -46,12 +49,12 @@ public LinkAceClient(string linkAceUrl, string apiToken, HttpClient? client = nu
/// <summary>
/// Creates a new link.
/// </summary>
/// <param name="link">The link to create.</param>
/// <param name="createLinkRequest">The request to create a link.</param>
/// <returns>The HTTP response message.</returns>
public async Task<HttpResponseMessage?> CreateLink(Link link)
public async Task<HttpResponseMessage?> CreateLink(CreateLinkRequest createLinkRequest)
{
var response = await _client.PostAsync($"{_apiUrl}/links",
new StringContent(JsonSerializer.Serialize(link), Encoding.UTF8,
new StringContent(JsonSerializer.Serialize(createLinkRequest, _serializationOptions), Encoding.UTF8,
MediaTypeNames.Application.Json));
return response;
}
Expand Down Expand Up @@ -80,7 +83,7 @@ public LinkAceClient(string linkAceUrl, string apiToken, HttpClient? client = nu
public async Task<HttpResponseMessage?> UpdateLinkById(int id, Link link)
{
var response = await _client.PatchAsync($"{_apiUrl}/links/{id}",
new StringContent(JsonSerializer.Serialize(link), Encoding.UTF8,
new StringContent(JsonSerializer.Serialize(link, _serializationOptions), Encoding.UTF8,
MediaTypeNames.Application.Json));
return response;
}
Expand Down