retroactiune/Retroactiune.Core/Entities/Feedback.cs

54 lines
1.8 KiB
C#
Raw Normal View History

2021-07-04 12:24:57 +00:00
using System;
2021-07-24 16:04:07 +00:00
using System.Diagnostics.CodeAnalysis;
2021-07-04 12:24:57 +00:00
using System.Text.Json.Serialization;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace Retroactiune.Core.Entities
2021-06-09 21:03:07 +00:00
{
2021-07-04 12:24:57 +00:00
/// <summary>
/// Feedback is the feedback given to the <see cref="FeedbackReceiver"/>.
/// </summary>
2021-06-09 21:03:07 +00:00
public class Feedback
{
public Feedback()
{
Id = ObjectId.GenerateNewId().ToString();
CreatedAt = DateTime.UtcNow;
}
2021-07-24 16:04:07 +00:00
2021-07-04 12:24:57 +00:00
[BsonId, JsonPropertyName("id")]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[JsonPropertyName("feedback_receiver_id")]
[BsonRepresentation(BsonType.ObjectId)]
public string FeedbackReceiverId { get; set; }
2021-07-24 16:04:07 +00:00
[JsonPropertyName("rating")] public uint Rating { get; set; }
2021-07-04 12:24:57 +00:00
[JsonPropertyName("description")] public string Description { get; set; }
[JsonPropertyName("created_at")] public DateTime CreatedAt { get; set; }
2021-07-24 16:04:07 +00:00
private bool Equals(Feedback other)
{
return Id == other.Id && FeedbackReceiverId == other.FeedbackReceiverId && Rating == other.Rating &&
Description == other.Description && CreatedAt - other.CreatedAt < TimeSpan.FromSeconds(1);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Feedback) obj);
}
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")]
public override int GetHashCode()
{
return HashCode.Combine(Id, FeedbackReceiverId, Rating, Description, CreatedAt);
}
2021-06-09 21:03:07 +00:00
}
}