user

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const UserKey contextKey = "user"

Variables

View Source
var ErrNoUser = errors.New("user not found")
View Source
var ErrUserDataInvalid = errors.New("user data invalid")
View Source
var ErrUserNotFound = errors.New("user not found")

Functions

func CurrentId

func CurrentId(ctx context.Context) (int, error)

CurrentId retrieves the current user's ID from the context. Returns ErrNoUser if ID not present in context.

func WithUser

func WithUser(ctx context.Context, user User) context.Context

Types

type EventCalendarType

type EventCalendarType string
const (
	KlokkuCalendar EventCalendarType = "klokku"
	GoogleCalendar EventCalendarType = "google"
)

type GoogleCalendarSettings

type GoogleCalendarSettings struct {
	CalendarId string
}

type GoogleCalendarSettingsDTO

type GoogleCalendarSettingsDTO struct {
	CalendarId string `json:"calendarId"`
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(userService Service) *Handler

func (*Handler) CreateUser

func (h *Handler) CreateUser(w http.ResponseWriter, r *http.Request)

CreateUser godoc @Summary Create a new user @Description Register a new user in the system @Tags User @Accept json @Produce json @Param user body UserDTO true "User" @Success 201 {object} UserDTO @Failure 400 {object} rest.ErrorResponse "Invalid request" @Failure 403 {string} string "User not found" @Router /api/user [post]

func (*Handler) CurrentUser

func (h *Handler) CurrentUser(w http.ResponseWriter, r *http.Request)

CurrentUser godoc @Summary Get current user @Description Retrieve the currently authenticated user's information @Tags User @Produce json @Success 200 {object} UserDTO @Failure 403 {string} string "User not found" @Failure 404 {string} string "User Not Found" @Router /api/user/current [get] @Security XUserId

func (*Handler) DeletePhoto

func (h *Handler) DeletePhoto(w http.ResponseWriter, r *http.Request)

DeletePhoto godoc @Summary Delete user photo @Description Remove the current user's profile photo @Tags User @Success 204 "No Content" @Failure 403 {string} string "User not found" @Router /api/user/current/photo [delete] @Security XUserId

func (*Handler) DeleteUser

func (h *Handler) DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser godoc @Summary Delete a user @Description Delete a user by UID @Tags User @Param userUid path string true "User UID" @Success 204 "No Content" @Failure 400 {string} string "Bad Request" @Failure 403 {string} string "User not found" @Router /api/user/{userUid} [delete]

func (*Handler) GetAvailableUsers

func (h *Handler) GetAvailableUsers(w http.ResponseWriter, r *http.Request)

GetAvailableUsers godoc @Summary Get all users @Description Retrieve a list of all registered users @Tags User @Produce json @Success 200 {array} UserDTO @Failure 403 {string} string "User not found" @Router /api/user [get]

func (*Handler) GetPhoto

func (h *Handler) GetPhoto(w http.ResponseWriter, r *http.Request)

GetPhoto godoc @Summary Get user photo @Description Retrieve a user's profile photo. If userUid is provided, gets that user's photo, otherwise gets current user's photo @Tags User @Produce image/jpeg @Param userUid path string false "User UID (optional)" @Success 200 {file} image/jpeg @Failure 400 {string} string "Bad Request" @Failure 403 {string} string "User not found" @Router /api/user/current/photo [get] @Router /api/user/{userUid}/photo [get]

func (*Handler) IsUsernameAvailable

func (h *Handler) IsUsernameAvailable(w http.ResponseWriter, r *http.Request)

IsUsernameAvailable godoc @Summary Check username availability @Description Check if a username is available for registration @Tags User @Produce json @Param username query string true "Username to check" @Success 200 {object} object{available=bool} @Failure 400 {object} rest.ErrorResponse "Username is required" @Router /api/user/name-availability [get]

func (*Handler) UpdateUser

func (h *Handler) UpdateUser(w http.ResponseWriter, r *http.Request)

UpdateUser godoc @Summary Update current user @Description Update the currently authenticated user's information @Tags User @Accept json @Produce json @Param user body UserDTO true "User" @Success 200 {object} UserDTO @Failure 400 {object} rest.ErrorResponse "Invalid request" @Failure 403 {string} string "User not found" @Router /api/user/current [put] @Security XUserId

func (*Handler) UploadPhoto

func (h *Handler) UploadPhoto(w http.ResponseWriter, r *http.Request)

UploadPhoto godoc @Summary Upload user photo @Description Upload a profile photo for the current user (max 3MB) @Tags User @Accept multipart/form-data @Param photo formData file true "User photo" @Success 200 "OK" @Failure 400 {object} rest.ErrorResponse "Image too large or invalid" @Failure 403 {string} string "User not found" @Router /api/user/current/photo [put] @Security XUserId

type Provider

type Provider interface {
	GetCurrentUser(ctx context.Context) (User, error)
}

type Repo

type Repo interface {
	CreateUser(ctx context.Context, user User) (int, error)
	GetUser(ctx context.Context, id int) (User, error)
	GetUserByUid(ctx context.Context, uid string) (User, error)
	UpdateUser(ctx context.Context, userId int, user User) (User, error)
	DeleteUser(ctx context.Context, id int) error
	GetAllUsers(ctx context.Context) ([]User, error)
	IsUsernameAvailable(ctx context.Context, username string) (bool, error)
}

type Service

type Service interface {
	GetCurrentUser(ctx context.Context) (User, error)
	CreateUser(ctx context.Context, user User) (User, error)
	GetUser(ctx context.Context, id int) (User, error)
	UpdateUser(ctx context.Context, user User) (User, error)
	GetUserByUid(ctx context.Context, uid string) (User, error)
	DeleteUser(ctx context.Context, id int) error
	GetAllUsers(ctx context.Context) ([]User, error)
	StoreUserPhoto(ctx context.Context, photo []byte) error
	GetUserPhoto(ctx context.Context, id int) ([]byte, error)
	GetCurrentUserPhoto(ctx context.Context) ([]byte, error)
	DeleteUserPhoto(ctx context.Context) error
	IsUsernameAvailable(ctx context.Context, username string) (bool, error)
}

type Settings

type Settings struct {
	Timezone          string
	WeekFirstDay      time.Weekday
	EventCalendarType EventCalendarType
	GoogleCalendar    GoogleCalendarSettings
	IgnoreShortEvents bool
}

type SettingsDTO

type SettingsDTO struct {
	Timezone          string                    `json:"timezone"`
	WeekStartDay      string                    `json:"weekStartDay"`
	EventCalendarType EventCalendarType         `json:"eventCalendarType"`
	GoogleCalendar    GoogleCalendarSettingsDTO `json:"googleCalendar"`
	IgnoreShortEvents bool                      `json:"ignoreShortEvents"`
}

type StubUserRepository

type StubUserRepository struct {
	// contains filtered or unexported fields
}

func NewStubUserRepository

func NewStubUserRepository() *StubUserRepository

func (*StubUserRepository) CreateUser

func (s *StubUserRepository) CreateUser(ctx context.Context, user User) (int, error)

func (*StubUserRepository) DeleteUser

func (s *StubUserRepository) DeleteUser(ctx context.Context, id int) error

func (*StubUserRepository) GetAllUsers

func (s *StubUserRepository) GetAllUsers(ctx context.Context) ([]User, error)

func (*StubUserRepository) GetUser

func (s *StubUserRepository) GetUser(ctx context.Context, id int) (User, error)

func (*StubUserRepository) GetUserByUid

func (s *StubUserRepository) GetUserByUid(ctx context.Context, uid string) (User, error)

func (*StubUserRepository) IsUsernameAvailable

func (s *StubUserRepository) IsUsernameAvailable(ctx context.Context, username string) (bool, error)

func (*StubUserRepository) UpdateUser

func (s *StubUserRepository) UpdateUser(ctx context.Context, userId int, user User) (User, error)

type User

type User struct {
	Id          int
	Uid         string
	Username    string
	DisplayName string
	PhotoUrl    string
	Settings    Settings
}

func CurrentUser

func CurrentUser(ctx context.Context) (User, error)

type UserDTO

type UserDTO struct {
	Uid         string      `json:"uid"`
	Username    string      `json:"username"`
	DisplayName string      `json:"displayName"`
	PhotoUrl    string      `json:"photoUrl"`
	Settings    SettingsDTO `json:"settings"`
}

type UserRepoImpl

type UserRepoImpl struct {
	// contains filtered or unexported fields
}

func NewUserRepo

func NewUserRepo(db *pgxpool.Pool) *UserRepoImpl

func (*UserRepoImpl) CreateUser

func (u *UserRepoImpl) CreateUser(ctx context.Context, user User) (int, error)

func (*UserRepoImpl) DeleteUser

func (u *UserRepoImpl) DeleteUser(ctx context.Context, id int) error

func (*UserRepoImpl) GetAllUsers

func (u *UserRepoImpl) GetAllUsers(ctx context.Context) ([]User, error)

func (*UserRepoImpl) GetUser

func (u *UserRepoImpl) GetUser(ctx context.Context, id int) (User, error)

func (*UserRepoImpl) GetUserByUid

func (u *UserRepoImpl) GetUserByUid(ctx context.Context, uid string) (User, error)

func (*UserRepoImpl) IsUsernameAvailable

func (u *UserRepoImpl) IsUsernameAvailable(ctx context.Context, username string) (bool, error)

func (*UserRepoImpl) UpdateUser

func (u *UserRepoImpl) UpdateUser(ctx context.Context, userId int, user User) (User, error)

type UserServiceImpl

type UserServiceImpl struct {
	// contains filtered or unexported fields
}

func NewUserService

func NewUserService(repo Repo) *UserServiceImpl

func (*UserServiceImpl) CreateUser

func (u *UserServiceImpl) CreateUser(ctx context.Context, user User) (User, error)

func (*UserServiceImpl) DeleteUser

func (u *UserServiceImpl) DeleteUser(ctx context.Context, id int) error

func (*UserServiceImpl) DeleteUserPhoto

func (u *UserServiceImpl) DeleteUserPhoto(ctx context.Context) error

func (*UserServiceImpl) GetAllUsers

func (u *UserServiceImpl) GetAllUsers(ctx context.Context) ([]User, error)

func (*UserServiceImpl) GetCurrentUser

func (u *UserServiceImpl) GetCurrentUser(ctx context.Context) (User, error)

func (*UserServiceImpl) GetCurrentUserPhoto

func (u *UserServiceImpl) GetCurrentUserPhoto(ctx context.Context) ([]byte, error)

func (*UserServiceImpl) GetUser

func (u *UserServiceImpl) GetUser(ctx context.Context, id int) (User, error)

func (*UserServiceImpl) GetUserByUid

func (u *UserServiceImpl) GetUserByUid(ctx context.Context, uid string) (User, error)

func (*UserServiceImpl) GetUserPhoto

func (u *UserServiceImpl) GetUserPhoto(_ context.Context, id int) ([]byte, error)

func (*UserServiceImpl) IsUsernameAvailable

func (u *UserServiceImpl) IsUsernameAvailable(ctx context.Context, username string) (bool, error)

func (*UserServiceImpl) StoreUserPhoto

func (u *UserServiceImpl) StoreUserPhoto(ctx context.Context, photo []byte) error

func (*UserServiceImpl) UpdateUser

func (u *UserServiceImpl) UpdateUser(ctx context.Context, user User) (User, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL