-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(SPV-1425): add validation for paymail #933
base: main
Are you sure you want to change the base?
Conversation
Manual TestsβΉοΈ Remember to ask team members to perform manual tests and to assign |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #933 +/- ##
==========================================
- Coverage 35.69% 35.18% -0.52%
==========================================
Files 419 427 +8
Lines 19853 20095 +242
==========================================
- Hits 7087 7070 -17
- Misses 12175 12434 +259
Partials 591 591
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 31 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
@@ -32,8 +33,8 @@ func (s *APIAdminUsers) AddPaymailToUser(c *gin.Context, id string) { | |||
newPaymail := &paymailsmodels.NewPaymail{ | |||
Alias: alias, | |||
Domain: domain, | |||
PublicName: requestBody.PublicName, | |||
Avatar: requestBody.AvatarURL, | |||
PublicName: lo.IfF(requestBody.PublicName != nil, func() string { return *requestBody.PublicName }).Else(""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposition for simplifying this is to have function like below:
package lox
import "github.com/samber/lo"
type IfElse[T any] interface {
Else(result T) T
}
func Elvis[T any](value *T) IfElse[T] {
return lo.IfF[T](value != nil, func() T {
return *value
})
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've applied it to this part, but it doesn't help with other IfF where the logic is more complicated as it requires mapping.
We could do an additional function that also accepts a function but the only benefit of that is to skip the != nil check.
so right now we have
return &transaction.OutputAnnotation{
Bucket: bucket.Name(from.Bucket),
Paymail: lo.IfF(
from.Paymail != nil,
func() *transaction.PaymailAnnotation {
return &transaction.PaymailAnnotation{
Sender: from.Paymail.Sender,
Receiver: from.Paymail.Receiver,
Reference: from.Paymail.Reference,
}
},
).Else(nil),
}
We could have
return &transaction.OutputAnnotation{
Bucket: bucket.Name(from.Bucket),
Paymail: lox.UnwrapAndMap(
from.Paymail,
func() *transaction.PaymailAnnotation {
return &transaction.PaymailAnnotation{
Sender: from.Paymail.Sender,
Receiver: from.Paymail.Receiver,
Reference: from.Paymail.Reference,
}
},
).Else(nil),
}
LMKWYT
Pull Request Checklist