chore: port lab 1 solution

This commit is contained in:
kk10
2026-10-02 11:45:26 +03:00
parent 65003b6119
commit 2f279a1715
43 changed files with 2402 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
package dto
import (
"regexp"
"strings"
"time"
"unicode/utf8"
"github.com/google/uuid"
)
var usernamePattern = regexp.MustCompile(`^[a-z0-9_]{3,32}$`)
type CreateUserRequest struct {
Username string `json:"username"`
DisplayName string `json:"display_name"`
}
type UserResponse struct {
ID uuid.UUID `json:"id"`
Username string `json:"username"`
DisplayName string `json:"display_name"`
CreatedAt time.Time `json:"created_at"`
}
func (r CreateUserRequest) Validate() bool {
if !usernamePattern.MatchString(r.Username) {
return false
}
displayNameLength := utf8.RuneCountInString(r.DisplayName)
if strings.TrimSpace(r.DisplayName) == "" || displayNameLength > 100 {
return false
}
return true
}