Remove EnumExtensions.cs
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
namespace Hutopy.Web.Extensions;
|
||||
|
||||
public static class EnumExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a string to the specified enum type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TEnum">The type of the enum to convert to. Must be an enum.</typeparam>
|
||||
/// <param name="value">The string value to convert.</param>
|
||||
/// <param name="ignoreCase">Specifies whether the string comparison should ignore case. Default is true.</param>
|
||||
/// <returns>
|
||||
/// The corresponding enum value if the conversion is successful; otherwise, null if the string
|
||||
/// cannot be converted to the specified enum type.
|
||||
/// </returns>
|
||||
public static TEnum? ToEnum<TEnum>(this string value, bool ignoreCase = true) where TEnum : struct
|
||||
{
|
||||
if (Enum.TryParse(value, ignoreCase, out TEnum result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an enum value to its string representation.
|
||||
/// </summary>
|
||||
/// <typeparam name="TEnum">The type of the enum.</typeparam>
|
||||
/// <param name="enumValue">The enum value to convert.</param>
|
||||
/// <returns>The string representation of the enum value.</returns>
|
||||
public static string FromEnum<TEnum>(this TEnum enumValue) where TEnum : struct, Enum
|
||||
{
|
||||
return enumValue.ToString();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Hutopy.Web.Extensions;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Data.Enums;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
@@ -47,7 +46,16 @@ public class AddReaction(
|
||||
CancellationToken ct)
|
||||
{
|
||||
var content = await context.Contents.SingleAsync(x => x.Id == req.ContentId, ct);
|
||||
var reactionEnum = req.Reaction.ToEnum<Reaction>();
|
||||
Reaction? reactionEnum;
|
||||
if (Enum.TryParse(req.Reaction, true, out Reaction result))
|
||||
{
|
||||
reactionEnum = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
reactionEnum = null;
|
||||
}
|
||||
|
||||
var currentReaction = content.Reactions.SingleOrDefault(x => x.UserId == req.UserId);
|
||||
|
||||
// Already reacted or reaction didn't change, do nothing
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Hutopy.Web.Extensions;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Handlers.Models;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
@@ -44,7 +43,7 @@ public class GetContent(
|
||||
HtmlFileUrl = c.HtmlFileUrl ?? "",
|
||||
Reactions = c.Reactions.Select(x => new ReactionModel
|
||||
{
|
||||
Reaction = x.Reaction.FromEnum(), UserId = x.UserId, UserName = x.UserName
|
||||
Reaction = x.Reaction.ToString(), UserId = x.UserId, UserName = x.UserName
|
||||
}).ToList()
|
||||
})
|
||||
.SingleOrDefaultAsync(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Hutopy.Web.Extensions;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Handlers.Models;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
@@ -55,7 +54,7 @@ public class GetContentsByCreatorHandler(
|
||||
HtmlFileUrl = c.HtmlFileUrl ?? "",
|
||||
Reactions = c.Reactions.Select(x => new ReactionModel
|
||||
{
|
||||
Reaction = x.Reaction.FromEnum(),
|
||||
Reaction = x.Reaction.ToString(),
|
||||
UserId = x.UserId,
|
||||
UserName = x.UserName
|
||||
}).ToList()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Hutopy.Web.Extensions;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
using Hutopy.Web.Features.Contents.Handlers.Models;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
@@ -53,7 +52,7 @@ public class GetFeaturedContentsHandler(
|
||||
ThumbnailUrl = c.ThumbnailUrl,
|
||||
Reactions = c.Reactions.Select(x => new ReactionModel
|
||||
{
|
||||
Reaction = x.Reaction.FromEnum(),
|
||||
Reaction = x.Reaction.ToString(),
|
||||
UserId = x.UserId,
|
||||
UserName = x.UserName
|
||||
}).ToList()
|
||||
|
||||
Reference in New Issue
Block a user