all repos

onasty @ 26c7f05

a one-time notes service
8 files changed, 58 insertions(+), 3 deletions(-)
docs: add missing code comments (#185)

* docs(usersrv): add doc comments for the interface

* feat(events): add comments to public interface

* docs: config

* fix(cors): allow PATCH routes

* docs: add comments to public interfaces of store
Author: Olexandr Smirnov ss2316544@gmail.com
Committed by: Olexandr Smirnov olexsmir@gmail.com
Committed at: 2025-08-11 16:02:18 +0300
Change ID: olptkzqmvvnlnxupnypszlwlkrxpwrks
Parent: aebfa02
M internal/config/config.go

@@ -8,6 +8,7 @@ "strings"

"time" ) +// Environment represents current app environment. type Environment string func (e Environment) IsDevMode() bool {
M internal/events/events.go

@@ -11,6 +11,8 @@ natsHeaderErrorCode = "Nats-Service-Error-Code"

natsHeaderErrorMsg = "Nats-Service-Error" ) +var _ error = (*Error)(nil) + type Error struct { Code string Message string
M internal/events/mailermq/mailermq.go

@@ -12,7 +12,10 @@

const sendTopic = "mailer.send" type Mailer interface { + // SendVerificationEmail sends an email with a verification token to the user. SendVerificationEmail(ctx context.Context, input SendVerificationEmailRequest) error + + // SendPasswordResetEmail sends an email with a password reset token to the user. SendPasswordResetEmail(ctx context.Context, input SendPasswordResetEmailRequest) error }
M internal/service/usersrv/usersrv.go

@@ -22,26 +22,52 @@ "github.com/olexsmir/onasty/internal/store/rdb/usercache"

) type UserServicer interface { + // SignUp creates a new user and sends verification email. SignUp(ctx context.Context, inp dtos.SignUp) (uuid.UUID, error) + + // SignIn authenticates a user and returns access and refresh tokens. SignIn(ctx context.Context, inp dtos.SignIn) (dtos.Tokens, error) + + // RefreshTokens refreshes the access and refresh tokens using the provided refresh token. RefreshTokens(ctx context.Context, refreshToken string) (dtos.Tokens, error) + + // Logout logs out a user by deleting the session associated with the provided refresh token. Logout(ctx context.Context, userID uuid.UUID, refreshToken string) error + + // LogoutAll logs out a user by deleting all sessions associated with the user ID. LogoutAll(ctx context.Context, userID uuid.UUID) error + + // GetUserInfo retrieves user information by user ID. GetUserInfo(ctx context.Context, userID uuid.UUID) (dtos.UserInfo, error) + // ChangePassword changes the user's password. ChangePassword(ctx context.Context, userID uuid.UUID, inp dtos.ChangeUserPassword) error + + // RequestPasswordReset initiates a password reset process by sending a reset email. RequestPasswordReset(ctx context.Context, inp dtos.RequestResetPassword) error + + // ResetPassword resets the user's password using the provided reset token. ResetPassword(ctx context.Context, inp dtos.ResetPassword) error + // GetOAuthURL retrieves the OAuth URL for the specified provider. GetOAuthURL(providerName string) (dtos.OAuthRedirect, error) + + // HandleOAuthLogin handles the OAuth login process by exchanging the code for tokens. HandleOAuthLogin(ctx context.Context, providerName, code string) (dtos.Tokens, error) + // Verify verifies the user's email using the provided verification key. Verify(ctx context.Context, verificationKey string) error + + // ResendVerificationEmail resends the verification email to the user. ResendVerificationEmail(ctx context.Context, inp dtos.ResendVerificationEmail) error + // ParseJWTToken parses the JWT token and returns the payload. ParseJWTToken(token string) (jwtutil.Payload, error) + // CheckIfUserExists checks if a user exists by user ID. CheckIfUserExists(ctx context.Context, userID uuid.UUID) (bool, error) + + // CheckIfUserIsActivated checks if a user is activated by user ID. CheckIfUserIsActivated(ctx context.Context, userID uuid.UUID) (bool, error) }
M internal/store/psql/passwordtokrepo/passwordtokrepo.go

@@ -13,8 +13,14 @@ "github.com/olexsmir/onasty/internal/store/psqlutil"

) type PasswordResetTokenStorer interface { + // Create a new password reset token. Create(ctx context.Context, input models.ResetPasswordToken) error + // GetUserIDByTokenAndMarkAsUsed gets the token, and marks it as used. + // + // In case the token is not found, returns [model.ErrResetPasswordTokenNotFound] + // If token if used, or expired, returns [model.ErrResetPasswordTokenAlreadyUsed], + // or [models.ErrResetPasswordTokenExpired]. GetUserIDByTokenAndMarkAsUsed( ctx context.Context, token string,
M internal/store/psql/sessionrepo/sessionrepo.go

@@ -13,10 +13,19 @@ "github.com/olexsmir/onasty/internal/store/psqlutil"

) type SessionStorer interface { + // Set creates new session associated with user. Set(ctx context.Context, usedID uuid.UUID, refreshToken string, expiresAt time.Time) error + + // GetUserIDByRefreshToken returns user ID associated with the refresh token. GetUserIDByRefreshToken(ctx context.Context, refreshToken string) (uuid.UUID, error) + + // Update updates refresh token with newer. Update(ctx context.Context, userID uuid.UUID, refreshToken string, newRefreshToken string) error + + // Delete deletes session by user ID and their refresh token. Delete(ctx context.Context, userID uuid.UUID, refreshToken string) error + + // DeleteAllByUserID deletes all sessions associated with user. DeleteAllByUserID(ctx context.Context, userID uuid.UUID) error }
M internal/store/psql/userepo/userepo.go

@@ -12,14 +12,22 @@ "github.com/olexsmir/onasty/internal/store/psqlutil"

) type UserStorer interface { + // Create creates a new user. Create(ctx context.Context, inp models.User) (uuid.UUID, error) // GetByEmail returns user by email and password - // the password should be hashed + // the password should be hashed. GetByEmail(ctx context.Context, email string) (models.User, error) - GetUserIDByEmail(ctx context.Context, email string) (uuid.UUID, error) + + // GetByID returns user by id. + // If user not found, returns [models.ErrUserNotFound]. GetByID(ctx context.Context, userID uuid.UUID) (models.User, error) + // GetUserIDByEmail returns user id that is associated with their email. + // If user not found, returns [models.ErrUserNotFound]. + GetUserIDByEmail(ctx context.Context, email string) (uuid.UUID, error) + + // MakrUserAsActivated marks user as activated by their id MarkUserAsActivated(ctx context.Context, id uuid.UUID) error // ChangePassword changes user password from oldPassword to newPassword
M internal/transport/http/middlewares.go

@@ -11,7 +11,7 @@

func (t *Transport) corsMiddleware() gin.HandlerFunc { return cors.New(cors.Config{ AllowOrigins: t.corsAllowedOrigins, - AllowMethods: []string{"GET", "POST", "PUT", "DELETE"}, + AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"}, AllowHeaders: []string{"Authorization", "Content-Type"}, AllowCredentials: true, MaxAge: t.corsMaxAge,