72 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text.Json.Serialization;
namespace CORP_MAUI.Models;
/// <summary>
/// Модель поста/новости
/// </summary>
public class Post
{
public int Id { get; set; }
[JsonPropertyName("title")]
public string Title { get; set; } = string.Empty;
[JsonPropertyName("text")]
public string? Text { get; set; }
private string _content = string.Empty;
[JsonPropertyName("body")]
public string Content
{
get => !string.IsNullOrWhiteSpace(_content) ? _content : (Text ?? string.Empty);
set => _content = value;
}
[JsonPropertyName("image_url")]
public string? ImageUrl { get; set; }
[JsonPropertyName("image")]
public string? Image { get; set; }
[JsonIgnore]
public string? DisplayImageUrl
{
get
{
string? url = !string.IsNullOrEmpty(ImageUrl) ? ImageUrl : Image;
if (string.IsNullOrEmpty(url)) return null;
// Если ссылка уже абсолютная - возвращаем как есть
if (url.StartsWith("http", StringComparison.OrdinalIgnoreCase)) return url;
// Если ссылка относительная - добавляем домен
// Обрабатываем случай, когда url начинается со / или без
string cleanUrl = url.TrimStart('/');
return $"https://corp.robotail.pro/{cleanUrl}";
}
}
[JsonPropertyName("date")]
public DateTime? Date { get; set; }
[JsonIgnore]
public DateTime DisplayDate => (CreatedAt.Year > 2000 ? CreatedAt : (Date ?? DateTime.Now)).ToLocalTime();
public User? Author { get; set; }
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }
[JsonPropertyName("updated_at")]
public DateTime UpdatedAt { get; set; }
[JsonPropertyName("likes_count")]
public int LikesCount { get; set; }
[JsonPropertyName("comments_count")]
public int CommentsCount { get; set; }
public List<string> Tags { get; set; } = new();
}