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",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.VoteRequest"
|
||||
"$ref": "#/definitions/dto.CastVoteRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -1817,6 +1817,22 @@ const docTemplate = `{
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"dto.CastVoteRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"up",
|
||||
"down",
|
||||
"none"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.ConfirmAccountDeletionRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -2018,22 +2034,6 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.VoteRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"up",
|
||||
"down",
|
||||
"none"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"handlers.APIInfo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -1367,7 +1367,7 @@
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.VoteRequest"
|
||||
"$ref": "#/definitions/dto.CastVoteRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -1814,6 +1814,22 @@
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"dto.CastVoteRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"up",
|
||||
"down",
|
||||
"none"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.ConfirmAccountDeletionRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -2015,22 +2031,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.VoteRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"up",
|
||||
"down",
|
||||
"none"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"handlers.APIInfo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
basePath: /api
|
||||
definitions:
|
||||
dto.CastVoteRequest:
|
||||
properties:
|
||||
type:
|
||||
enum:
|
||||
- up
|
||||
- down
|
||||
- none
|
||||
type: string
|
||||
required:
|
||||
- type
|
||||
type: object
|
||||
dto.ConfirmAccountDeletionRequest:
|
||||
properties:
|
||||
delete_posts:
|
||||
@@ -140,17 +151,6 @@ definitions:
|
||||
required:
|
||||
- username
|
||||
type: object
|
||||
dto.VoteRequest:
|
||||
properties:
|
||||
type:
|
||||
enum:
|
||||
- up
|
||||
- down
|
||||
- none
|
||||
type: string
|
||||
required:
|
||||
- type
|
||||
type: object
|
||||
handlers.APIInfo:
|
||||
properties:
|
||||
data: {}
|
||||
@@ -1121,7 +1121,7 @@ paths:
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/dto.VoteRequest'
|
||||
$ref: '#/definitions/dto.CastVoteRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"goyco/internal/database"
|
||||
)
|
||||
|
||||
type VoteRequest struct {
|
||||
type CastVoteRequest struct {
|
||||
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 {
|
||||
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) {
|
||||
|
||||
@@ -58,7 +58,7 @@ type VoteResponse = CommonResponse
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @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"
|
||||
// @Failure 401 {object} VoteResponse "Authentication required"
|
||||
// @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
|
||||
}
|
||||
|
||||
req, ok := GetValidatedDTO[dto.VoteRequest](r)
|
||||
req, ok := GetValidatedDTO[dto.CastVoteRequest](r)
|
||||
if !ok {
|
||||
SendErrorResponse(w, "Invalid request", http.StatusBadRequest)
|
||||
return
|
||||
@@ -283,7 +283,7 @@ func (h *VoteHandler) MountRoutes(r chi.Router, config RouteModuleConfig) {
|
||||
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.Get("/posts/{id}/vote", h.GetUserVote)
|
||||
protected.Get("/posts/{id}/votes", h.GetPostVotes)
|
||||
|
||||
Reference in New Issue
Block a user