finished docs for user reletaded stucts and added endpoint for listallusers
This commit is contained in:
		
							parent
							
								
									f3c5abf4f3
								
							
						
					
					
						commit
						ad85194d4f
					
				
					 2 changed files with 124 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -106,6 +106,58 @@ const docTemplate = `{
 | 
			
		|||
                }
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        "/promoteToAdmin": {
 | 
			
		||||
            "post": {
 | 
			
		||||
                "description": "promote chosen user to admin",
 | 
			
		||||
                "consumes": [
 | 
			
		||||
                    "application/json"
 | 
			
		||||
                ],
 | 
			
		||||
                "produces": [
 | 
			
		||||
                    "text/plain"
 | 
			
		||||
                ],
 | 
			
		||||
                "tags": [
 | 
			
		||||
                    "User"
 | 
			
		||||
                ],
 | 
			
		||||
                "summary": "promote user to admin",
 | 
			
		||||
                "parameters": [
 | 
			
		||||
                    {
 | 
			
		||||
                        "description": "user info",
 | 
			
		||||
                        "name": "NewUser",
 | 
			
		||||
                        "in": "body",
 | 
			
		||||
                        "required": true,
 | 
			
		||||
                        "schema": {
 | 
			
		||||
                            "$ref": "#/definitions/types.NewUser"
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                ],
 | 
			
		||||
                "responses": {
 | 
			
		||||
                    "200": {
 | 
			
		||||
                        "description": "Successfully prometed user",
 | 
			
		||||
                        "schema": {
 | 
			
		||||
                            "type": "json"
 | 
			
		||||
                        }
 | 
			
		||||
                    },
 | 
			
		||||
                    "400": {
 | 
			
		||||
                        "description": "bad request",
 | 
			
		||||
                        "schema": {
 | 
			
		||||
                            "type": "string"
 | 
			
		||||
                        }
 | 
			
		||||
                    },
 | 
			
		||||
                    "401": {
 | 
			
		||||
                        "description": "Unauthorized",
 | 
			
		||||
                        "schema": {
 | 
			
		||||
                            "type": "string"
 | 
			
		||||
                        }
 | 
			
		||||
                    },
 | 
			
		||||
                    "500": {
 | 
			
		||||
                        "description": "Internal server error",
 | 
			
		||||
                        "schema": {
 | 
			
		||||
                            "type": "string"
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        "/register": {
 | 
			
		||||
            "post": {
 | 
			
		||||
                "description": "Register a new user",
 | 
			
		||||
| 
						 | 
				
			
			@ -192,6 +244,41 @@ const docTemplate = `{
 | 
			
		|||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        "/users/all": {
 | 
			
		||||
            "get": {
 | 
			
		||||
                "description": "lists all users",
 | 
			
		||||
                "consumes": [
 | 
			
		||||
                    "application/json"
 | 
			
		||||
                ],
 | 
			
		||||
                "produces": [
 | 
			
		||||
                    "text/plain"
 | 
			
		||||
                ],
 | 
			
		||||
                "tags": [
 | 
			
		||||
                    "User"
 | 
			
		||||
                ],
 | 
			
		||||
                "summary": "Lists users",
 | 
			
		||||
                "responses": {
 | 
			
		||||
                    "200": {
 | 
			
		||||
                        "description": "Successfully signed token for user",
 | 
			
		||||
                        "schema": {
 | 
			
		||||
                            "type": "json"
 | 
			
		||||
                        }
 | 
			
		||||
                    },
 | 
			
		||||
                    "401": {
 | 
			
		||||
                        "description": "Unauthorized",
 | 
			
		||||
                        "schema": {
 | 
			
		||||
                            "type": "string"
 | 
			
		||||
                        }
 | 
			
		||||
                    },
 | 
			
		||||
                    "500": {
 | 
			
		||||
                        "description": "Internal server error",
 | 
			
		||||
                        "schema": {
 | 
			
		||||
                            "type": "string"
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    "definitions": {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -148,6 +148,16 @@ func (gs *GState) LoginRenew(c *fiber.Ctx) error {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// ListAllUsers is a handler that returns a list of all users in the application database
 | 
			
		||||
//
 | 
			
		||||
//	@Summary		Lists users
 | 
			
		||||
//	@Description	lists all users
 | 
			
		||||
//	@Tags			User
 | 
			
		||||
//	@Accept			json
 | 
			
		||||
//	@Produce		plain
 | 
			
		||||
//	@Success		200	{json}		json	"Successfully signed token for user"
 | 
			
		||||
//	@Failure		401	{string}	string	"Unauthorized"
 | 
			
		||||
//	@Failure		500	{string}	string	"Internal server error"
 | 
			
		||||
//	@Router			/users/all [get]
 | 
			
		||||
func (gs *GState) ListAllUsers(c *fiber.Ctx) error {
 | 
			
		||||
	// Get all users from the database
 | 
			
		||||
	users, err := gs.Db.GetAllUsersApplication()
 | 
			
		||||
| 
						 | 
				
			
			@ -159,6 +169,17 @@ func (gs *GState) ListAllUsers(c *fiber.Ctx) error {
 | 
			
		|||
	return c.JSON(users)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//	@Summary		promote user to admin
 | 
			
		||||
//	@Description	promote chosen user to admin
 | 
			
		||||
//	@Tags			User
 | 
			
		||||
//	@Accept			json
 | 
			
		||||
//	@Produce		plain
 | 
			
		||||
//	@Param			NewUser	body		types.NewUser	true	"user info"
 | 
			
		||||
//	@Success		200		{json}		json			"Successfully prometed user"
 | 
			
		||||
//	@Failure		400		{string}	string			"bad request"
 | 
			
		||||
//	@Failure		401		{string}	string			"Unauthorized"
 | 
			
		||||
//	@Failure		500		{string}	string			"Internal server error"
 | 
			
		||||
//	@Router			/promoteToAdmin [post]
 | 
			
		||||
func (gs *GState) PromoteToAdmin(c *fiber.Ctx) error {
 | 
			
		||||
	// Extract the username from the request body
 | 
			
		||||
	var newUser types.NewUser
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue