Documentation
¶
Index ¶
- Constants
- Variables
- func CurrentId(ctx context.Context) (int, error)
- func WithUser(ctx context.Context, user User) context.Context
- type EventCalendarType
- type GoogleCalendarSettings
- type GoogleCalendarSettingsDTO
- type Handler
- func (h *Handler) CreateUser(w http.ResponseWriter, r *http.Request)
- func (h *Handler) CurrentUser(w http.ResponseWriter, r *http.Request)
- func (h *Handler) DeletePhoto(w http.ResponseWriter, r *http.Request)
- func (h *Handler) DeleteUser(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetAvailableUsers(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetPhoto(w http.ResponseWriter, r *http.Request)
- func (h *Handler) IsUsernameAvailable(w http.ResponseWriter, r *http.Request)
- func (h *Handler) UpdateUser(w http.ResponseWriter, r *http.Request)
- func (h *Handler) UploadPhoto(w http.ResponseWriter, r *http.Request)
- type Provider
- type Repo
- type Service
- type Settings
- type SettingsDTO
- type StubUserRepository
- func (s *StubUserRepository) CreateUser(ctx context.Context, user User) (int, error)
- func (s *StubUserRepository) DeleteUser(ctx context.Context, id int) error
- func (s *StubUserRepository) GetAllUsers(ctx context.Context) ([]User, error)
- func (s *StubUserRepository) GetUser(ctx context.Context, id int) (User, error)
- func (s *StubUserRepository) GetUserByUid(ctx context.Context, uid string) (User, error)
- func (s *StubUserRepository) IsUsernameAvailable(ctx context.Context, username string) (bool, error)
- func (s *StubUserRepository) UpdateUser(ctx context.Context, userId int, user User) (User, error)
- type User
- type UserDTO
- type UserRepoImpl
- func (u *UserRepoImpl) CreateUser(ctx context.Context, user User) (int, error)
- func (u *UserRepoImpl) DeleteUser(ctx context.Context, id int) error
- func (u *UserRepoImpl) GetAllUsers(ctx context.Context) ([]User, error)
- func (u *UserRepoImpl) GetUser(ctx context.Context, id int) (User, error)
- func (u *UserRepoImpl) GetUserByUid(ctx context.Context, uid string) (User, error)
- func (u *UserRepoImpl) IsUsernameAvailable(ctx context.Context, username string) (bool, error)
- func (u *UserRepoImpl) UpdateUser(ctx context.Context, userId int, user User) (User, error)
- type UserServiceImpl
- func (u *UserServiceImpl) CreateUser(ctx context.Context, user User) (User, error)
- func (u *UserServiceImpl) DeleteUser(ctx context.Context, id int) error
- func (u *UserServiceImpl) DeleteUserPhoto(ctx context.Context) error
- func (u *UserServiceImpl) GetAllUsers(ctx context.Context) ([]User, error)
- func (u *UserServiceImpl) GetCurrentUser(ctx context.Context) (User, error)
- func (u *UserServiceImpl) GetCurrentUserPhoto(ctx context.Context) ([]byte, error)
- func (u *UserServiceImpl) GetUser(ctx context.Context, id int) (User, error)
- func (u *UserServiceImpl) GetUserByUid(ctx context.Context, uid string) (User, error)
- func (u *UserServiceImpl) GetUserPhoto(_ context.Context, id int) ([]byte, error)
- func (u *UserServiceImpl) IsUsernameAvailable(ctx context.Context, username string) (bool, error)
- func (u *UserServiceImpl) StoreUserPhoto(ctx context.Context, photo []byte) error
- func (u *UserServiceImpl) UpdateUser(ctx context.Context, user User) (User, error)
Constants ¶
const UserKey contextKey = "user"
Variables ¶
var ErrNoUser = errors.New("user not found")
var ErrUserDataInvalid = errors.New("user data invalid")
var ErrUserNotFound = errors.New("user not found")
Functions ¶
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 (*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 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 (*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) GetUserByUid ¶
func (*StubUserRepository) IsUsernameAvailable ¶
func (*StubUserRepository) UpdateUser ¶
type User ¶
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 (*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) GetUserByUid ¶
func (*UserRepoImpl) IsUsernameAvailable ¶
func (*UserRepoImpl) UpdateUser ¶
type UserServiceImpl ¶
type UserServiceImpl struct {
// contains filtered or unexported fields
}
func NewUserService ¶
func NewUserService(repo Repo) *UserServiceImpl
func (*UserServiceImpl) CreateUser ¶
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) GetUserByUid ¶
func (*UserServiceImpl) GetUserPhoto ¶
func (*UserServiceImpl) IsUsernameAvailable ¶
func (*UserServiceImpl) StoreUserPhoto ¶
func (u *UserServiceImpl) StoreUserPhoto(ctx context.Context, photo []byte) error