Created Woodpecker CI/CD deployment
- Created Dockerfile for packing up API and Web projects as Docker image
This commit is contained in:
14
API/YABA.Common/Attributes/ClaimNameAttribute.cs
Normal file
14
API/YABA.Common/Attributes/ClaimNameAttribute.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace YABA.Common.Attributes
|
||||
{
|
||||
public class ClaimNameAttribute : Attribute
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
|
||||
public ClaimNameAttribute(string name)
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
API/YABA.Common/DTOs/Bookmarks/BookmarkDTO.cs
Normal file
20
API/YABA.Common/DTOs/Bookmarks/BookmarkDTO.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using YABA.Common.DTOs.Tags;
|
||||
using YABA.Common.Interfaces;
|
||||
|
||||
namespace YABA.Common.DTOs.Bookmarks
|
||||
{
|
||||
public class BookmarkDTO : IBookmark
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTimeOffset CreatedOn { get; set; }
|
||||
public DateTimeOffset LastModified { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Note { get; set; }
|
||||
public bool IsHidden { get; set; }
|
||||
public string Url { get; set; }
|
||||
public List<TagDTO>? Tags { get; set; } = new List<TagDTO>();
|
||||
}
|
||||
}
|
||||
18
API/YABA.Common/DTOs/Bookmarks/CreateBookmarkRequestDTO.cs
Normal file
18
API/YABA.Common/DTOs/Bookmarks/CreateBookmarkRequestDTO.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using YABA.Common.Interfaces;
|
||||
|
||||
namespace YABA.Common.DTOs.Bookmarks
|
||||
{
|
||||
public class CreateBookmarkRequestDTO : IBookmark
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Note { get; set; }
|
||||
public bool IsHidden { get; set; }
|
||||
public IEnumerable<string>? Tags { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
||||
16
API/YABA.Common/DTOs/Bookmarks/UpdateBookmarkRequestDTO.cs
Normal file
16
API/YABA.Common/DTOs/Bookmarks/UpdateBookmarkRequestDTO.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using YABA.Common.Interfaces;
|
||||
|
||||
namespace YABA.Common.DTOs.Bookmarks
|
||||
{
|
||||
public class UpdateBookmarkRequestDTO : IBookmark
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Note { get; set; }
|
||||
public bool IsHidden { get; set; }
|
||||
public string? Url { get; set; }
|
||||
public IEnumerable<string>? Tags { get; set; }
|
||||
}
|
||||
}
|
||||
11
API/YABA.Common/DTOs/Tags/CreateTagDTO.cs
Normal file
11
API/YABA.Common/DTOs/Tags/CreateTagDTO.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace YABA.Common.DTOs.Tags
|
||||
{
|
||||
public class CreateTagDTO
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
public bool IsHidden { get; set; }
|
||||
}
|
||||
}
|
||||
9
API/YABA.Common/DTOs/Tags/TagDTO.cs
Normal file
9
API/YABA.Common/DTOs/Tags/TagDTO.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace YABA.Common.DTOs.Tags
|
||||
{
|
||||
public class TagDTO
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsHidden { get; set; }
|
||||
}
|
||||
}
|
||||
10
API/YABA.Common/DTOs/Tags/UpdateTagDTO.cs
Normal file
10
API/YABA.Common/DTOs/Tags/UpdateTagDTO.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace YABA.Common.DTOs.Tags
|
||||
{
|
||||
public class UpdateTagDTO
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public bool? IsHidden { get; set; }
|
||||
}
|
||||
}
|
||||
12
API/YABA.Common/DTOs/UserDTO.cs
Normal file
12
API/YABA.Common/DTOs/UserDTO.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace YABA.Common.DTOs
|
||||
{
|
||||
public class UserDTO
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public DateTimeOffset CreatedOn { get; set; }
|
||||
public DateTimeOffset LastModified { get; set; }
|
||||
}
|
||||
}
|
||||
9
API/YABA.Common/DTOs/WebsiteMetaDataDTO.cs
Normal file
9
API/YABA.Common/DTOs/WebsiteMetaDataDTO.cs
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
namespace YABA.Common.DTOs
|
||||
{
|
||||
public class WebsiteMetaDataDTO
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
}
|
||||
24
API/YABA.Common/Extensions/DictionaryExtensions.cs
Normal file
24
API/YABA.Common/Extensions/DictionaryExtensions.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YABA.Common.Extensions
|
||||
{
|
||||
public static class DictionaryExtensions
|
||||
{
|
||||
public static void AddRange<K, V>(this Dictionary<K, V> source, Dictionary<K, V> collection)
|
||||
{
|
||||
if (collection == null)
|
||||
{
|
||||
throw new ArgumentNullException("Collection is null");
|
||||
}
|
||||
|
||||
foreach (var item in collection)
|
||||
{
|
||||
if (!source.ContainsKey(item.Key))
|
||||
{
|
||||
source.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
API/YABA.Common/Extensions/EnumExtensions.cs
Normal file
40
API/YABA.Common/Extensions/EnumExtensions.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using YABA.Common.Attributes;
|
||||
using YABA.Common.Lookups;
|
||||
|
||||
namespace YABA.Common.Extensions
|
||||
{
|
||||
public static class EnumExtensions
|
||||
{
|
||||
private static readonly IEnumerable<CrudResultLookup> SuccessfulCrudStatuses = new List<CrudResultLookup>() {
|
||||
CrudResultLookup.CreateSucceeded,
|
||||
CrudResultLookup.UpdateSucceeded,
|
||||
CrudResultLookup.DeleteSucceeded,
|
||||
CrudResultLookup.RetrieveSuccessful
|
||||
};
|
||||
|
||||
public static TAttribute GetAttribute<TAttribute>(this Enum value) where TAttribute : Attribute
|
||||
{
|
||||
var enumType = value.GetType();
|
||||
var name = Enum.GetName(enumType, value);
|
||||
return enumType.GetField(name).GetCustomAttributes(false).OfType<TAttribute>().SingleOrDefault();
|
||||
}
|
||||
|
||||
public static string GetDisplayName(this Enum enumValue)
|
||||
{
|
||||
return enumValue.GetAttribute<DisplayAttribute>().Name;
|
||||
}
|
||||
|
||||
public static string GetClaimName(this ClaimsLookup claimLookup)
|
||||
{
|
||||
return claimLookup.GetAttribute<ClaimNameAttribute>().Name;
|
||||
}
|
||||
|
||||
public static bool IsCrudResultSuccessful(this CrudResultLookup importStatusLookup) => SuccessfulCrudStatuses.Contains(importStatusLookup);
|
||||
|
||||
public static bool IsCrudResultFailure(this CrudResultLookup importStatusLookup) => !SuccessfulCrudStatuses.Contains(importStatusLookup);
|
||||
}
|
||||
}
|
||||
18
API/YABA.Common/Extensions/UserIdentityExtensions.cs
Normal file
18
API/YABA.Common/Extensions/UserIdentityExtensions.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.Security.Claims;
|
||||
using System.Security.Principal;
|
||||
using YABA.Common.Lookups;
|
||||
|
||||
namespace YABA.Common.Extensions
|
||||
{
|
||||
public static class UserIdentityExtensions
|
||||
{
|
||||
public static string GetUserId(this IIdentity identity) => GetCustomClaim(identity, ClaimsLookup.UserId);
|
||||
public static string GetAuthProviderId(this IIdentity identity) => GetCustomClaim(identity, ClaimsLookup.AuthProviderId);
|
||||
|
||||
public static string GetCustomClaim(this IIdentity identity, ClaimsLookup claim)
|
||||
{
|
||||
var claimsIdentity = identity as ClaimsIdentity;
|
||||
return claimsIdentity.FindFirst(claim.GetClaimName())?.Value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
API/YABA.Common/Interfaces/IBookmark.cs
Normal file
12
API/YABA.Common/Interfaces/IBookmark.cs
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
namespace YABA.Common.Interfaces
|
||||
{
|
||||
public interface IBookmark
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Note { get; set; }
|
||||
public bool IsHidden { get; set; }
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
||||
22
API/YABA.Common/Lookups/ClaimsLookup.cs
Normal file
22
API/YABA.Common/Lookups/ClaimsLookup.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using YABA.Common.Attributes;
|
||||
|
||||
namespace YABA.Common.Lookups
|
||||
{
|
||||
public enum ClaimsLookup
|
||||
{
|
||||
[ClaimNameAttribute("https://dev.iwanaga.moe/api/auth_provider_id")]
|
||||
AuthProviderId = 1,
|
||||
|
||||
[ClaimNameAttribute("https://dev.iwanaga.moe/api/email_address")]
|
||||
UserEmail = 2,
|
||||
|
||||
[ClaimNameAttribute("https://dev.iwanaga.moe/api/email_verified")]
|
||||
IsEmailConfirmed = 3,
|
||||
|
||||
[ClaimNameAttribute("https://dev.iwanaga.moe/api/username")]
|
||||
Username = 4,
|
||||
|
||||
[ClaimNameAttribute("https://dev.iwanaga.moe/api/id")]
|
||||
UserId = 5
|
||||
}
|
||||
}
|
||||
34
API/YABA.Common/Lookups/CrudResultLookup.cs
Normal file
34
API/YABA.Common/Lookups/CrudResultLookup.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace YABA.Common.Lookups
|
||||
{
|
||||
public enum CrudResultLookup
|
||||
{
|
||||
[Display(Name = "Insert failed")]
|
||||
CreateFailed = 1,
|
||||
|
||||
[Display(Name = "Insert succeeded")]
|
||||
CreateSucceeded = 2,
|
||||
|
||||
[Display(Name = "Insert failed. Entry already exists")]
|
||||
CreateFailedEntryExists = 3,
|
||||
|
||||
[Display(Name = "Update failed")]
|
||||
UpdateFailed = 4,
|
||||
|
||||
[Display(Name = "Update succeeded")]
|
||||
UpdateSucceeded = 5,
|
||||
|
||||
[Display(Name = "Delete failed")]
|
||||
DeleteFailed = 6,
|
||||
|
||||
[Display(Name = "Delete succeeded")]
|
||||
DeleteSucceeded = 7,
|
||||
|
||||
[Display(Name = "Retrieve failed")]
|
||||
RetrieveFailed = 8,
|
||||
|
||||
[Display(Name = "Retrieve successful")]
|
||||
RetrieveSuccessful = 9
|
||||
}
|
||||
}
|
||||
12
API/YABA.Common/YABA.Common.csproj
Normal file
12
API/YABA.Common/YABA.Common.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user