handlers

package
v0.0.0-...-f5dcb26 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrBadRequest

func ErrBadRequest(c *gin.Context, err string)

func ErrDatabaseFailed

func ErrDatabaseFailed(c *gin.Context, err string)

func ErrFailedGeneratingToken

func ErrFailedGeneratingToken(c *gin.Context, err string)

func ErrNotAuthenticated

func ErrNotAuthenticated(c *gin.Context, err string)

func ErrRecordNotFound

func ErrRecordNotFound(c *gin.Context, err string)

func ErrUnauthorizedUser

func ErrUnauthorizedUser(c *gin.Context, err string)

func ErrValidationFailed

func ErrValidationFailed(c *gin.Context, err map[string]string)

Types

type AuthControler

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

func NewAuthControler

func NewAuthControler() *AuthControler

func (*AuthControler) GetAdminRegisterHandler

func (ac *AuthControler) GetAdminRegisterHandler(c *gin.Context)

GetAdminRegisterHandler handles the registration of a new admin user @Summary Register a new admin user @Description Register a new admin user and return an authentication token @Tags auth @Accept json @Produce json @Param body body types.AdminRegisterParams true "Admin registration details" @Success 200 {string} string "Token generated successfully" @Success 401 {object} ErrorResponse "Failed to Authenticate" @Failure 400 {object} ErrorResponse "Provided with incorrect data" @Failure 500 {object} ErrorResponse "internal server error" @Router /auth/admin/register [post]

func (*AuthControler) LoginHandler

func (ar *AuthControler) LoginHandler(c *gin.Context)

LoginHandler handles user login @Summary User login @Description Authenticate a user and return an authentication token @Tags auth @Accept json @Produce json @Param body body types.LoginUser true "User login details" @Success 200 {object} map[string]interface{} "authenticated successfully" @Failure 400 {object} ErrorResponse "Provided with incorrect data" @Failure 401 {object} ErrorResponse "username or password is incorrect" @Failure 500 {object} ErrorResponse "internal server error" @Router /auth/login [post]

func (*AuthControler) RegiserHandler

func (ar *AuthControler) RegiserHandler(c *gin.Context)

RegiserHandler handles the registration of a new user @Summary Register a new user @Description Register a new user and return an authentication token @Tags auth @Accept json @Produce json @Param body body types.CreateUserParams true "User registration details" @Success 201 {object} map[string]interface{} "successfuly registered" @Failure 400 {object} ErrorResponse "Validation failed or bad request" @Failure 409 {object} ErrorResponse "Conflict whit the current state" @Failure 422 {object} ErrorResponse "Provided with invalid data" @Failure 500 {object} ErrorResponse "Internal server error" @Router /auth/register [post]

type ErrorResponse

type ErrorResponse struct {
	Error   int    `json:"error"`
	Message string `json:"message"`
}

type PostController

type PostController struct {
	PostRepository repository.PostgresPostRepo
}

func NewPostController

func NewPostController() *PostController

func (*PostController) CreatePostHandler

func (pc *PostController) CreatePostHandler(c *gin.Context)

@security BearerAuth @Summary Create a new post @Description Create a new post. Only accessible by authorized users with a valid JWT token. @Tags posts @Accept json @Produce json @Param user path string true "User ID" @Param body body types.CreatePostParams true "Post details" @Success 201 {object} types.Post "Post created successfully" @Failure 400 {object} ErrorResponse "Invalid input or error creating post" @Failure 404 {object} ErrorResponse "Record not found" @Router /posts/{user} [post]

func (*PostController) DeletePostHandler

func (pc *PostController) DeletePostHandler(c *gin.Context)

DeletePostHandler handles the deletion of a specific post by its ID @Summary Delete a specific post @Description Delete a post by its ID. Only accessible by authorized users with a valid JWT token. @Tags posts @Accept json @Produce json @Param user path string true "User ID" @Param id path string true "Post ID" @Success 204 {object} ErrorResponse "Post deleted successfully" @Failure 404 {object} ErrorResponse "Not Found" @Router /posts/{user}/{id} [delete] @Security BearerAuth

func (*PostController) GetPostHandler

func (pc *PostController) GetPostHandler(c *gin.Context)

GetPostHandler retrieves a specific post by its ID @Summary Get a specific post by ID @Description Retrieve a post by its ID. Only accessible by authorized users with a valid JWT token. @Tags posts @Accept json @Produce json @Param id path string true "Post ID" @Success 200 {object} types.Post "Post retrieved successfully" @Failure 404 {object} ErrorResponse "Not Found" @Router /posts/{id} [get] @Security BearerAuth

func (*PostController) ListPostsHandler

func (pc *PostController) ListPostsHandler(c *gin.Context)

ListPostsHandler handles the retrieval of posts, optionally filtering by content @Summary Retrieve all posts or filter by content @Description Retrieves a list of posts. Optionally, you can filter posts by providing a 'content' query parameter. @security BearerAuth @Tags posts @Accept json @Produce json @Param content query string false "Filter posts by content" @Success 200 {array} types.Post "List of posts" @Failure 400 {object} ErrorResponse "Invalid request or error retrieving posts" @Failure 404 {object} ErrorResponse "Record not fount" @Router /posts [get]

func (*PostController) UpdatePostsHandler

func (pc *PostController) UpdatePostsHandler(c *gin.Context)

