Documentation
¶
Overview ¶
Package service ...
Index ¶
- Constants
- Variables
- func Normalize(v Validatable) error
- func ValidateCreate(v CreateRuler) error
- func ValidateUpdate(v UpdateRuler) error
- type AuthenticateOAuthUserInput
- type AuthenticateUserInput
- type ChangeDiff
- type ChangeUserPasswordInput
- type ChangeUsernameInput
- type ConfirmEmailChangeInput
- type ConfirmEmailInput
- type CreateChangeEmailRequestInput
- type CreateEmailConfirmationInput
- type CreateOAuthUserAccountInput
- type CreatePasswordResetRequestInput
- type CreateRuler
- type CreateUserSessionInput
- type DeleteUserInput
- type DeleteUserSessionInput
- type EntityChange
- type FindPasswordResetByTokenInput
- type FindUserByEmailInput
- type FindUserByIDInput
- type FindUserSessionByIDInput
- type GetOAuthUserAccountInput
- type GetUserAndSessionFromJWTInput
- type HardDeleteUserInput
- type ProlongUserSessionInput
- type RegisterUserInput
- type ResetPasswordInput
- type ResolveUserFromOAuthAccountInput
- type Service
- func (s *Service) ApplyChangeRequest(ctx context.Context, reqID ds.ID) (err error)
- func (s *Service) ApplyChangesToBook(ctx context.Context, changes []ChangeDiff, req *ds.EntityChangeRequest, ...) (err error)
- func (s *Service) ApplyChangesToEntity(ctx context.Context, e *ds.Entity, changes map[string]any) (err error)
- func (s *Service) ApplyChangesToPage(ctx context.Context, changes []ChangeDiff, req *ds.EntityChangeRequest, ...) (err error)
- func (s *Service) ApproveNewBook(ctx context.Context, book *ds.Book) (err error)
- func (s *Service) AttachTopics(ctx context.Context, entityID ds.ID, topics []ds.Topic) (err error)
- func (s *Service) AuthenticateOAuthUser(ctx context.Context, authAcc goth.User) (token string, err error)
- func (s *Service) AuthenticateUser(ctx context.Context, email, password string) (user *ds.User, token string, err error)
- func (s *Service) ChangeEntityStatus(ctx context.Context, entityID ds.ID, status ds.EntityStatus) error
- func (s *Service) ChangeUserPassword(ctx context.Context, userID ds.ID, oldPassword, newPassword string) (err error)
- func (s *Service) ChangeUsername(ctx context.Context, in ChangeUsernameInput) (err error)
- func (s *Service) CommitChangeRequest(ctx context.Context, req *ds.EntityChangeRequest) error
- func (s *Service) ConfirmEmail(ctx context.Context, code string) (err error)
- func (s *Service) ConfirmEmailChange(ctx context.Context, token string) (err error)
- func (s *Service) CreateBook(ctx context.Context, book *ds.Book) (err error)
- func (s *Service) CreateChangeEmailRequest(ctx context.Context, userID ds.ID, newEmail string) (err error)
- func (s *Service) CreateEmailConfirmation(ctx context.Context, userID ds.ID) (code string, err error)
- func (s *Service) CreateEntity(ctx context.Context, e *ds.Entity) error
- func (s *Service) CreateFile(ctx context.Context, f *ds.File) error
- func (s *Service) CreateOAuthUserAccount(ctx context.Context, m *ds.OAuthUserAccount) (err error)
- func (s *Service) CreatePage(ctx context.Context, page *ds.Page) (err error)
- func (s *Service) CreatePasswordResetRequest(ctx context.Context, emailAddr string) (err error)
- func (s *Service) CreateUserSession(ctx context.Context, userID ds.ID) (sess *ds.UserSession, err error)
- func (s *Service) DeleteBook(ctx context.Context, id ds.ID) error
- func (s *Service) DeleteFile(ctx context.Context, id ds.ID) error
- func (s *Service) DeleteUser(ctx context.Context, userID ds.ID, password string) (err error)
- func (s *Service) DeleteUserSession(ctx context.Context, id ds.ID) (err error)
- func (s *Service) EventLogChanges(ctx context.Context, id ds.ID) (changes any, err error)
- func (s *Service) FilterBooks(ctx context.Context, f ds.BooksFilter) (data []ds.Book, count int, err error)
- func (s *Service) FilterChangeRequests(ctx context.Context, f ds.ChangeRequestsFilter) (data []ds.EntityChangeRequest, count int, err error)
- func (s *Service) FilterEventLogs(ctx context.Context, f ds.EventLogsFilter) (data []ds.EventLog, count int, err error)
- func (s *Service) FilterFiles(ctx context.Context, f ds.FilesFilter) (data []ds.File, count int, err error)
- func (s *Service) FilterTopics(ctx context.Context, f ds.TopicsFilter) (data []ds.Topic, count int, err error)
- func (s *Service) FilterUsers(ctx context.Context, f ds.UsersFilter) (data []ds.User, count int, err error)
- func (s *Service) GetBookByID(ctx context.Context, id ds.ID) (*ds.Book, error)
- func (s *Service) GetBookByPublicID(ctx context.Context, publicID string) (*ds.Book, error)
- func (s *Service) GetBookByRef(ctx context.Context, ref any) (*ds.Book, error)
- func (s *Service) GetChangeRequestDiff(ctx context.Context, reqID ds.ID) (diffs []ChangeDiff, req *ds.EntityChangeRequest, err error)
- func (s *Service) GetDataProviderFromEntityType(ctx context.Context, id ds.ID, t ds.EntityType) (dp ds.DataProvider, err error)
- func (s *Service) GetEntityByID(ctx context.Context, id ds.ID) (*ds.Entity, error)
- func (s *Service) GetEntityChangeState(ctx context.Context, entityID ds.ID, data ds.DataProvider) (state *EntityChange, err error)
- func (s *Service) GetFileByHash(ctx context.Context, hash string) (*ds.File, error)
- func (s *Service) GetFileByID(ctx context.Context, id ds.ID) (*ds.File, error)
- func (s *Service) GetFilePreview(ctx context.Context, f *ds.File) (fh file.ReadSeekCloser, size int64, err error)
- func (s *Service) GetOAuthUserAccount(ctx context.Context, prov provider.Type, provUserID string) (m *ds.OAuthUserAccount, err error)
- func (s *Service) GetPageByID(ctx context.Context, id ds.ID) (*ds.Page, error)
- func (s *Service) GetPageByPublicID(ctx context.Context, id string) (*ds.Page, error)
- func (s *Service) GetPagesByPublicID(ctx context.Context, id ...string) ([]ds.Page, error)
- func (s *Service) GetPasswordResetByToken(ctx context.Context, token string) (prt *ds.PasswordResetToken, err error)
- func (s *Service) GetUserAndSessionFromJWT(ctx context.Context, token string) (user *ds.User, sess *ds.UserSession, err error)
- func (s *Service) GetUserByEmail(ctx context.Context, email string) (user *ds.User, err error)
- func (s *Service) GetUserByID(ctx context.Context, id ds.ID) (user *ds.User, err error)
- func (s *Service) GetUserSessionByID(ctx context.Context, id ds.ID) (sess *ds.UserSession, err error)
- func (s *Service) HardDeleteFileUnsafe(ctx context.Context, f *ds.File) error
- func (s *Service) HardDeleteUser(ctx context.Context, userID ds.ID) (err error)
- func (s *Service) LogAccountActivated(ctx context.Context, userID ds.ID) error
- func (s *Service) LogBookApproved(ctx context.Context, approvedBy ds.ID, book *ds.Book) error
- func (s *Service) LogBookRejected(ctx context.Context, rejectedBy ds.ID, note string, book *ds.Book) error
- func (s *Service) LogEmailChangeRequested(ctx context.Context, userID ds.ID) error
- func (s *Service) LogEmailChanged(ctx context.Context, userID ds.ID, oldEmail, newEmail string) error
- func (s *Service) LogEmailConfirmed(ctx context.Context, email string, userID ds.ID) error
- func (s *Service) LogEntityCreated(ctx context.Context, e *ds.Entity) error
- func (s *Service) LogEntityRenamed(ctx context.Context, userID, entityID ds.ID, oldTitle, newTitle any) error
- func (s *Service) LogEntityUpdated(ctx context.Context, userID, entityID ds.ID, title, changes any) error
- func (s *Service) LogPasswordChanged(ctx context.Context, userID ds.ID) error
- func (s *Service) LogPasswordChangedByResetRequest(ctx context.Context, userID ds.ID) error
- func (s *Service) LogPasswordResetRequest(ctx context.Context, userID ds.ID) error
- func (s *Service) LogUserRegistered(ctx context.Context, userID ds.ID) error
- func (s *Service) LogUsernameChanged(ctx context.Context, userID ds.ID, oldName, newName string) error
- func (s *Service) ProlongUserSession(ctx context.Context, id ds.ID) (err error)
- func (s *Service) RegisterUser(ctx context.Context, username, emailAddr, password string) (user *ds.User, err error)
- func (s *Service) RejectChangeRequest(ctx context.Context, id, reviewerID ds.ID, note string) (err error)
- func (s *Service) RejectNewBook(ctx context.Context, note string, book *ds.Book) (err error)
- func (s *Service) ReplaceTopicsUsingPublicIDs(ctx context.Context, e *ds.Entity, ids []string) (err error)
- func (s *Service) ResetPassword(ctx context.Context, token, password string) (err error)
- func (s *Service) ResolveUserFromOAuthAccount(ctx context.Context, authAcc goth.User) (user *ds.User, err error)
- func (s *Service) UpdateBook(ctx context.Context, id ds.ID, newBook *ds.Book) (req *ds.EntityChangeRequest, err error)
- func (s *Service) UpdateEntityChangeRequest(ctx context.Context, m *ds.EntityChangeRequest) (err error)
- func (s *Service) UpdateFilePreviewByHash(ctx context.Context, preview, hash string) error
- func (s *Service) UpdatePage(ctx context.Context, id string, newPage *ds.Page) (req *ds.EntityChangeRequest, err error)
- func (s *Service) UploadFile(ctx context.Context, args UploadFileArgs) (*ds.File, error)
- type UpdateRuler
- type UploadFileArgs
- type Validatable
Constants ¶
const ( // UsernameMinLen defines the minimum allowed length, in characters, for a user's username. UsernameMinLen = 2 // UsernameMaxLen defines the maximum allowed length, in characters, for a user's username. UsernameMaxLen = 30 // UserPasswordMinLen defines the minimum allowed length, in characters, for a user's password. UserPasswordMinLen = 6 )
const ( // UserWithThisEmailAlreadyExists is the specific error message for email validation failure during registration. UserWithThisEmailAlreadyExists = "User with this email already exists." // UsernameAlreadyTaken is the specific error message for username validation failure during registration. UsernameAlreadyTaken = "Username already taken" )
Variables ¶
var ( // ErrCoverIsNotABookCover indicates that the provided file // cannot be used as a book cover because it is not marked // or classified as a book cover. ErrCoverIsNotABookCover = errors.New("cover: not a book cover") // ErrCoverBelongsToAnotherUser indicates that the provided // cover file is owned by a different user and therefore // cannot be attached to the current user's book. ErrCoverBelongsToAnotherUser = errors.New("cover: not owner") // ErrBookIsNotUnderReview is returned when an operation requires a book // to be in the "under review" state. ErrBookIsNotUnderReview = errors.New("book is not under review") // ErrInvalidRefID is returned when a reference ID is neither a valid UUID nor string. ErrInvalidRefID = app.ErrUnprocessable("id must be UUID or string") )
var ( // ErrInvalidEntityStatus is returned when an unsupported or unknown // entity status value is encountered. ErrInvalidEntityStatus = errors.New("invalid entity status") // ErrInvalidEntityType is returned when an unsupported or unknown // entity type value is encountered. ErrInvalidEntityType = errors.New("invalid entity type") )
var ( // UsernameBasicRegex defines the basic character set allowed in a username (letters, numbers, dot, underscore, dash). UsernameBasicRegex = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`) // UsernameSpecialCharsRegex enforces a limit on the maximum number of special characters (dot, underscore, dash). UsernameSpecialCharsRegex = regexp.MustCompile(`^[^._-]*([._-][^._-]*){0,2}$`) )
var ( // ErrInvalidConfirmationCode is the specific error returned // when an email confirmation code is invalid or expired. ErrInvalidConfirmationCode = app.InputError{"code": "Invalid confirmation code"} // ErrInvalidPasswordResetToken ... ErrInvalidPasswordResetToken = app.ErrUnprocessable("password reset request is either expired or invalid") // ErrInvalidPassword is returned when a user tries to change their password // but provides an incorrect old password. ErrInvalidPassword = app.ErrUnprocessable("invalid password") // ErrInvalidChangeEmailToken ... ErrInvalidChangeEmailToken = app.ErrUnprocessable("change email request is expired or invalid") // ErrChangeEmailToSameEmail ... ErrChangeEmailToSameEmail = app.ErrUnprocessable("you already use this email, no change needed") // ErrInvalidJWT is returned when an authentication token is malformed, // invalidly signed, or contains unexpected claims. ErrInvalidJWT = app.ErrForbidden("invalid token") // ErrSessionExpired is returned when a JWT is validly signed but the associated // database session has expired based on its timestamp. ErrSessionExpired = app.ErrForbidden("session expired") )
var ( // ErrChangeRequestAlreadyCommited indicates that a change request has already been applied and cannot be modified. ErrChangeRequestAlreadyCommited = errors.New("change request already committed") )
var ( // ErrInvalidEmailOrPassword is returned when a user attempts to log in with credentials // that do not match any record. ErrInvalidEmailOrPassword = app.ErrUnprocessable("invalid email or password") )
var ( ErrPreviewUnavailable = errors.New("preview unavailable") )
Functions ¶
func Normalize ¶
func Normalize(v Validatable) error
Normalize prepares the input by sanitizing and validating it.
func ValidateCreate ¶
func ValidateCreate(v CreateRuler) error
ValidateCreate validates the given entity using its specific creation rules.
func ValidateUpdate ¶
func ValidateUpdate(v UpdateRuler) error
ValidateUpdate validates the given entity using its specific update rules.
Types ¶
type AuthenticateOAuthUserInput ¶
AuthenticateOAuthUserInput defines the input for OAuth user authentication.
func (*AuthenticateOAuthUserInput) Sanitize ¶
func (in *AuthenticateOAuthUserInput) Sanitize()
Sanitize trims whitespace from OAuth user fields.
func (*AuthenticateOAuthUserInput) Validate ¶
func (in *AuthenticateOAuthUserInput) Validate() error
Validate validates the OAuth authentication input against defined rules.
type AuthenticateUserInput ¶
type AuthenticateUserInput struct {
Email, Password string //nolint:gosec
}
AuthenticateUserInput defines the input for user authentication.
func (*AuthenticateUserInput) Sanitize ¶
func (in *AuthenticateUserInput) Sanitize()
Sanitize trims whitespace from email and password fields.
func (*AuthenticateUserInput) Validate ¶
func (in *AuthenticateUserInput) Validate() error
Validate validates the authentication input against defined rules.
type ChangeDiff ¶
type ChangeDiff struct {
Key string `json:"key"`
Type prop.Type `json:"type"`
Diff string `json:"diff,omitempty"`
Current any `json:"current,omitempty"`
Proposed any `json:"proposed,omitempty"`
}
ChangeDiff represents the difference between current and proposed values in an entity change request. For type "diff" Diff property should be set, for other types Current and Proposed should be set.
type ChangeUserPasswordInput ¶
ChangeUserPasswordInput defines the input for changing a user's password.
func (*ChangeUserPasswordInput) Sanitize ¶
func (in *ChangeUserPasswordInput) Sanitize()
Sanitize trims whitespace from password fields.
func (*ChangeUserPasswordInput) Validate ¶
func (in *ChangeUserPasswordInput) Validate() error
Validate validates the change password input against defined rules.
type ChangeUsernameInput ¶
ChangeUsernameInput defines the input for changing a user's username.
func (*ChangeUsernameInput) Sanitize ¶
func (in *ChangeUsernameInput) Sanitize()
Sanitize trims whitespace from the new username.
func (*ChangeUsernameInput) Validate ¶
func (in *ChangeUsernameInput) Validate() error
Validate validates the change username input against defined rules.
type ConfirmEmailChangeInput ¶
type ConfirmEmailChangeInput struct {
Token string
}
ConfirmEmailChangeInput defines the input for confirming an email change.
func (*ConfirmEmailChangeInput) Sanitize ¶
func (in *ConfirmEmailChangeInput) Sanitize()
Sanitize trims whitespace from the token.
func (*ConfirmEmailChangeInput) Validate ¶
func (in *ConfirmEmailChangeInput) Validate() error
Validate validates the email change confirmation input against defined rules.
type ConfirmEmailInput ¶
type ConfirmEmailInput struct {
Code string
}
ConfirmEmailInput defines the input for email confirmation.
func (*ConfirmEmailInput) Sanitize ¶
func (in *ConfirmEmailInput) Sanitize()
Sanitize trims whitespace from the confirmation code.
func (*ConfirmEmailInput) Validate ¶
func (in *ConfirmEmailInput) Validate() error
Validate validates the email confirmation input against defined rules.
type CreateChangeEmailRequestInput ¶
CreateChangeEmailRequestInput defines the input for creating an email change request.
func (*CreateChangeEmailRequestInput) Sanitize ¶
func (in *CreateChangeEmailRequestInput) Sanitize()
Sanitize trims whitespace from the new email.
func (*CreateChangeEmailRequestInput) Validate ¶
func (in *CreateChangeEmailRequestInput) Validate() error
Validate validates the email change request input against defined rules.
type CreateEmailConfirmationInput ¶
CreateEmailConfirmationInput defines the input for creating an email confirmation.
func (*CreateEmailConfirmationInput) Sanitize ¶
func (in *CreateEmailConfirmationInput) Sanitize()
Sanitize performs no sanitization for this input.
func (*CreateEmailConfirmationInput) Validate ¶
func (in *CreateEmailConfirmationInput) Validate() error
Validate validates the email confirmation input against defined rules.
type CreateOAuthUserAccountInput ¶
type CreateOAuthUserAccountInput struct {
*ds.OAuthUserAccount
}
CreateOAuthUserAccountInput defines the input for creating an OAuth user account.
func (*CreateOAuthUserAccountInput) Sanitize ¶
func (in *CreateOAuthUserAccountInput) Sanitize()
Sanitize trims whitespace from the provider user ID.
func (*CreateOAuthUserAccountInput) Validate ¶
func (in *CreateOAuthUserAccountInput) Validate() error
Validate validates the OAuth user account input against defined rules.
type CreatePasswordResetRequestInput ¶
type CreatePasswordResetRequestInput struct {
Email string
}
CreatePasswordResetRequestInput defines the input for creating a password reset request.
func (*CreatePasswordResetRequestInput) Sanitize ¶
func (in *CreatePasswordResetRequestInput) Sanitize()
Sanitize trims whitespace from the email.
func (*CreatePasswordResetRequestInput) Validate ¶
func (in *CreatePasswordResetRequestInput) Validate() error
Validate validates the password reset request input against defined rules.
type CreateRuler ¶
CreateRuler defines an interface for entities that provide validation rules for creation operations.
type CreateUserSessionInput ¶
CreateUserSessionInput defines the input for creating a user session.
func (*CreateUserSessionInput) Sanitize ¶
func (in *CreateUserSessionInput) Sanitize()
Sanitize performs no sanitization for this input.
func (*CreateUserSessionInput) Validate ¶
func (in *CreateUserSessionInput) Validate() error
Validate validates the user session input against defined rules.
type DeleteUserInput ¶
DeleteUserInput defines the input for deleting a user.
func (*DeleteUserInput) Sanitize ¶
func (in *DeleteUserInput) Sanitize()
Sanitize performs no sanitization for this input.
func (*DeleteUserInput) Validate ¶
func (in *DeleteUserInput) Validate() error
Validate validates the delete user input against defined rules.
type DeleteUserSessionInput ¶
DeleteUserSessionInput defines the input for deleting a user session.
func (*DeleteUserSessionInput) Sanitize ¶
func (in *DeleteUserSessionInput) Sanitize()
Sanitize performs no sanitization for this input.
func (*DeleteUserSessionInput) Validate ¶
func (in *DeleteUserSessionInput) Validate() error
Validate validates the delete session input (no validation rules defined).
type EntityChange ¶
type EntityChange struct {
ID ds.ID `json:"id"`
Data map[string]any `json:"data"`
Revision int `json:"revision"`
RevisionDate *time.Time `json:"revision_date"`
}
EntityChange represents the effective editable state of an entity.
type FindPasswordResetByTokenInput ¶
type FindPasswordResetByTokenInput struct {
Token string
}
FindPasswordResetByTokenInput defines the input for finding a password reset token.
func (*FindPasswordResetByTokenInput) Sanitize ¶
func (in *FindPasswordResetByTokenInput) Sanitize()
Sanitize trims whitespace from the token.
func (*FindPasswordResetByTokenInput) Validate ¶
func (in *FindPasswordResetByTokenInput) Validate() error
Validate validates the password reset token input against defined rules.
type FindUserByEmailInput ¶
type FindUserByEmailInput struct {
Email string
}
FindUserByEmailInput defines the input for finding a user by email.
func (*FindUserByEmailInput) Sanitize ¶
func (in *FindUserByEmailInput) Sanitize()
Sanitize trims whitespace from the email.
func (*FindUserByEmailInput) Validate ¶
func (in *FindUserByEmailInput) Validate() error
Validate validates the find user by email input against defined rules.
type FindUserByIDInput ¶
FindUserByIDInput defines the input for finding a user by ID.
func (*FindUserByIDInput) Sanitize ¶
func (in *FindUserByIDInput) Sanitize()
Sanitize performs no sanitization for this input.
func (*FindUserByIDInput) Validate ¶
func (in *FindUserByIDInput) Validate() error
Validate validates the find user by ID input against defined rules.
type FindUserSessionByIDInput ¶
FindUserSessionByIDInput defines the input for finding a user session by ID.
func (*FindUserSessionByIDInput) Sanitize ¶
func (in *FindUserSessionByIDInput) Sanitize()
Sanitize performs no sanitization for this input.
func (*FindUserSessionByIDInput) Validate ¶
func (in *FindUserSessionByIDInput) Validate() error
Validate validates the find session input (no validation rules defined).
type GetOAuthUserAccountInput ¶
GetOAuthUserAccountInput defines the input for getting an OAuth user account.
func (*GetOAuthUserAccountInput) Sanitize ¶
func (in *GetOAuthUserAccountInput) Sanitize()
Sanitize trims whitespace from the provider user ID.
func (*GetOAuthUserAccountInput) Validate ¶
func (in *GetOAuthUserAccountInput) Validate() error
Validate validates the OAuth user account input against defined rules.
type GetUserAndSessionFromJWTInput ¶
type GetUserAndSessionFromJWTInput struct {
Token string
}
GetUserAndSessionFromJWTInput defines the input for authenticating via JWT.
func (*GetUserAndSessionFromJWTInput) Sanitize ¶
func (in *GetUserAndSessionFromJWTInput) Sanitize()
Sanitize trims whitespace from the token.
func (*GetUserAndSessionFromJWTInput) Validate ¶
func (in *GetUserAndSessionFromJWTInput) Validate() error
Validate validates the JWT input against defined rules.
type HardDeleteUserInput ¶
type HardDeleteUserInput struct {
UserID int64
}
HardDeleteUserInput defines the input for hard deleting a user.
func (*HardDeleteUserInput) Sanitize ¶
func (in *HardDeleteUserInput) Sanitize()
Sanitize performs no sanitization for this input.
func (*HardDeleteUserInput) Validate ¶
func (in *HardDeleteUserInput) Validate() error
Validate validates the hard delete user input against defined rules.
type ProlongUserSessionInput ¶
ProlongUserSessionInput defines the input for prolonging a user session.
func (*ProlongUserSessionInput) Sanitize ¶
func (in *ProlongUserSessionInput) Sanitize()
Sanitize performs no sanitization for this input.
func (*ProlongUserSessionInput) Validate ¶
func (in *ProlongUserSessionInput) Validate() error
Validate validates the prolong session input (no validation rules defined).
type RegisterUserInput ¶
RegisterUserInput defines the expected input parameters for the user registration process.
func (*RegisterUserInput) Sanitize ¶
func (in *RegisterUserInput) Sanitize()
Sanitize trims whitespace from all registration fields.
func (*RegisterUserInput) Validate ¶
func (in *RegisterUserInput) Validate() error
Validate validates the registration input against defined rules.
type ResetPasswordInput ¶
ResetPasswordInput defines the input for resetting a password.
func (*ResetPasswordInput) Sanitize ¶
func (in *ResetPasswordInput) Sanitize()
Sanitize trims whitespace from token and password fields.
func (*ResetPasswordInput) Validate ¶
func (in *ResetPasswordInput) Validate() error
Validate validates the password reset input against defined rules.
type ResolveUserFromOAuthAccountInput ¶
ResolveUserFromOAuthAccountInput defines the input for resolving a user from an OAuth account.
func (*ResolveUserFromOAuthAccountInput) Sanitize ¶
func (in *ResolveUserFromOAuthAccountInput) Sanitize()
Sanitize trims whitespace from OAuth user fields.
func (*ResolveUserFromOAuthAccountInput) Validate ¶
func (in *ResolveUserFromOAuthAccountInput) Validate() error
Validate validates the OAuth user input against defined rules.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service holds dependencies required for the application's business logic layer.
func (*Service) ApplyChangeRequest ¶
ApplyChangeRequest applies a pending change request to its associated entity.
func (*Service) ApplyChangesToBook ¶
func (s *Service) ApplyChangesToBook(ctx context.Context, changes []ChangeDiff, req *ds.EntityChangeRequest, sendNotification bool) (err error)
ApplyChangesToBook applies approved changes from a change request to a book entity.
func (*Service) ApplyChangesToEntity ¶
func (s *Service) ApplyChangesToEntity(ctx context.Context, e *ds.Entity, changes map[string]any) (err error)
ApplyChangesToEntity applies approved changes to an entity's editable fields.
func (*Service) ApplyChangesToPage ¶
func (s *Service) ApplyChangesToPage(ctx context.Context, changes []ChangeDiff, req *ds.EntityChangeRequest, sendNotification bool) (err error)
ApplyChangesToPage applies approved changes from a change request to a page entity.
func (*Service) ApproveNewBook ¶
ApproveNewBook approves a newly submitted book.
func (*Service) AttachTopics ¶
AttachTopics associates the given topics with the specified entity.
func (*Service) AuthenticateOAuthUser ¶
func (s *Service) AuthenticateOAuthUser(ctx context.Context, authAcc goth.User) (token string, err error)
AuthenticateOAuthUser authenticates a user via OAuth provider credentials. It resolves the user account from the OAuth data and creates a new session token.
func (*Service) AuthenticateUser ¶
func (s *Service) AuthenticateUser(ctx context.Context, email, password string) ( user *ds.User, token string, err error)
AuthenticateUser authenticates a user using their email and password.
func (*Service) ChangeEntityStatus ¶
func (s *Service) ChangeEntityStatus(ctx context.Context, entityID ds.ID, status ds.EntityStatus) error
ChangeEntityStatus updates the status of the given entity.
func (*Service) ChangeUserPassword ¶
func (s *Service) ChangeUserPassword(ctx context.Context, userID ds.ID, oldPassword, newPassword string) (err error)
ChangeUserPassword handles the logic for an authenticated user to change their own password.
func (*Service) ChangeUsername ¶
func (s *Service) ChangeUsername(ctx context.Context, in ChangeUsernameInput) (err error)
ChangeUsername handles the logic for changing a user's username.
func (*Service) CommitChangeRequest ¶
CommitChangeRequest marks a change request as committed in the database.
func (*Service) ConfirmEmail ¶
ConfirmEmail confirms an email address by validating the provided code, setting the email_confirmed flag for the associated user, and then deleting the used confirmation record.
func (*Service) ConfirmEmailChange ¶
ConfirmEmailChange handles the logic for finalizing an email change via a token.
func (*Service) CreateBook ¶
CreateBook handles the transactional creation of a book, with its base entity and logs.
func (*Service) CreateChangeEmailRequest ¶
func (s *Service) CreateChangeEmailRequest(ctx context.Context, userID ds.ID, newEmail string) (err error)
CreateChangeEmailRequest handles the business logic for a user initiating an email change.
func (*Service) CreateEmailConfirmation ¶
func (s *Service) CreateEmailConfirmation(ctx context.Context, userID ds.ID) (code string, err error)
CreateEmailConfirmation creates a new ds.EmailConfirmation for given user.
func (*Service) CreateEntity ¶
CreateEntity validates and creates a new entity in the database.
func (*Service) CreateFile ¶
CreateFile ...
func (*Service) CreateOAuthUserAccount ¶
CreateOAuthUserAccount creates a new user session object.
func (*Service) CreatePage ¶
CreatePage handles creation of a page.
func (*Service) CreatePasswordResetRequest ¶
CreatePasswordResetRequest handles the logic for initiating a password reset.
func (*Service) CreateUserSession ¶
func (s *Service) CreateUserSession(ctx context.Context, userID ds.ID) (sess *ds.UserSession, err error)
CreateUserSession creates a new user session object.
func (*Service) DeleteBook ¶
DeleteBook deletes an existing book by its ID.
func (*Service) DeleteFile ¶
DeleteFile deletes a file.
func (*Service) DeleteUser ¶
DeleteUser handles the logic for soft-deleting a user account.
func (*Service) DeleteUserSession ¶
DeleteUserSession removes a user session record from the database using its ID.
func (*Service) EventLogChanges ¶
EventLogChanges returns the changes data from an event log's metadata.
func (*Service) FilterBooks ¶
func (s *Service) FilterBooks(ctx context.Context, f ds.BooksFilter) (data []ds.Book, count int, err error)
FilterBooks retrieves a paginated list of books matching the given filter.
func (*Service) FilterChangeRequests ¶
func (s *Service) FilterChangeRequests(ctx context.Context, f ds.ChangeRequestsFilter) (data []ds.EntityChangeRequest, count int, err error)
FilterChangeRequests retrieves a paginated list of change requests matching the given filter.
func (*Service) FilterEventLogs ¶
func (s *Service) FilterEventLogs(ctx context.Context, f ds.EventLogsFilter) (data []ds.EventLog, count int, err error)
FilterEventLogs retrieves a paginated list of event logs matching the given filter.
func (*Service) FilterFiles ¶
func (s *Service) FilterFiles(ctx context.Context, f ds.FilesFilter) (data []ds.File, count int, err error)
FilterFiles ...
func (*Service) FilterTopics ¶
func (s *Service) FilterTopics(ctx context.Context, f ds.TopicsFilter) (data []ds.Topic, count int, err error)
FilterTopics retrieves a paginated list of topics matching the given filter.
func (*Service) FilterUsers ¶
func (s *Service) FilterUsers(ctx context.Context, f ds.UsersFilter) (data []ds.User, count int, err error)
FilterUsers retrieves a filtered list of users based on the provided filter criteria.
func (*Service) GetBookByID ¶
GetBookByID retrieves a book record from the database by its ID.
func (*Service) GetBookByPublicID ¶
GetBookByPublicID retrieves a book record from the database by its public ID.
func (*Service) GetBookByRef ¶
GetBookByRef returns a book by a reference of unknown type.
The reference may be either:
- ds.ID (internal UUID-based identifier), or
- string, representing either a UUID or a public identifier (e.g. "book_ABCXYZ").
func (*Service) GetChangeRequestDiff ¶
func (s *Service) GetChangeRequestDiff(ctx context.Context, reqID ds.ID) (diffs []ChangeDiff, req *ds.EntityChangeRequest, err error)
GetChangeRequestDiff retrieves a change request and computes the diff between proposed and current values. Returns the diff containing both proposed changes and current values, along with the change request.
func (*Service) GetDataProviderFromEntityType ¶
func (s *Service) GetDataProviderFromEntityType(ctx context.Context, id ds.ID, t ds.EntityType) (dp ds.DataProvider, err error)
GetDataProviderFromEntityType retrieves an entity by ID and type, returning it as a DataProvider interface.
func (*Service) GetEntityByID ¶
GetEntityByID retrieves an Entity by its ID from the database.
func (*Service) GetEntityChangeState ¶
func (s *Service) GetEntityChangeState(ctx context.Context, entityID ds.ID, data ds.DataProvider) (state *EntityChange, err error)
GetEntityChangeState returns the effective state of an entity for the current user.
If the user has no pending change request for the given entity, it returns the original entity data with revision 0. If a pending change request exists, its diff is applied on top of the provided data, and the resulting state, revision, and last update time are returned.
func (*Service) GetFileByHash ¶
GetFileByHash retrieves a file by its ID.
func (*Service) GetFileByID ¶
GetFileByID retrieves a file by its ID.
func (*Service) GetFilePreview ¶
func (s *Service) GetFilePreview(ctx context.Context, f *ds.File) (fh file.ReadSeekCloser, size int64, err error)
GetFilePreview ...
func (*Service) GetOAuthUserAccount ¶
func (s *Service) GetOAuthUserAccount( ctx context.Context, prov provider.Type, provUserID string) (m *ds.OAuthUserAccount, err error)
GetOAuthUserAccount retrieves an OAuth user account by provider and provider user ID.
func (*Service) GetPageByID ¶
GetPageByID retrieves a page by its ID from the database.
func (*Service) GetPageByPublicID ¶
GetPageByPublicID retrieves a page by its public ID.
func (*Service) GetPagesByPublicID ¶
GetPagesByPublicID retrieves pages by given public IDs.
func (*Service) GetPasswordResetByToken ¶
func (s *Service) GetPasswordResetByToken(ctx context.Context, token string) (prt *ds.PasswordResetToken, err error)
GetPasswordResetByToken retrieves a password reset token from the database and validates it.
func (*Service) GetUserAndSessionFromJWT ¶
func (s *Service) GetUserAndSessionFromJWT(ctx context.Context, token string) ( user *ds.User, sess *ds.UserSession, err error)
GetUserAndSessionFromJWT checks the associated session's validity and retrieves the corresponding user record.
func (*Service) GetUserByEmail ¶
GetUserByEmail retrieves a user record from the database by their email address.
func (*Service) GetUserByID ¶
GetUserByID retrieves a user record from the database by their ID.
func (*Service) GetUserSessionByID ¶
func (s *Service) GetUserSessionByID(ctx context.Context, id ds.ID) (sess *ds.UserSession, err error)
GetUserSessionByID retrieves a user session from the database using its ID.
func (*Service) HardDeleteFileUnsafe ¶
HardDeleteFileUnsafe permanently deletes a file. Note: This method does not check deletion prerequisites (e.g., permissions, ownership, or references) and is intended for internal use only (for example, background cleanup jobs). It must not be called from public API handlers. Hence the "Unsafe" suffix.
func (*Service) HardDeleteUser ¶
HardDeleteUser handles the logic for deleting a user account and relations.
func (*Service) LogAccountActivated ¶
LogAccountActivated records successful account activation.
func (*Service) LogBookApproved ¶
LogBookApproved writes event logs for a successfully approved book.
It creates two event log records:
- A private log indicating that the book was approved by reviewer.
- A public log for the book owner indicating that the book was added.
func (*Service) LogBookRejected ¶
func (s *Service) LogBookRejected(ctx context.Context, rejectedBy ds.ID, note string, book *ds.Book) error
LogBookRejected writes an event log for a rejected book.
func (*Service) LogEmailChangeRequested ¶
LogEmailChangeRequested records that a user has initiated an email change flow.
func (*Service) LogEmailChanged ¶
func (s *Service) LogEmailChanged(ctx context.Context, userID ds.ID, oldEmail, newEmail string) error
LogEmailChanged records a completed email address change for a user.
func (*Service) LogEmailConfirmed ¶
LogEmailConfirmed records successful email confirmation for a user.
func (*Service) LogEntityCreated ¶
LogEntityCreated records an event related to entity creation.
If the entity requires moderation, a hidden "entity_submitted" event is created. If the entity is already approved (e.g. created by an admin or trusted user), a public "entity_created" event is recorded immediately.
Public-facing feeds should only display the final "entity_created" event.
func (*Service) LogEntityRenamed ¶
func (s *Service) LogEntityRenamed(ctx context.Context, userID, entityID ds.ID, oldTitle, newTitle any) error
LogEntityRenamed records an entity rename event.
func (*Service) LogEntityUpdated ¶
func (s *Service) LogEntityUpdated(ctx context.Context, userID, entityID ds.ID, title, changes any) error
LogEntityUpdated records a public-facing entity update event.
func (*Service) LogPasswordChanged ¶
LogPasswordChanged records a password change initiated by the user while authenticated.
func (*Service) LogPasswordChangedByResetRequest ¶
LogPasswordChangedByResetRequest records a password change performed.
func (*Service) LogPasswordResetRequest ¶
LogPasswordResetRequest records that a user has requested a password reset.
func (*Service) LogUserRegistered ¶
LogUserRegistered records the creation of a user account.
func (*Service) LogUsernameChanged ¶
func (s *Service) LogUsernameChanged(ctx context.Context, userID ds.ID, oldName, newName string) error
LogUsernameChanged records a username change performed by the user.
func (*Service) ProlongUserSession ¶
ProlongUserSession updates the expiration time of an existing user session in the database.
func (*Service) RegisterUser ¶
func (s *Service) RegisterUser(ctx context.Context, username, emailAddr, password string) (user *ds.User, err error)
RegisterUser handles the complete user registration process.
func (*Service) RejectChangeRequest ¶
func (s *Service) RejectChangeRequest(ctx context.Context, id, reviewerID ds.ID, note string) (err error)
RejectChangeRequest rejects a pending change request with a review note.
func (*Service) RejectNewBook ¶
RejectNewBook rejects a newly submitted book.
func (*Service) ReplaceTopicsUsingPublicIDs ¶
func (s *Service) ReplaceTopicsUsingPublicIDs(ctx context.Context, e *ds.Entity, ids []string) (err error)
ReplaceTopicsUsingPublicIDs replaces all topics associated with an entity using public IDs.
func (*Service) ResetPassword ¶
ResetPassword handles the logic for resetting a user's password using a token.
func (*Service) ResolveUserFromOAuthAccount ¶
func (s *Service) ResolveUserFromOAuthAccount(ctx context.Context, authAcc goth.User) (user *ds.User, err error)
ResolveUserFromOAuthAccount attempts to find an existing user associated with an OAuth provider. 1. If the OAuth account exists, it returns the linked user. 2. If the OAuth account is missing but the email exists, it links the OAuth account to that user. 3. If neither exists, it creates a new user (with a unique username) and links the OAuth account.
func (*Service) UpdateBook ¶
func (s *Service) UpdateBook(ctx context.Context, id ds.ID, newBook *ds.Book) (req *ds.EntityChangeRequest, err error)
UpdateBook updates an existing book by its ID.
For admin users, changes are applied immediately. For non-admin users, a pending entity change request is created instead, and the update must be reviewed before being applied.
func (*Service) UpdateEntityChangeRequest ¶
func (s *Service) UpdateEntityChangeRequest(ctx context.Context, m *ds.EntityChangeRequest) (err error)
UpdateEntityChangeRequest creates or updates a pending entity change request.
If no pending change request exists for the given entity and user, a new one is created with revision 1. If a pending request already exists and the diff has changed, the existing request is updated and its revision is incremented. If the diff is identical, no action is performed.
func (*Service) UpdateFilePreviewByHash ¶
UpdateFilePreviewByHash ...
func (*Service) UpdatePage ¶
func (s *Service) UpdatePage(ctx context.Context, id string, newPage *ds.Page) (req *ds.EntityChangeRequest, err error)
UpdatePage updates an existing page identified by its public ID.
If the caller is an admin, changes are applied immediately and recorded in the entity change log.
func (*Service) UploadFile ¶
UploadFile ...
type UpdateRuler ¶
UpdateRuler defines an interface for entities that provide validation rules for update operations.
type UploadFileArgs ¶
type UploadFileArgs struct {
Name string
OwnerID ds.ID
Purpose ds.FilePurpose
Temp bool
File file.ReadSeekCloser
}
UploadFileArgs ...
type Validatable ¶
type Validatable interface {
Sanitize()
Validate() error
}
Validatable indicates that the struct can be validated.