isn/src/isnd/Data/Packages/Package.cs

73 lines
2.1 KiB
C#
Raw Normal View History

2021-08-23 03:21:08 +01:00
using System;
2021-06-21 23:38:05 +01:00
using System.Collections.Generic;
2021-05-16 14:07:14 +01:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2022-08-20 12:54:24 +01:00
using System.Linq;
using isnd.Data.Catalog;
2022-07-10 17:05:05 +01:00
using isnd.Interfaces;
2021-06-21 23:38:05 +01:00
using Newtonsoft.Json;
2021-05-16 14:07:14 +01:00
2022-07-10 17:05:05 +01:00
namespace isnd.Data.Packages
2021-05-16 14:07:14 +01:00
{
2021-08-23 03:21:08 +01:00
public class Package : IObject
2021-05-16 14:07:14 +01:00
{
[Key][Required]
2021-09-05 15:44:47 +01:00
[StringLength(1024)]
2022-07-10 17:05:05 +01:00
public string Id { get; set; }
2021-05-16 14:07:14 +01:00
[Required]
[ForeignKey("Owner")]
public string OwnerId { get; set; }
2021-06-21 23:38:05 +01:00
[StringLength(1024)]
2021-05-16 14:07:14 +01:00
public string Description { get; set; }
2021-06-21 23:38:05 +01:00
2021-08-23 03:21:08 +01:00
public bool Public { get ; set;}
2021-06-21 23:38:05 +01:00
[JsonIgnore]
2021-05-16 14:07:14 +01:00
virtual public ApplicationUser Owner { get; set; }
2021-06-21 23:38:05 +01:00
[JsonIgnore]
public virtual List<PackageVersion> Versions { get; set; }
2021-08-28 18:41:22 +01:00
/// <summary>
2022-07-03 14:50:57 +01:00
/// Latest version at put, posted,
/// or even deletion when no more active version.
2021-08-28 18:41:22 +01:00
/// </summary>
/// <value></value>
[Required][JsonIgnore]
public long CommitNId { get; set ; }
[NotMapped]
public string CommitId { get => CommitNId.ToString(); }
[ForeignKey("CommitNId")]
public virtual Commit LatestVersion{ get; set; }
2021-08-23 03:21:08 +01:00
public DateTime CommitTimeStamp { get; set; }
2022-09-23 20:34:51 +01:00
/// <summary>
/// Returns the leaf
/// </summary>
/// <param name="bid">base url tu use for building the id property</param>
/// <returns></returns>
2022-09-24 12:32:00 +01:00
public RegistrationLeaf ToLeave(string bid)
2022-08-20 12:54:24 +01:00
{
2022-09-23 20:34:51 +01:00
if (Versions.Count == 0) throw new Exception("NO VERSION");
2022-08-20 12:54:24 +01:00
var v = Versions.First();
RegistrationLeaf leave = new RegistrationLeaf
{
2022-09-25 02:24:21 +01:00
Id = bid + Id + "/" + v.FullString + ".json",
2022-08-20 12:54:24 +01:00
PackageContent = v.NugetLink,
Entry = new CatalogEntry
{
2022-09-23 20:34:51 +01:00
Id = bid + Id + ".json",
2022-08-20 12:54:24 +01:00
idp = Id,
version = v.FullString,
authors = $"{Owner.FullName} <${Owner.Email}>"
}
};
return leave;
}
2021-05-16 14:07:14 +01:00
}
}