Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserExists = errors.New("user already exists") ErrInvalidCredentials = errors.New("invalid eamil or password") )
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func (*Handler) GetMe ¶
swagger:operation GET /me users getMe --- tags: [users] description: Get current authenticated user details security: - bearerAuth: [] responses:
200:
description: Successfully retrieved user details
schema:
type: object
properties:
id:
type: string
description: User ID in hex format
example: 5f7d8f9e0c1d2e3f4a5b6c7d
email:
type: string
format: email
example: user@example.com
role:
type: string
enum: [user, admin]
example: user
401:
description: Unauthorized - missing or invalid token
schema:
type: object
properties:
error:
type: string
example: unauthorized
func (*Handler) Login ¶
swagger:operation POST /login users login --- tags: [users] description: Authenticate a user parameters:
- name: body in: body required: true schema: {$ref: "#/definitions/LoginRequest"}
responses:
200:
description: Successfully authenticated
schema:
type: object
properties:
token:
type: string
description: JWT access token
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
user:
type: object
description: Authenticated user details
properties:
id:
type: string
description: User ID in hex format
example: 5f7d8f9e0c1d2e3f4a5b6c7d
email:
type: string
format: email
example: user@example.com
role:
type: string
enum: [user, admin]
example: user
400:
description: Invalid request format
schema:
type: object
properties:
error:
type: string
example: invalid email format
401:
description: Authentication failed
schema:
type: object
properties:
error:
type: string
example: invalid credentials
500:
description: Internal server error
schema:
type: object
properties:
error:
type: string
example: failed to generate auth token
func (*Handler) RegisterAdmin ¶
swagger:operation POST /admin/register admin registerAdmin --- tags: [admin] description: Register a new admin account (requires admin privileges) security: - bearerAuth: [] parameters:
- name: body in: body required: true schema: {$ref: "#/definitions/RegisterRequest"}
responses:
201:
description: Admin user created successfully
400:
description: Bad request
schema:
type: object
properties:
error:
type: string
example: "Invalid password format"
409:
description: Conflict
schema:
type: object
properties:
error:
type: string
example: "user already exists"
500:
description: Internal server error
schema:
type: object
properties:
error:
type: string
example: "failed to create admin user"
func (*Handler) RegisterUser ¶
swagger:operation POST /register users registerUser --- tags: [users] description: Register a new user account
parameters:
- name: body in: body description: User registration information required: true schema: {$ref: "#/definitions/RegisterRequest"}
responses:
201:
description: User created successfully
400:
description: Bad request
schema:
type: object
properties:
error:
type: string
example: "Invalid email format"
409:
description: Conflict
schema:
type: object
properties:
error:
type: string
example: "user already exists"
500:
description: Internal server error
schema:
type: object
properties:
error:
type: string
example: "failed to create user"
type LoginRequest ¶
type LoginRequest struct {
// Email of the user
// required: true
// example: user@example.com
Email string `json:"email" binding:"required,email"`
// Password of the user
// required: true
// example: password123
Password string `json:"password" binding:"required,min=8"`
}
swagger:model LoginRequest
type RegisterRequest ¶
type RegisterRequest struct {
// Email of the user
// required: true
// example: user@example.com
Email string `json:"email" binding:"required,email"`
// Password must be at least 8 characters long
// required: true
// example: password123
Password string `json:"password" binding:"required,min=8"`
}
swagger:model RegisterRequest
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(db *mongo.Database) *Repository
func (*Repository) CreateUser ¶
func (r *Repository) CreateUser(ctx context.Context, user *User) error
func (*Repository) GetUserByEmail ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repo *Repository) *Service