feat: profile bio

This commit is contained in:
Krispire Admin
2026-08-07 23:47:03 +05:30
parent afcdd7ef19
commit 623935df22
8 changed files with 55 additions and 9 deletions
+17
View File
@@ -9,6 +9,7 @@ import (
"path"
"strings"
"time"
"unicode/utf8"
"github.com/prabhupadasays/spsays-bff/internal/model"
"github.com/prabhupadasays/spsays-bff/internal/repository"
@@ -43,6 +44,7 @@ type UpdateProfileInput struct {
Name *string
AvatarURL *string
Handle *string
Bio *string
Country *string
Sampradaya *string
Gender *string
@@ -53,6 +55,10 @@ type UpdateProfileInput struct {
PeakActiveTime *string
}
// MaxBioRunes caps the profile bio. Counted in runes so the limit means the
// same thing in every script. Keep in sync with the editor's counter.
const MaxBioRunes = 200
// validGenders is the accepted set; "" clears the field.
var validGenders = map[string]bool{"male": true, "female": true, "other": true}
@@ -87,6 +93,17 @@ func (s *UserService) UpdateProfile(ctx context.Context, id string, in UpdatePro
}
p.Handle = &clean
}
if in.Bio != nil {
// "" clears. Counted in runes, not bytes, so a devotee writing in
// Devanāgarī gets the same 200 characters as a Latin-script writer
// (len() would cut them off after ~66). Collapse the CRLF that
// Windows browsers submit so the count matches what the editor shows.
b := strings.TrimSpace(strings.ReplaceAll(*in.Bio, "\r\n", "\n"))
if utf8.RuneCountInString(b) > MaxBioRunes {
return nil, fmt.Errorf("bio too long (max %d characters)", MaxBioRunes)
}
p.Bio = &b
}
if in.Country != nil {
// "" clears; otherwise a 2-letter ISO-3166-1 alpha-2 code (the
// frontend dropdown only ever sends valid codes).