Compare commits
3 Commits
e2e5d42035
...
c5418f4e4c
| Author | SHA1 | Date | |
|---|---|---|---|
| c5418f4e4c | |||
| db0369225e | |||
| 07ac965b3d |
34
docs/docs.go
34
docs/docs.go
@@ -1370,7 +1370,7 @@ const docTemplate = `{
|
|||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/dto.VoteRequest"
|
"$ref": "#/definitions/dto.CastVoteRequest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -1817,6 +1817,22 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
|
"dto.CastVoteRequest": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"type"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"up",
|
||||||
|
"down",
|
||||||
|
"none"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"dto.ConfirmAccountDeletionRequest": {
|
"dto.ConfirmAccountDeletionRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
@@ -2018,22 +2034,6 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dto.VoteRequest": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"type"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"up",
|
|
||||||
"down",
|
|
||||||
"none"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"handlers.APIInfo": {
|
"handlers.APIInfo": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -1367,7 +1367,7 @@
|
|||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/dto.VoteRequest"
|
"$ref": "#/definitions/dto.CastVoteRequest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -1814,6 +1814,22 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
|
"dto.CastVoteRequest": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"type"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"up",
|
||||||
|
"down",
|
||||||
|
"none"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"dto.ConfirmAccountDeletionRequest": {
|
"dto.ConfirmAccountDeletionRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
@@ -2015,22 +2031,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dto.VoteRequest": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"type"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"up",
|
|
||||||
"down",
|
|
||||||
"none"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"handlers.APIInfo": {
|
"handlers.APIInfo": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
basePath: /api
|
basePath: /api
|
||||||
definitions:
|
definitions:
|
||||||
|
dto.CastVoteRequest:
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
enum:
|
||||||
|
- up
|
||||||
|
- down
|
||||||
|
- none
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- type
|
||||||
|
type: object
|
||||||
dto.ConfirmAccountDeletionRequest:
|
dto.ConfirmAccountDeletionRequest:
|
||||||
properties:
|
properties:
|
||||||
delete_posts:
|
delete_posts:
|
||||||
@@ -140,17 +151,6 @@ definitions:
|
|||||||
required:
|
required:
|
||||||
- username
|
- username
|
||||||
type: object
|
type: object
|
||||||
dto.VoteRequest:
|
|
||||||
properties:
|
|
||||||
type:
|
|
||||||
enum:
|
|
||||||
- up
|
|
||||||
- down
|
|
||||||
- none
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- type
|
|
||||||
type: object
|
|
||||||
handlers.APIInfo:
|
handlers.APIInfo:
|
||||||
properties:
|
properties:
|
||||||
data: {}
|
data: {}
|
||||||
@@ -1121,7 +1121,7 @@ paths:
|
|||||||
name: request
|
name: request
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/dto.VoteRequest'
|
$ref: '#/definitions/dto.CastVoteRequest'
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"goyco/internal/database"
|
"goyco/internal/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VoteRequest struct {
|
type CastVoteRequest struct {
|
||||||
Type string `json:"type" validate:"required,oneof=up down none"`
|
Type string `json:"type" validate:"required,oneof=up down none"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -788,7 +788,7 @@ func createUpdatePostRequest(body string) *http.Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createVoteRequest(body string) *http.Request {
|
func createVoteRequest(body string) *http.Request {
|
||||||
return createRequestWithDTO[dto.VoteRequest](http.MethodPost, "/api/posts/1/vote", []byte(body))
|
return createRequestWithDTO[dto.CastVoteRequest](http.MethodPost, "/api/posts/1/vote", []byte(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParsePagination(t *testing.T) {
|
func TestParsePagination(t *testing.T) {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ type VoteResponse = CommonResponse
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Param id path int true "Post ID"
|
// @Param id path int true "Post ID"
|
||||||
// @Param request body dto.VoteRequest true "Vote data (type: 'up', 'down', or 'none' to remove)"
|
// @Param request body dto.CastVoteRequest true "Vote data (type: 'up', 'down', or 'none' to remove)"
|
||||||
// @Success 200 {object} VoteResponse "Vote cast successfully with updated post statistics"
|
// @Success 200 {object} VoteResponse "Vote cast successfully with updated post statistics"
|
||||||
// @Failure 401 {object} VoteResponse "Authentication required"
|
// @Failure 401 {object} VoteResponse "Authentication required"
|
||||||
// @Failure 400 {object} VoteResponse "Invalid request data or vote type"
|
// @Failure 400 {object} VoteResponse "Invalid request data or vote type"
|
||||||
@@ -78,7 +78,7 @@ func (h *VoteHandler) CastVote(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
req, ok := GetValidatedDTO[dto.VoteRequest](r)
|
req, ok := GetValidatedDTO[dto.CastVoteRequest](r)
|
||||||
if !ok {
|
if !ok {
|
||||||
SendErrorResponse(w, "Invalid request", http.StatusBadRequest)
|
SendErrorResponse(w, "Invalid request", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@@ -283,7 +283,7 @@ func (h *VoteHandler) MountRoutes(r chi.Router, config RouteModuleConfig) {
|
|||||||
protected = config.GeneralRateLimit(protected)
|
protected = config.GeneralRateLimit(protected)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected.Post("/posts/{id}/vote", WithValidation[dto.VoteRequest](config.ValidationMiddleware, h.CastVote))
|
protected.Post("/posts/{id}/vote", WithValidation[dto.CastVoteRequest](config.ValidationMiddleware, h.CastVote))
|
||||||
protected.Delete("/posts/{id}/vote", h.RemoveVote)
|
protected.Delete("/posts/{id}/vote", h.RemoveVote)
|
||||||
protected.Get("/posts/{id}/vote", h.GetUserVote)
|
protected.Get("/posts/{id}/vote", h.GetUserVote)
|
||||||
protected.Get("/posts/{id}/votes", h.GetPostVotes)
|
protected.Get("/posts/{id}/votes", h.GetPostVotes)
|
||||||
|
|||||||
Reference in New Issue
Block a user