diff --git a/docs/docs.go b/docs/docs.go index 89fbeb4..2eb095b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -27,6 +27,7 @@ const docTemplate = `{ "tags": [ "authentication" ], + "summary": "Authenticate user", "parameters": [ { "description": "User credentials", @@ -34,7 +35,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.User" + "$ref": "#/definitions/models.UserRequest" } } ], @@ -68,6 +69,11 @@ const docTemplate = `{ }, "/posts": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve all posts from the database", "produces": [ "application/json" @@ -75,6 +81,7 @@ const docTemplate = `{ "tags": [ "posts" ], + "summary": "Get all posts", "responses": { "200": { "description": "OK", @@ -95,6 +102,9 @@ const docTemplate = `{ }, "post": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -109,14 +119,16 @@ const docTemplate = `{ "tags": [ "posts" ], + "summary": "Create a new post", "parameters": [ { + "example": "{\"title\": \"string\", \"content\": \"string\"}", "description": "Create Post", "name": "post", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.Post" + "type": "string" } } ], @@ -156,6 +168,11 @@ const docTemplate = `{ }, "/posts/{postId}": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve a post by its ID from the database", "produces": [ "application/json" @@ -163,6 +180,7 @@ const docTemplate = `{ "tags": [ "posts" ], + "summary": "Get a post by ID", "parameters": [ { "type": "integer", @@ -195,6 +213,9 @@ const docTemplate = `{ }, "put": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -209,6 +230,7 @@ const docTemplate = `{ "tags": [ "posts" ], + "summary": "Update a post", "parameters": [ { "type": "integer", @@ -218,12 +240,13 @@ const docTemplate = `{ "required": true }, { + "example": "{\"title\": \"string\", \"content\": \"string\"}", "description": "Post data", "name": "post", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.Post" + "type": "string" } } ], @@ -262,6 +285,9 @@ const docTemplate = `{ }, "delete": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -270,6 +296,7 @@ const docTemplate = `{ "tags": [ "posts" ], + "summary": "Delete a post", "parameters": [ { "type": "integer", @@ -310,6 +337,9 @@ const docTemplate = `{ "/posts/{postId}/dislike": { "post": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -318,6 +348,7 @@ const docTemplate = `{ "tags": [ "posts" ], + "summary": "Dislike a post", "parameters": [ { "type": "integer", @@ -352,6 +383,9 @@ const docTemplate = `{ "/posts/{postId}/like": { "post": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -360,6 +394,7 @@ const docTemplate = `{ "tags": [ "posts" ], + "summary": "Like a post", "parameters": [ { "type": "integer", @@ -393,6 +428,11 @@ const docTemplate = `{ }, "/users": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve all users, optionally filtered by name or nickname", "consumes": [ "application/json" @@ -403,14 +443,7 @@ const docTemplate = `{ "tags": [ "users" ], - "parameters": [ - { - "type": "string", - "description": "Name or nickname of the user to filter", - "name": "user", - "in": "query" - } - ], + "summary": "Get all users", "responses": { "200": { "description": "OK", @@ -430,6 +463,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "Bearer": [] + } + ], "description": "Create a new user with the provided data", "consumes": [ "application/json" @@ -440,6 +478,7 @@ const docTemplate = `{ "tags": [ "users" ], + "summary": "Create a new user", "parameters": [ { "description": "New user data", @@ -475,6 +514,11 @@ const docTemplate = `{ }, "/users/{userID}": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve a user by their ID", "consumes": [ "application/json" @@ -485,6 +529,7 @@ const docTemplate = `{ "tags": [ "users" ], + "summary": "Get user by ID", "parameters": [ { "type": "integer", @@ -516,6 +561,11 @@ const docTemplate = `{ } }, "put": { + "security": [ + { + "Bearer": [] + } + ], "description": "Update a user by their ID", "consumes": [ "application/json" @@ -526,6 +576,7 @@ const docTemplate = `{ "tags": [ "users" ], + "summary": "Update user by ID", "parameters": [ { "type": "integer", @@ -563,6 +614,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "Bearer": [] + } + ], "description": "Delete a user by their ID", "consumes": [ "application/json" @@ -573,6 +629,7 @@ const docTemplate = `{ "tags": [ "users" ], + "summary": "Delete user by ID", "parameters": [ { "type": "integer", @@ -612,6 +669,11 @@ const docTemplate = `{ }, "/users/{userID}/follow": { "post": { + "security": [ + { + "Bearer": [] + } + ], "description": "Follow a user by their ID", "consumes": [ "application/json" @@ -622,6 +684,7 @@ const docTemplate = `{ "tags": [ "users" ], + "summary": "Follow user by ID", "parameters": [ { "type": "integer", @@ -655,6 +718,11 @@ const docTemplate = `{ }, "/users/{userID}/followers": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Search followers of a user by their ID", "consumes": [ "application/json" @@ -665,6 +733,7 @@ const docTemplate = `{ "tags": [ "users" ], + "summary": "Search followers of user", "parameters": [ { "type": "integer", @@ -701,6 +770,11 @@ const docTemplate = `{ }, "/users/{userID}/following": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Search users followed by a user by their ID", "consumes": [ "application/json" @@ -711,6 +785,7 @@ const docTemplate = `{ "tags": [ "users" ], + "summary": "Search following users of user", "parameters": [ { "type": "integer", @@ -747,6 +822,11 @@ const docTemplate = `{ }, "/users/{userID}/unfollow": { "post": { + "security": [ + { + "Bearer": [] + } + ], "description": "Unfollow a user by their ID", "consumes": [ "application/json" @@ -757,6 +837,7 @@ const docTemplate = `{ "tags": [ "users" ], + "summary": "Unfollow user by ID", "parameters": [ { "type": "integer", @@ -790,6 +871,11 @@ const docTemplate = `{ }, "/users/{userID}/update-password": { "post": { + "security": [ + { + "Bearer": [] + } + ], "description": "Update the password of a user by their ID", "consumes": [ "application/json" @@ -800,6 +886,7 @@ const docTemplate = `{ "tags": [ "users" ], + "summary": "Update user password", "parameters": [ { "type": "integer", @@ -807,6 +894,15 @@ const docTemplate = `{ "name": "userID", "in": "path", "required": true + }, + { + "description": "New password", + "name": "password", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.Password" + } } ], "responses": { @@ -839,6 +935,11 @@ const docTemplate = `{ }, "/users/{userId}/posts": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve all posts created by a specific user", "produces": [ "application/json" @@ -846,6 +947,7 @@ const docTemplate = `{ "tags": [ "posts" ], + "summary": "Get all posts by user", "parameters": [ { "type": "integer", @@ -882,6 +984,17 @@ const docTemplate = `{ } }, "definitions": { + "models.Password": { + "type": "object", + "properties": { + "current": { + "type": "string" + }, + "new": { + "type": "string" + } + } + }, "models.Post": { "type": "object", "properties": { @@ -930,6 +1043,25 @@ const docTemplate = `{ "type": "string" } } + }, + "models.UserRequest": { + "type": "object", + "properties": { + "email": { + "type": "string" + }, + "password": { + "type": "string" + } + } + } + }, + "securityDefinitions": { + "Bearer": { + "description": "Provide the JWT token with prefix 'Bearer ' in the text box.", + "type": "apiKey", + "name": "Authorization", + "in": "header" } } }` @@ -938,7 +1070,7 @@ const docTemplate = `{ var SwaggerInfo = &swag.Spec{ Version: "", Host: "", - BasePath: "/v1", + BasePath: "", Schemes: []string{}, Title: "SocialMedia-API", Description: "RESTful API developed in Golang, intended to serve as the backend for a social networking application", diff --git a/docs/swagger.json b/docs/swagger.json index e3abf47..6c8d0a9 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -5,7 +5,6 @@ "title": "SocialMedia-API", "contact": {} }, - "basePath": "/v1", "paths": { "/login": { "post": { @@ -19,6 +18,7 @@ "tags": [ "authentication" ], + "summary": "Authenticate user", "parameters": [ { "description": "User credentials", @@ -26,7 +26,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.User" + "$ref": "#/definitions/models.UserRequest" } } ], @@ -60,6 +60,11 @@ }, "/posts": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve all posts from the database", "produces": [ "application/json" @@ -67,6 +72,7 @@ "tags": [ "posts" ], + "summary": "Get all posts", "responses": { "200": { "description": "OK", @@ -87,6 +93,9 @@ }, "post": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -101,14 +110,16 @@ "tags": [ "posts" ], + "summary": "Create a new post", "parameters": [ { + "example": "{\"title\": \"string\", \"content\": \"string\"}", "description": "Create Post", "name": "post", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.Post" + "type": "string" } } ], @@ -148,6 +159,11 @@ }, "/posts/{postId}": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve a post by its ID from the database", "produces": [ "application/json" @@ -155,6 +171,7 @@ "tags": [ "posts" ], + "summary": "Get a post by ID", "parameters": [ { "type": "integer", @@ -187,6 +204,9 @@ }, "put": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -201,6 +221,7 @@ "tags": [ "posts" ], + "summary": "Update a post", "parameters": [ { "type": "integer", @@ -210,12 +231,13 @@ "required": true }, { + "example": "{\"title\": \"string\", \"content\": \"string\"}", "description": "Post data", "name": "post", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.Post" + "type": "string" } } ], @@ -254,6 +276,9 @@ }, "delete": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -262,6 +287,7 @@ "tags": [ "posts" ], + "summary": "Delete a post", "parameters": [ { "type": "integer", @@ -302,6 +328,9 @@ "/posts/{postId}/dislike": { "post": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -310,6 +339,7 @@ "tags": [ "posts" ], + "summary": "Dislike a post", "parameters": [ { "type": "integer", @@ -344,6 +374,9 @@ "/posts/{postId}/like": { "post": { "security": [ + { + "Bearer": [] + }, { "ApiKeyAuth": [] } @@ -352,6 +385,7 @@ "tags": [ "posts" ], + "summary": "Like a post", "parameters": [ { "type": "integer", @@ -385,6 +419,11 @@ }, "/users": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve all users, optionally filtered by name or nickname", "consumes": [ "application/json" @@ -395,14 +434,7 @@ "tags": [ "users" ], - "parameters": [ - { - "type": "string", - "description": "Name or nickname of the user to filter", - "name": "user", - "in": "query" - } - ], + "summary": "Get all users", "responses": { "200": { "description": "OK", @@ -422,6 +454,11 @@ } }, "post": { + "security": [ + { + "Bearer": [] + } + ], "description": "Create a new user with the provided data", "consumes": [ "application/json" @@ -432,6 +469,7 @@ "tags": [ "users" ], + "summary": "Create a new user", "parameters": [ { "description": "New user data", @@ -467,6 +505,11 @@ }, "/users/{userID}": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve a user by their ID", "consumes": [ "application/json" @@ -477,6 +520,7 @@ "tags": [ "users" ], + "summary": "Get user by ID", "parameters": [ { "type": "integer", @@ -508,6 +552,11 @@ } }, "put": { + "security": [ + { + "Bearer": [] + } + ], "description": "Update a user by their ID", "consumes": [ "application/json" @@ -518,6 +567,7 @@ "tags": [ "users" ], + "summary": "Update user by ID", "parameters": [ { "type": "integer", @@ -555,6 +605,11 @@ } }, "delete": { + "security": [ + { + "Bearer": [] + } + ], "description": "Delete a user by their ID", "consumes": [ "application/json" @@ -565,6 +620,7 @@ "tags": [ "users" ], + "summary": "Delete user by ID", "parameters": [ { "type": "integer", @@ -604,6 +660,11 @@ }, "/users/{userID}/follow": { "post": { + "security": [ + { + "Bearer": [] + } + ], "description": "Follow a user by their ID", "consumes": [ "application/json" @@ -614,6 +675,7 @@ "tags": [ "users" ], + "summary": "Follow user by ID", "parameters": [ { "type": "integer", @@ -647,6 +709,11 @@ }, "/users/{userID}/followers": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Search followers of a user by their ID", "consumes": [ "application/json" @@ -657,6 +724,7 @@ "tags": [ "users" ], + "summary": "Search followers of user", "parameters": [ { "type": "integer", @@ -693,6 +761,11 @@ }, "/users/{userID}/following": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Search users followed by a user by their ID", "consumes": [ "application/json" @@ -703,6 +776,7 @@ "tags": [ "users" ], + "summary": "Search following users of user", "parameters": [ { "type": "integer", @@ -739,6 +813,11 @@ }, "/users/{userID}/unfollow": { "post": { + "security": [ + { + "Bearer": [] + } + ], "description": "Unfollow a user by their ID", "consumes": [ "application/json" @@ -749,6 +828,7 @@ "tags": [ "users" ], + "summary": "Unfollow user by ID", "parameters": [ { "type": "integer", @@ -782,6 +862,11 @@ }, "/users/{userID}/update-password": { "post": { + "security": [ + { + "Bearer": [] + } + ], "description": "Update the password of a user by their ID", "consumes": [ "application/json" @@ -792,6 +877,7 @@ "tags": [ "users" ], + "summary": "Update user password", "parameters": [ { "type": "integer", @@ -799,6 +885,15 @@ "name": "userID", "in": "path", "required": true + }, + { + "description": "New password", + "name": "password", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.Password" + } } ], "responses": { @@ -831,6 +926,11 @@ }, "/users/{userId}/posts": { "get": { + "security": [ + { + "Bearer": [] + } + ], "description": "Retrieve all posts created by a specific user", "produces": [ "application/json" @@ -838,6 +938,7 @@ "tags": [ "posts" ], + "summary": "Get all posts by user", "parameters": [ { "type": "integer", @@ -874,6 +975,17 @@ } }, "definitions": { + "models.Password": { + "type": "object", + "properties": { + "current": { + "type": "string" + }, + "new": { + "type": "string" + } + } + }, "models.Post": { "type": "object", "properties": { @@ -922,6 +1034,25 @@ "type": "string" } } + }, + "models.UserRequest": { + "type": "object", + "properties": { + "email": { + "type": "string" + }, + "password": { + "type": "string" + } + } + } + }, + "securityDefinitions": { + "Bearer": { + "description": "Provide the JWT token with prefix 'Bearer ' in the text box.", + "type": "apiKey", + "name": "Authorization", + "in": "header" } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 66d921d..2dbf254 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,5 +1,11 @@ -basePath: /v1 definitions: + models.Password: + properties: + current: + type: string + new: + type: string + type: object models.Post: properties: authorId: @@ -32,6 +38,13 @@ definitions: password: type: string type: object + models.UserRequest: + properties: + email: + type: string + password: + type: string + type: object info: contact: {} description: RESTful API developed in Golang, intended to serve as the backend for @@ -49,7 +62,7 @@ paths: name: credentials required: true schema: - $ref: '#/definitions/models.User' + $ref: '#/definitions/models.UserRequest' produces: - text/plain responses: @@ -69,6 +82,7 @@ paths: description: Internal Server Error schema: type: object + summary: Authenticate user tags: - authentication /posts: @@ -87,6 +101,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Get all posts tags: - posts post: @@ -95,11 +112,12 @@ paths: description: Create a new post with the data sent in the request body parameters: - description: Create Post + example: '{"title": "string", "content": "string"}' in: body name: post required: true schema: - $ref: '#/definitions/models.Post' + type: string produces: - application/json responses: @@ -124,7 +142,9 @@ paths: schema: type: object security: + - Bearer: [] - ApiKeyAuth: [] + summary: Create a new post tags: - posts /posts/{postId}: @@ -154,7 +174,9 @@ paths: schema: type: object security: + - Bearer: [] - ApiKeyAuth: [] + summary: Delete a post tags: - posts get: @@ -180,6 +202,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Get a post by ID tags: - posts put: @@ -193,11 +218,12 @@ paths: required: true type: integer - description: Post data + example: '{"title": "string", "content": "string"}' in: body name: post required: true schema: - $ref: '#/definitions/models.Post' + type: string produces: - application/json responses: @@ -222,7 +248,9 @@ paths: schema: type: object security: + - Bearer: [] - ApiKeyAuth: [] + summary: Update a post tags: - posts /posts/{postId}/dislike: @@ -248,7 +276,9 @@ paths: schema: type: object security: + - Bearer: [] - ApiKeyAuth: [] + summary: Dislike a post tags: - posts /posts/{postId}/like: @@ -274,7 +304,9 @@ paths: schema: type: object security: + - Bearer: [] - ApiKeyAuth: [] + summary: Like a post tags: - posts /users: @@ -282,11 +314,6 @@ paths: consumes: - application/json description: Retrieve all users, optionally filtered by name or nickname - parameters: - - description: Name or nickname of the user to filter - in: query - name: user - type: string produces: - application/json responses: @@ -300,6 +327,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Get all users tags: - users post: @@ -328,6 +358,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Create a new user tags: - users /users/{userID}: @@ -360,6 +393,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Delete user by ID tags: - users get: @@ -387,6 +423,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Get user by ID tags: - users put: @@ -418,6 +457,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Update user by ID tags: - users /users/{userID}/follow: @@ -446,6 +488,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Follow user by ID tags: - users /users/{userID}/followers: @@ -476,6 +521,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Search followers of user tags: - users /users/{userID}/following: @@ -506,6 +554,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Search following users of user tags: - users /users/{userID}/unfollow: @@ -534,6 +585,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Unfollow user by ID tags: - users /users/{userID}/update-password: @@ -547,6 +601,12 @@ paths: name: userID required: true type: integer + - description: New password + in: body + name: password + required: true + schema: + $ref: '#/definitions/models.Password' produces: - application/json responses: @@ -566,6 +626,9 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Update user password tags: - users /users/{userId}/posts: @@ -594,6 +657,15 @@ paths: description: Internal Server Error schema: type: object + security: + - Bearer: [] + summary: Get all posts by user tags: - posts +securityDefinitions: + Bearer: + description: Provide the JWT token with prefix 'Bearer ' in the text box. + in: header + name: Authorization + type: apiKey swagger: "2.0" diff --git a/main.go b/main.go index c3912d0..619762e 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,10 @@ import ( // @title SocialMedia-API // @description RESTful API developed in Golang, intended to serve as the backend for a social networking application -// @BasePath /v1 +// @securityDefinitions.apikey Bearer +// @in header +// @name Authorization +// @description Provide the JWT token with prefix 'Bearer ' in the text box. func main() { config.Load() r := router.Generate() diff --git a/src/controllers/login.go b/src/controllers/login.go index 5064862..884d77d 100644 --- a/src/controllers/login.go +++ b/src/controllers/login.go @@ -18,7 +18,7 @@ import ( // @Tags authentication // @Accept json // @Produce plain -// @Param credentials body models.User true "User credentials" +// @Param credentials body models.UserRequest true "User credentials" // @Success 200 {string} string "Authentication token" // @Failure 400 {object} object "Bad Request" // @Failure 401 {object} object "Unauthorized" @@ -31,7 +31,7 @@ func Login(w http.ResponseWriter, r *http.Request) { return } - var user models.User + var user models.UserRequest if err = json.Unmarshal(requestBody, &user); err != nil { responses.Error(w, http.StatusBadRequest, err) @@ -64,7 +64,7 @@ func Login(w http.ResponseWriter, r *http.Request) { return } - formattedToken := fmt.Sprintf("Token: %s", token) + formattedToken := fmt.Sprintf("Bearer %s", token) w.Write([]byte(formattedToken)) } diff --git a/src/controllers/posts.go b/src/controllers/posts.go index fcafd33..b89eebc 100644 --- a/src/controllers/posts.go +++ b/src/controllers/posts.go @@ -20,7 +20,8 @@ import ( // @Tags posts // @Accept json // @Produce json -// @Param post body models.Post true "Create Post" +// @Security Bearer +// @Param post body string true "Create Post" example({"title": "string", "content": "string"}) // @Success 201 {object} models.Post // @Failure 400 {object} object "Bad Request" // @Failure 401 {object} object "Unauthorized" @@ -75,6 +76,7 @@ func CreatePost(w http.ResponseWriter, r *http.Request) { // @Description Retrieve all posts from the database // @Tags posts // @Produce json +// @Security Bearer // @Success 200 {array} models.Post // @Failure 500 {object} object "Internal Server Error" // @Router /posts [get] @@ -106,6 +108,7 @@ func GetPosts(w http.ResponseWriter, r *http.Request) { // @Description Retrieve a post by its ID from the database // @Tags posts // @Produce json +// @Security Bearer // @Param postId path int true "Post ID" // @Success 200 {object} models.Post // @Failure 400 {object} object "Bad Request" @@ -141,8 +144,9 @@ func GetPost(w http.ResponseWriter, r *http.Request) { // @Tags posts // @Accept json // @Produce json +// @Security Bearer // @Param postId path int true "Post ID" -// @Param post body models.Post true "Post data" +// @Param post body string true "Post data" example({"title": "string", "content": "string"}) // @Success 204 {object} object // @Failure 400 {object} object "Bad Request" // @Failure 401 {object} object "Unauthorized" @@ -211,6 +215,7 @@ func UpdatePost(w http.ResponseWriter, r *http.Request) { // @Summary Delete a post // @Description Delete a post by its ID // @Tags posts +// @Security Bearer // @Param postId path int true "Post ID" // @Success 204 {object} object // @Failure 400 {object} object "Bad Request" @@ -263,6 +268,7 @@ func DeletePost(w http.ResponseWriter, r *http.Request) { // @Description Retrieve all posts created by a specific user // @Tags posts // @Produce json +// @Security Bearer // @Param userId path int true "User ID" // @Success 200 {array} models.Post // @Failure 400 {object} object "Bad Request" @@ -296,6 +302,7 @@ func GetPostsPerUser(w http.ResponseWriter, r *http.Request) { // @Summary Like a post // @Description Increment the likes count for a post // @Tags posts +// @Security Bearer // @Param postId path int true "Post ID" // @Success 204 {object} object // @Failure 400 {object} object "Bad Request" @@ -330,6 +337,7 @@ func LikePost(w http.ResponseWriter, r *http.Request) { // @Summary Dislike a post // @Description Decrement the likes count for a post // @Tags posts +// @Security Bearer // @Param postId path int true "Post ID" // @Success 204 {object} object // @Failure 400 {object} object "Bad Request" diff --git a/src/controllers/users.go b/src/controllers/users.go index edd99dd..b0ed124 100644 --- a/src/controllers/users.go +++ b/src/controllers/users.go @@ -22,6 +22,7 @@ import ( // @Tags users // @Accept json // @Produce json +// @Security Bearer // @Param user body models.User true "New user data" // @Success 201 {object} models.User // @Failure 400 {object} object "Bad Request" @@ -67,7 +68,7 @@ func CreateUser(w http.ResponseWriter, r *http.Request) { // @Tags users // @Accept json // @Produce json -// @Param user query string false "Name or nickname of the user to filter" +// @Security Bearer // @Success 200 {array} models.User // @Failure 500 {object} object "Internal Server Error" // @Router /users [get] @@ -96,6 +97,7 @@ func GetUsers(w http.ResponseWriter, r *http.Request) { // @Tags users // @Accept json // @Produce json +// @Security Bearer // @Param userID path int true "User ID" // @Success 200 {object} models.User // @Failure 400 {object} object "Bad Request" @@ -131,6 +133,7 @@ func GetUser(w http.ResponseWriter, r *http.Request) { // @Tags users // @Accept json // @Produce json +// @Security Bearer // @Param userID path int true "User ID" // @Success 204 {object} object // @Failure 400 {object} object "Bad Request" @@ -177,6 +180,7 @@ func DeleteUser(w http.ResponseWriter, r *http.Request) { // @Tags users // @Accept json // @Produce json +// @Security Bearer // @Param userID path int true "User ID" // @Success 204 {object} object // @Failure 400 {object} object "Bad Request" @@ -241,6 +245,7 @@ func UpdateUser(w http.ResponseWriter, r *http.Request) { // @Tags users // @Accept json // @Produce json +// @Security Bearer // @Param userID path int true "User ID" // @Success 204 {object} object // @Failure 401 {object} object "Unauthorized" @@ -286,6 +291,7 @@ func FollowUser(w http.ResponseWriter, r *http.Request) { // @Tags users // @Accept json // @Produce json +// @Security Bearer // @Param userID path int true "User ID" // @Success 204 {object} object // @Failure 401 {object} object "Unauthorized" @@ -332,6 +338,7 @@ func UnfollowUser(w http.ResponseWriter, r *http.Request) { // @Tags users // @Accept json // @Produce json +// @Security Bearer // @Param userID path int true "User ID" // @Success 200 {array} models.User // @Failure 400 {object} object "Bad Request" @@ -367,6 +374,7 @@ func SearchFollowers(w http.ResponseWriter, r *http.Request) { // @Tags users // @Accept json // @Produce json +// @Security Bearer // @Param userID path int true "User ID" // @Success 200 {array} models.User // @Failure 400 {object} object "Bad Request" @@ -402,7 +410,9 @@ func SearchFollowing(w http.ResponseWriter, r *http.Request) { // @Tags users // @Accept json // @Produce json +// @Security Bearer // @Param userID path int true "User ID" +// @Param password body models.Password true "New password" example({"new": "string", "current": "string"}) // @Success 204 {object} object // @Failure 400 {object} object "Bad Request" // @Failure 401 {object} object "Unauthorized" diff --git a/src/models/User.go b/src/models/User.go index b74d5ed..7333add 100644 --- a/src/models/User.go +++ b/src/models/User.go @@ -19,6 +19,11 @@ type User struct { CreatedAt time.Time `json:"CreatedAt,omitempty"` } +type UserRequest struct { + Email string `json:"email,omitempty"` + Password string `json:"password,omitempty"` +} + func (user *User) Prepare(step string) error { if err := user.validate(step); err != nil { return err