| | | 1 | | using KT.Modules.Report.Core.Domain; |
| | | 2 | | using System.Text.Json.Serialization; |
| | | 3 | | |
| | | 4 | | namespace KT.Modules.Report.Presentation.Dto.WebSocket |
| | | 5 | | { |
| | | 6 | | |
| | | 7 | | internal class LocationAdd |
| | | 8 | | { |
| | | 9 | | public float Latitude { get; set; } |
| | | 10 | | public float Longitude { get; set; } |
| | | 11 | | public Locality Locality { get; set; } |
| | | 12 | | public required string Neighbourhood { get; set; } |
| | | 13 | | } |
| | | 14 | | [JsonDerivedType(typeof(ReportDataAdd))] |
| | | 15 | | [JsonDerivedType(typeof(ReportDataDelete))] |
| | | 16 | | internal class ReportData |
| | | 17 | | { |
| | | 18 | | |
| | | 19 | | } |
| | | 20 | | internal class ReportDataAdd : ReportData |
| | | 21 | | { |
| | 2 | 22 | | public required string Id { get; set; } |
| | 2 | 23 | | public string UserId { get; set; } |
| | 2 | 24 | | public LocationAdd Location { get; set; } |
| | 2 | 25 | | public ReportType Type { get; set; } |
| | 2 | 26 | | public string? Description { get; set; } |
| | 2 | 27 | | public string? Title { get; set; } |
| | 2 | 28 | | public DateTime CreatedAt { get; set; } |
| | 2 | 29 | | public DateTime UpdatedAt { get; set; } |
| | | 30 | | |
| | | 31 | | public static ReportDataAdd fromDomain (Core.Domain.Report report) |
| | 1 | 32 | | { |
| | 1 | 33 | | var location = new LocationAdd |
| | 1 | 34 | | { |
| | 1 | 35 | | Latitude = report.Location.Latitude, |
| | 1 | 36 | | Longitude = report.Location.Longitude, |
| | 1 | 37 | | Locality = report.Location.Locality, |
| | 1 | 38 | | Neighbourhood = report.Location.Neighbourhood |
| | 1 | 39 | | }; |
| | | 40 | | |
| | 1 | 41 | | return new ReportDataAdd |
| | 1 | 42 | | { |
| | 1 | 43 | | Id = report.Id, |
| | 1 | 44 | | UserId = report.UserId, |
| | 1 | 45 | | Location = location, |
| | 1 | 46 | | Type = report.Type, |
| | 1 | 47 | | Description = report.Description, |
| | 1 | 48 | | Title = report.Title, |
| | 1 | 49 | | CreatedAt = report.CreatedAt, |
| | 1 | 50 | | UpdatedAt = report.UpdatedAt, |
| | 1 | 51 | | }; |
| | 1 | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | internal class ReportDataDelete : ReportData |
| | | 56 | | { |
| | | 57 | | public required string Id { get; set; } |
| | | 58 | | |
| | | 59 | | public static ReportDataDelete fromDomain(Core.Domain.Report report) |
| | | 60 | | { |
| | | 61 | | return new ReportDataDelete |
| | | 62 | | { |
| | | 63 | | Id = report.Id, |
| | | 64 | | }; |
| | | 65 | | } |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | internal enum ReportNotificaionType |
| | | 69 | | { |
| | | 70 | | CREATE = 0, |
| | | 71 | | UPDATE = 1, |
| | | 72 | | DELETE = 2, |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | internal class ReportNotification |
| | | 76 | | { |
| | | 77 | | public required ReportNotificaionType Type { get; set; } |
| | | 78 | | public required ReportData Report { get; set; } |
| | | 79 | | |
| | | 80 | | |
| | | 81 | | |
| | | 82 | | public static ReportNotification Create (ReportData reportData, ReportNotificaionType type) |
| | | 83 | | { |
| | | 84 | | return new ReportNotification |
| | | 85 | | { |
| | | 86 | | Type = type, |
| | | 87 | | Report = reportData |
| | | 88 | | }; |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | public static ReportNotification DeleteReportNotification(string reportId) |
| | | 92 | | { |
| | | 93 | | return new ReportNotification |
| | | 94 | | { |
| | | 95 | | Type = ReportNotificaionType.DELETE, |
| | | 96 | | Report = new ReportDataDelete { Id = reportId } |
| | | 97 | | }; |
| | | 98 | | } |
| | | 99 | | } |
| | | 100 | | |
| | | 101 | | } |