You are not logged in.
Pages: 1
TUserDTO = packed record
ID: TID;
LogonName: RawUtf8;
DisplayName: RawUtf8;
InviteCode: RawUtf8;
ReferralCode: RawUtf8;
GroupName: RawUtf8;
Email: RawUtf8;
Phone: RawUtf8;
AvatarURL: RawUtf8;
Gender: TGenderTypeEnum;
Birthdate: TTimeLog;
Country: RawUtf8;
Province: RawUtf8;
City: RawUtf8;
...
end; lazarus + mormot 2 + mongodb
How to Elegantly Validate Input Length?
Offline
The TSynFilter and TSynValidation classes are currently for ORM only...
You could be tempted to define a reusable function() returning an enumeration or a string to make it on the client/DTO side.
But since it may be very depending of each use case of this DTO, it may not be easy to reuse this function.
Perhaps, the cleanest is to put the logic on the server side, having the application layer check the DTO sent by the client, depending on its actual context call.
With an application layer, the API method/URI is tied to the application context, so it knows enough about the context to validate the input.
And only having basic validation, e.g. at the UI level, for most obvious issue.
This would ensure that the very same logic could be reuse if you use another kind of client (e.g. web app).
Of course, there will be final context validation at persistence level, because your persistence service would not trust the application layer, and could reject length.
Note that input length is likely to be depending on the backend database. It is better in 2026 to have no size limit on the database field length.
Offline
class procedure TOrmUser.InternalDefineModel(Props: TOrmProperties);
begin
inherited InternalDefineModel(Props);
AddFilterOrValidate('Phone', TSynValidatePhone.Create);
AddFilterOrValidate('Email', TSynValidateEmail.Create);
...
end; Is this how it's written?
Offline
Pages: 1