ApiMapper.cs
4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using RobotProductionSystem.Api.Contracts;
using RobotProductionSystem.Api.Domain;
namespace RobotProductionSystem.Api.Services;
public static class ApiMapper
{
public static AuthUserDto ToAuthUser(User user) =>
new(user.Id, user.Username, user.Name, user.Email, user.Roles.Select(x => x.Role).ToArray(), user.Station,
user.AvatarSrc is null && user.AvatarAlt is null ? null : new AvatarDto(user.AvatarSrc, user.AvatarAlt));
public static object ToMember(Member member) => new
{
member.Name,
member.Username,
member.Role,
Avatar = new { Src = member.AvatarSrc, Alt = member.AvatarAlt },
member.Email,
member.Bio
};
public static SettingsProfileDto ToProfile(SettingsProfile profile) =>
new(profile.Name, profile.Email, profile.Username, profile.Avatar, profile.Bio);
public static SettingsNotificationsDto ToNotifications(SettingsNotification notifications) => new()
{
Email = notifications.Email,
Desktop = notifications.Desktop,
ProductUpdates = notifications.ProductUpdates,
WeeklyDigest = notifications.WeeklyDigest,
ImportantUpdates = notifications.ImportantUpdates
};
public static object ToDeviceType(DeviceType item) => new
{
item.Id,
item.Name,
item.Model,
item.Category,
item.LengthMm,
item.WidthMm,
item.HeightMm,
item.WeightKg,
item.HasBattery,
item.BatterySpec,
item.Description,
UpdatedAt = item.UpdatedAt.ToString("O")
};
public static object ToWorkOrder(WorkOrder item) => new
{
item.Id,
item.OrderNo,
item.DeviceCode,
item.BatchNo,
item.Line,
item.OwnerUsername,
item.OwnerName,
PlannedDate = item.PlannedDate.ToString("yyyy-MM-dd"),
item.Status,
Progress = new { item.CompletedSn, item.TotalSn },
Audit = new
{
item.CreatedBy,
CreatedAt = item.CreatedAt.ToString("O"),
item.UpdatedBy,
UpdatedAt = item.UpdatedAt.ToString("O"),
item.LastAction,
LastActionAt = item.LastActionAt.ToString("O"),
item.LastActionBy
},
Events = item.Events.OrderByDescending(x => x.At).Select(x => new
{
Id = x.EventId,
x.Action,
x.FromStatus,
x.ToStatus,
x.Operator,
At = x.At.ToString("O"),
x.Remark
})
};
public static object ToSnItem(SnItem item) => new
{
item.Id,
item.Sn,
item.WorkOrderNo,
item.Status,
CurrentStep = ProcessStepMapper.ToApiValue(item.CurrentStep),
item.ExceptionStatus,
item.FreezeReason,
item.ScrapReason,
Audit = new
{
item.CreatedBy,
CreatedAt = item.CreatedAt.ToString("O"),
item.UpdatedBy,
UpdatedAt = item.UpdatedAt.ToString("O"),
item.LastAction,
LastActionAt = item.LastActionAt.ToString("O"),
item.LastActionBy
},
Events = item.Events.OrderByDescending(x => x.At).Select(x => new
{
Id = x.EventId,
x.Action,
x.FromStatus,
x.ToStatus,
x.Operator,
At = x.At.ToString("O"),
x.Reason,
x.EvidencePath,
CurrentStep = ProcessStepMapper.ToApiValue(x.CurrentStep),
x.ExceptionStatus
})
};
public static object ToOperationTask(OperationTask item) => new
{
item.Id,
item.WorkOrderNo,
item.Sn,
StepName = ProcessStepMapper.ToApiValue(item.StepName),
item.Workstation,
item.Device,
item.Operator,
StartedAt = item.StartedAt?.ToString("O"),
EndedAt = item.EndedAt?.ToString("O"),
item.Result,
item.Status,
item.NextAction,
AuditEvents = item.AuditEvents.OrderByDescending(x => x.At).Select(x => new
{
Id = x.EventId,
x.Action,
x.FromStatus,
x.ToStatus,
x.Operator,
At = x.At.ToString("O"),
x.Remark,
x.EvidencePath,
x.NextAction
})
};
}