50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package internal
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
type User struct {
|
|
Id int `json:"-" db:"id"`
|
|
Name string `json:"name" binding:"required"`
|
|
Username string `json:"username" binding:"required"`
|
|
Password string `json:"password" binding:"required"`
|
|
UserRole string `json:"-" db:"role"`
|
|
}
|
|
|
|
type AuthUser struct {
|
|
Username string `json:"username" binding:"required"`
|
|
Password string `json:"password" binding:"required"`
|
|
}
|
|
|
|
type RefreshTokenRequest struct {
|
|
RefreshToken string `json:"refreshToken" binding:"required"`
|
|
}
|
|
|
|
type UserRole string
|
|
|
|
const (
|
|
Student UserRole = "student"
|
|
Teacher UserRole = "teacher"
|
|
Admin UserRole = "admin"
|
|
)
|
|
|
|
func (userrole UserRole) ToString() string {
|
|
return string(userrole)
|
|
}
|
|
|
|
var ErrInvalidRole = errors.New("invalid role")
|
|
|
|
func FromString(in string) (UserRole, error) {
|
|
switch in {
|
|
case Student.ToString():
|
|
return Student, nil
|
|
case Teacher.ToString():
|
|
return Teacher, nil
|
|
case Admin.ToString():
|
|
return Admin, nil
|
|
}
|
|
return Student, fmt.Errorf("%q is not a valid role: %w", in, ErrInvalidRole)
|
|
}
|