UpdatePostsHandler godoc @Summary Update a Post @Description Update the content of an existing post by its UUID. @Tags posts @Accept json @Produce json @Param id path string true "Post ID" @Param user path string true "User ID" @Param post body types.Post true "Post Content" @Success 200 {object} types.Post "Updated Post" @Failure 400 {object} ErrorResponse "Bad Request" @Failure 404 {object} ErrorResponse "Post Not Found" @security BearerAuth @Router /posts/{user}/{id} [put]

type ProfileControler

type ProfileControler struct {
	ProfileRepository repository.PostgresProfileRepo
}

func NewProfileControler

func NewProfileControler() *ProfileControler

func (*ProfileControler) GetUserProfileHandler

func (pc *ProfileControler) GetUserProfileHandler(c *gin.Context)

GetUserProfileHandler handles the retrieval of a user profile by ID. @Summary Get user profile @Description Retrieve the profile information for a specific user by ID. @Tags profile @Accept json @Produce json @Param id path string true "User ID" @Success 200 {object} ErrorResponse "User profile retrieved successfully" @Failure 400 {object} ErrorResponse "Bad Request" @Failure 404 {object} ErrorResponse "Record not found" @Security BearerAuth @Router /profile/{id} [get]

type SubsController

type SubsController struct {
	SubsRepository repository.PostgresSubsRepo
}

func NewSubsController

func NewSubsController() *SubsController

func (*SubsController) CreateSubs

func (sc *SubsController) CreateSubs(c *gin.Context)

@Summary Create a new subscription @Description Creates a new subscription for a user. Accessible to authenticated users. @Tags Subscriptions @Accept json @Produce json @Param subscriber path string true "Subscriber ID" @Param subscription body types.SubscriptionResponse true "Subscription data" @Success 201 {object} ErrorResponse "Subscription created successfully" @Failure 400 {object} ErrorResponse "Bad request error" @Failure 404 {object} ErrorResponse "Record not found" @Security BearerAuth @Router /subs/{subscriber} [post]

func (*SubsController) GetAllSubscribed

func (sc *SubsController) GetAllSubscribed(c *gin.Context)

@Summary Get all users subscribed to a user @Description Retrieves all users subscribed to a specific user by ID. Accessible to authenticated users. @Tags Subscriptions @Accept json @Produce json @Param id path string true "User ID" @Success 200 {object} map[string]interface{} "List of subscribers" @Failure 400 {object} ErrorResponse "Invalid user ID" @Failure 404 {object} ErrorResponse "User not found error" @Security BearerAuth @Router /subs/subscribers/{id} [get]

func (*SubsController) GetAllSubscriptions

func (sc *SubsController) GetAllSubscriptions(c *gin.Context)

@Summary Get all subscriptions of a user @Description Retrieves all subscriptions for a user by ID or username. Accessible to authenticated users. @Tags Subscriptions @Accept json @Produce json @Param id path string optional "User ID" @Param username query string optional "Username" @Success 200 {object} map[string]interface{} "List of subscriptions" @Failure 404 {object} ErrorResponse "User not found error" @Security BearerAuth @Router /subs/subscriptions/{id} [get]

type UserControler

type UserControler struct {
	UserRepository repository.PostgresRep
}

func NewUserControler

func NewUserControler() *UserControler

func (*UserControler) DeleteUserHandler

func (cl *UserControler) DeleteUserHandler(c *gin.Context)

@Summary Delete a user @Description Deletes a user by ID. Accessible only by admin users. @Tags Users @Accept json @Produce json @Param id path string true "User ID" @Success 204 "User deleted successfully" @Failure 404 {object} ErrorResponse "User not found or failed to delete" @Security BearerAuth @Router /users/{id} [delete]

func (*UserControler) GetUserHandler

func (cl *UserControler) GetUserHandler(c *gin.Context)

@Summary Get a specific user @Description Retrieves details of a specific user by ID. Accessible only by admin users. @Tags Users @Accept json @Produce json @Param id path string true "User ID" @Success 200 {object} types.ResponseUser "User details" @Failure 404 {object} ErrorResponse "User not found error" @Security BearerAuth @Router /users/{id} [get]

func (*UserControler) InsertUserHandler

func (cl *UserControler) InsertUserHandler(c *gin.Context)

@Summary Create a new user @Description Creates a new user. Accessible only by admin users. @Tags Users @Accept json @Produce json @Param user body types.CreateUserParams true "User data" @Success 200 {object} types.ResponseUser "Created user details" @Failure 400 {object} ErrorResponse "Bad request error" @Failure 500 {object} ErrorResponse "Internal server error" @Failure 404 {object} ErrorResponse "Record not found" @Security BearerAuth @Router /users [post]

func (*UserControler) ListUserHandler

func (cl *UserControler) ListUserHandler(c *gin.Context)

@Summary List all users @Description Retrieves a list of all users. Accessible only by admin users. @Tags Users @Accept json @Produce json @Success 200 {array} types.ResponseUser "List of users" @Failure 400 {object} ErrorResponse "Bad request error" @Security BearerAuth @Router /users/list [get]

func (*UserControler) UpdateUsernameHandler

func (cl *UserControler) UpdateUsernameHandler(c *gin.Context)

@Summary Update a user's username @Description Updates the username of a user by ID. Accessible only by admin users. @Tags Users @Accept json @Produce json @Param id path string true "User ID" @Param username body types.UpdateUsernameParams true "New username" @Success 202 {object} map[string]interface{} "Username updated successfully" @Failure 400 {object} ErrorResponse "Invalid request or bad user ID" @Failure 404 {object} ErrorResponse "Record not found" @Security BearerAuth @Router /users/{id}/username [put]

Jump to

Keyboard shortcuts

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