Compare commits

...

3 Commits

8 changed files with 2775 additions and 2513 deletions

View File

@@ -14,8 +14,8 @@ const docTemplate = `{
"email": "sandro@cazzaniga.fr" "email": "sandro@cazzaniga.fr"
}, },
"license": { "license": {
"name": "MIT", "name": "GPLv3",
"url": "https://opensource.org/licenses/MIT" "url": "https://www.gnu.org/licenses/gpl-3.0.html"
}, },
"version": "{{.Version}}" "version": "{{.Version}}"
}, },
@@ -24,7 +24,7 @@ const docTemplate = `{
"paths": { "paths": {
"/api": { "/api": {
"get": { "get": {
"description": "Get information about the API endpoints and version", "description": "Retrieve API metadata, available endpoints, authentication details, and response formats",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@@ -45,7 +45,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/account": { "/api/auth/account": {
"delete": { "delete": {
"security": [ "security": [
{ {
@@ -91,7 +91,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/account/confirm": { "/api/auth/account/confirm": {
"post": { "post": {
"description": "Confirm account deletion using the provided token", "description": "Confirm account deletion using the provided token",
"consumes": [ "consumes": [
@@ -143,7 +143,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/confirm": { "/api/auth/confirm": {
"get": { "get": {
"description": "Confirm user email with verification token", "description": "Confirm user email with verification token",
"consumes": [ "consumes": [
@@ -187,7 +187,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/email": { "/api/auth/email": {
"put": { "put": {
"security": [ "security": [
{ {
@@ -256,7 +256,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/forgot-password": { "/api/auth/forgot-password": {
"post": { "post": {
"description": "Send a password reset email using a username or email", "description": "Send a password reset email using a username or email",
"consumes": [ "consumes": [
@@ -296,7 +296,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/login": { "/api/auth/login": {
"post": { "post": {
"description": "Authenticate user with username and password", "description": "Authenticate user with username and password",
"consumes": [ "consumes": [
@@ -354,7 +354,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/logout": { "/api/auth/logout": {
"post": { "post": {
"security": [ "security": [
{ {
@@ -388,7 +388,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/me": { "/api/auth/me": {
"get": { "get": {
"security": [ "security": [
{ {
@@ -428,7 +428,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/password": { "/api/auth/password": {
"put": { "put": {
"security": [ "security": [
{ {
@@ -485,7 +485,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/refresh": { "/api/auth/refresh": {
"post": { "post": {
"description": "Use a refresh token to get a new access token. This endpoint allows clients to obtain a new access token using a valid refresh token without requiring user credentials.", "description": "Use a refresh token to get a new access token. This endpoint allows clients to obtain a new access token using a valid refresh token without requiring user credentials.",
"consumes": [ "consumes": [
@@ -543,7 +543,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/register": { "/api/auth/register": {
"post": { "post": {
"description": "Register a new user with username, email and password", "description": "Register a new user with username, email and password",
"consumes": [ "consumes": [
@@ -595,7 +595,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/resend-verification": { "/api/auth/resend-verification": {
"post": { "post": {
"description": "Send a new verification email to the provided address", "description": "Send a new verification email to the provided address",
"consumes": [ "consumes": [
@@ -665,7 +665,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/reset-password": { "/api/auth/reset-password": {
"post": { "post": {
"description": "Reset a user's password using a reset token", "description": "Reset a user's password using a reset token",
"consumes": [ "consumes": [
@@ -711,7 +711,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/revoke": { "/api/auth/revoke": {
"post": { "post": {
"security": [ "security": [
{ {
@@ -768,7 +768,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/revoke-all": { "/api/auth/revoke-all": {
"post": { "post": {
"security": [ "security": [
{ {
@@ -808,7 +808,7 @@ const docTemplate = `{
} }
} }
}, },
"/auth/username": { "/api/auth/username": {
"put": { "put": {
"security": [ "security": [
{ {
@@ -871,55 +871,7 @@ const docTemplate = `{
} }
} }
}, },
"/health": { "/api/posts": {
"get": {
"description": "Check if the API is healthy with comprehensive database monitoring",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"api"
],
"summary": "Health check",
"responses": {
"200": {
"description": "Health check successful",
"schema": {
"type": "object",
"additionalProperties": true
}
}
}
}
},
"/metrics": {
"get": {
"description": "Get application metrics including post stats, user stats, vote stats, and database performance metrics",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"api"
],
"summary": "Get metrics",
"responses": {
"200": {
"description": "Application metrics with vote statistics and database monitoring",
"schema": {
"type": "object",
"additionalProperties": true
}
}
}
}
},
"/posts": {
"get": { "get": {
"description": "Get a list of posts with pagination. Posts include vote statistics (up_votes, down_votes, score) and current user's vote status.", "description": "Get a list of posts with pagination. Posts include vote statistics (up_votes, down_votes, score) and current user's vote status.",
"consumes": [ "consumes": [
@@ -1037,7 +989,7 @@ const docTemplate = `{
} }
} }
}, },
"/posts/search": { "/api/posts/search": {
"get": { "get": {
"description": "Search posts by title or content keywords. Results include vote statistics and current user's vote status.", "description": "Search posts by title or content keywords. Results include vote statistics and current user's vote status.",
"consumes": [ "consumes": [
@@ -1094,7 +1046,7 @@ const docTemplate = `{
} }
} }
}, },
"/posts/title": { "/api/posts/title": {
"get": { "get": {
"description": "Fetch the HTML title for the provided URL", "description": "Fetch the HTML title for the provided URL",
"consumes": [ "consumes": [
@@ -1144,7 +1096,7 @@ const docTemplate = `{
} }
} }
}, },
"/posts/{id}": { "/api/posts/{id}": {
"get": { "get": {
"description": "Get a post by ID with vote statistics and current user's vote status", "description": "Get a post by ID with vote statistics and current user's vote status",
"consumes": [ "consumes": [
@@ -1333,7 +1285,7 @@ const docTemplate = `{
} }
} }
}, },
"/posts/{id}/vote": { "/api/posts/{id}/vote": {
"get": { "get": {
"security": [ "security": [
{ {
@@ -1515,7 +1467,7 @@ const docTemplate = `{
} }
} }
}, },
"/posts/{id}/votes": { "/api/posts/{id}/votes": {
"get": { "get": {
"security": [ "security": [
{ {
@@ -1570,7 +1522,7 @@ const docTemplate = `{
} }
} }
}, },
"/users": { "/api/users": {
"get": { "get": {
"security": [ "security": [
{ {
@@ -1687,7 +1639,7 @@ const docTemplate = `{
} }
} }
}, },
"/users/{id}": { "/api/users/{id}": {
"get": { "get": {
"security": [ "security": [
{ {
@@ -1748,7 +1700,7 @@ const docTemplate = `{
} }
} }
}, },
"/users/{id}/posts": { "/api/users/{id}/posts": {
"get": { "get": {
"security": [ "security": [
{ {
@@ -1816,6 +1768,52 @@ const docTemplate = `{
} }
} }
} }
},
"/health": {
"get": {
"description": "Check the API health status along with database connectivity details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"api"
],
"summary": "Health check",
"responses": {
"200": {
"description": "Health check successful",
"schema": {
"$ref": "#/definitions/handlers.CommonResponse"
}
}
}
}
},
"/metrics": {
"get": {
"description": "Retrieve application metrics including aggregate counts and database performance data",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"api"
],
"summary": "Get metrics",
"responses": {
"200": {
"description": "Application metrics retrieved successfully",
"schema": {
"$ref": "#/definitions/handlers.CommonResponse"
}
}
}
}
} }
}, },
"definitions": { "definitions": {
@@ -1906,6 +1904,21 @@ const docTemplate = `{
} }
} }
}, },
"handlers.CommonResponse": {
"type": "object",
"properties": {
"data": {},
"error": {
"type": "string"
},
"message": {
"type": "string"
},
"success": {
"type": "boolean"
}
}
},
"handlers.ConfirmAccountDeletionRequest": { "handlers.ConfirmAccountDeletionRequest": {
"type": "object", "type": "object",
"properties": { "properties": {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -60,6 +60,13 @@ func NewAPIHandlerWithMonitoring(config *config.Config, postRepo repositories.Po
type APIInfo = CommonResponse type APIInfo = CommonResponse
// @Summary Get API information
// @Description Retrieve API metadata, available endpoints, authentication details, and response formats
// @Tags api
// @Accept json
// @Produce json
// @Success 200 {object} APIInfo "API information retrieved successfully"
// @Router /api [get]
func (h *APIHandler) GetAPIInfo(w http.ResponseWriter, r *http.Request) { func (h *APIHandler) GetAPIInfo(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api" { if r.URL.Path != "/api" {
http.NotFound(w, r) http.NotFound(w, r)
@@ -127,6 +134,13 @@ func (h *APIHandler) GetAPIInfo(w http.ResponseWriter, r *http.Request) {
SendSuccessResponse(w, "API information retrieved successfully", apiInfo) SendSuccessResponse(w, "API information retrieved successfully", apiInfo)
} }
// @Summary Health check
// @Description Check the API health status along with database connectivity details
// @Tags api
// @Accept json
// @Produce json
// @Success 200 {object} CommonResponse "Health check successful"
// @Router /health [get]
func (h *APIHandler) GetHealth(w http.ResponseWriter, r *http.Request) { func (h *APIHandler) GetHealth(w http.ResponseWriter, r *http.Request) {
if h.healthChecker != nil { if h.healthChecker != nil {
@@ -151,6 +165,13 @@ func (h *APIHandler) GetHealth(w http.ResponseWriter, r *http.Request) {
SendSuccessResponse(w, "Health check successful", health) SendSuccessResponse(w, "Health check successful", health)
} }
// @Summary Get metrics
// @Description Retrieve application metrics including aggregate counts and database performance data
// @Tags api
// @Accept json
// @Produce json
// @Success 200 {object} CommonResponse "Application metrics retrieved successfully"
// @Router /metrics [get]
func (h *APIHandler) GetMetrics(w http.ResponseWriter, r *http.Request) { func (h *APIHandler) GetMetrics(w http.ResponseWriter, r *http.Request) {
postCount, err := h.postRepo.Count() postCount, err := h.postRepo.Count()

View File

@@ -138,7 +138,7 @@ func NewAuthHandler(authService AuthServiceInterface, userRepo repositories.User
// @Failure 401 {object} AuthResponse "Invalid credentials" // @Failure 401 {object} AuthResponse "Invalid credentials"
// @Failure 403 {object} AuthResponse "Account is locked" // @Failure 403 {object} AuthResponse "Account is locked"
// @Failure 500 {object} AuthResponse "Internal server error" // @Failure 500 {object} AuthResponse "Internal server error"
// @Router /auth/login [post] // @Router /api/auth/login [post]
func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) {
var req struct { var req struct {
Username string `json:"username"` Username string `json:"username"`
@@ -180,7 +180,7 @@ func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) {
// @Failure 400 {object} AuthResponse "Invalid request data or validation failed" // @Failure 400 {object} AuthResponse "Invalid request data or validation failed"
// @Failure 409 {object} AuthResponse "Username or email already exists" // @Failure 409 {object} AuthResponse "Username or email already exists"
// @Failure 500 {object} AuthResponse "Internal server error" // @Failure 500 {object} AuthResponse "Internal server error"
// @Router /auth/register [post] // @Router /api/auth/register [post]
func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) {
var req struct { var req struct {
Username string `json:"username"` Username string `json:"username"`
@@ -256,7 +256,7 @@ func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) {
// @Success 200 {object} AuthResponse "Email confirmed successfully" // @Success 200 {object} AuthResponse "Email confirmed successfully"
// @Failure 400 {object} AuthResponse "Invalid or missing token" // @Failure 400 {object} AuthResponse "Invalid or missing token"
// @Failure 500 {object} AuthResponse "Internal server error" // @Failure 500 {object} AuthResponse "Internal server error"
// @Router /auth/confirm [get] // @Router /api/auth/confirm [get]
func (h *AuthHandler) ConfirmEmail(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) ConfirmEmail(w http.ResponseWriter, r *http.Request) {
token := strings.TrimSpace(r.URL.Query().Get("token")) token := strings.TrimSpace(r.URL.Query().Get("token"))
if token == "" { if token == "" {
@@ -288,7 +288,7 @@ func (h *AuthHandler) ConfirmEmail(w http.ResponseWriter, r *http.Request) {
// @Failure 429 {object} AuthResponse // @Failure 429 {object} AuthResponse
// @Failure 503 {object} AuthResponse // @Failure 503 {object} AuthResponse
// @Failure 500 {object} AuthResponse // @Failure 500 {object} AuthResponse
// @Router /auth/resend-verification [post] // @Router /api/auth/resend-verification [post]
func (h *AuthHandler) ResendVerificationEmail(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) ResendVerificationEmail(w http.ResponseWriter, r *http.Request) {
var req struct { var req struct {
Email string `json:"email"` Email string `json:"email"`
@@ -337,7 +337,7 @@ func (h *AuthHandler) ResendVerificationEmail(w http.ResponseWriter, r *http.Req
// @Success 200 {object} AuthResponse "User profile retrieved successfully" // @Success 200 {object} AuthResponse "User profile retrieved successfully"
// @Failure 401 {object} AuthResponse "Authentication required" // @Failure 401 {object} AuthResponse "Authentication required"
// @Failure 404 {object} AuthResponse "User not found" // @Failure 404 {object} AuthResponse "User not found"
// @Router /auth/me [get] // @Router /api/auth/me [get]
func (h *AuthHandler) Me(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) Me(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -362,7 +362,7 @@ func (h *AuthHandler) Me(w http.ResponseWriter, r *http.Request) {
// @Param request body ForgotPasswordRequest true "Username or email" // @Param request body ForgotPasswordRequest true "Username or email"
// @Success 200 {object} AuthResponse "Password reset email sent if account exists" // @Success 200 {object} AuthResponse "Password reset email sent if account exists"
// @Failure 400 {object} AuthResponse "Invalid request data" // @Failure 400 {object} AuthResponse "Invalid request data"
// @Router /auth/forgot-password [post] // @Router /api/auth/forgot-password [post]
func (h *AuthHandler) RequestPasswordReset(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) RequestPasswordReset(w http.ResponseWriter, r *http.Request) {
var req struct { var req struct {
UsernameOrEmail string `json:"username_or_email"` UsernameOrEmail string `json:"username_or_email"`
@@ -393,7 +393,7 @@ func (h *AuthHandler) RequestPasswordReset(w http.ResponseWriter, r *http.Reques
// @Success 200 {object} AuthResponse "Password reset successfully" // @Success 200 {object} AuthResponse "Password reset successfully"
// @Failure 400 {object} AuthResponse "Invalid or expired token, or validation failed" // @Failure 400 {object} AuthResponse "Invalid or expired token, or validation failed"
// @Failure 500 {object} AuthResponse "Internal server error" // @Failure 500 {object} AuthResponse "Internal server error"
// @Router /auth/reset-password [post] // @Router /api/auth/reset-password [post]
func (h *AuthHandler) ResetPassword(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) ResetPassword(w http.ResponseWriter, r *http.Request) {
var req struct { var req struct {
Token string `json:"token"` Token string `json:"token"`
@@ -450,7 +450,7 @@ func (h *AuthHandler) ResetPassword(w http.ResponseWriter, r *http.Request) {
// @Failure 409 {object} AuthResponse // @Failure 409 {object} AuthResponse
// @Failure 503 {object} AuthResponse // @Failure 503 {object} AuthResponse
// @Failure 500 {object} AuthResponse // @Failure 500 {object} AuthResponse
// @Router /auth/email [put] // @Router /api/auth/email [put]
func (h *AuthHandler) UpdateEmail(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) UpdateEmail(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -504,7 +504,7 @@ func (h *AuthHandler) UpdateEmail(w http.ResponseWriter, r *http.Request) {
// @Failure 401 {object} AuthResponse // @Failure 401 {object} AuthResponse
// @Failure 409 {object} AuthResponse // @Failure 409 {object} AuthResponse
// @Failure 500 {object} AuthResponse // @Failure 500 {object} AuthResponse
// @Router /auth/username [put] // @Router /api/auth/username [put]
func (h *AuthHandler) UpdateUsername(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) UpdateUsername(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -553,7 +553,7 @@ func (h *AuthHandler) UpdateUsername(w http.ResponseWriter, r *http.Request) {
// @Failure 400 {object} AuthResponse // @Failure 400 {object} AuthResponse
// @Failure 401 {object} AuthResponse // @Failure 401 {object} AuthResponse
// @Failure 500 {object} AuthResponse // @Failure 500 {object} AuthResponse
// @Router /auth/password [put] // @Router /api/auth/password [put]
func (h *AuthHandler) UpdatePassword(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) UpdatePassword(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -608,7 +608,7 @@ func (h *AuthHandler) UpdatePassword(w http.ResponseWriter, r *http.Request) {
// @Failure 401 {object} AuthResponse "Authentication required" // @Failure 401 {object} AuthResponse "Authentication required"
// @Failure 503 {object} AuthResponse "Email delivery unavailable" // @Failure 503 {object} AuthResponse "Email delivery unavailable"
// @Failure 500 {object} AuthResponse "Internal server error" // @Failure 500 {object} AuthResponse "Internal server error"
// @Router /auth/account [delete] // @Router /api/auth/account [delete]
func (h *AuthHandler) DeleteAccount(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) DeleteAccount(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -638,7 +638,7 @@ func (h *AuthHandler) DeleteAccount(w http.ResponseWriter, r *http.Request) {
// @Failure 400 {object} AuthResponse "Invalid or expired token" // @Failure 400 {object} AuthResponse "Invalid or expired token"
// @Failure 503 {object} AuthResponse "Email delivery unavailable" // @Failure 503 {object} AuthResponse "Email delivery unavailable"
// @Failure 500 {object} AuthResponse "Internal server error" // @Failure 500 {object} AuthResponse "Internal server error"
// @Router /auth/account/confirm [post] // @Router /api/auth/account/confirm [post]
func (h *AuthHandler) ConfirmAccountDeletion(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) ConfirmAccountDeletion(w http.ResponseWriter, r *http.Request) {
var req struct { var req struct {
Token string `json:"token"` Token string `json:"token"`
@@ -684,7 +684,7 @@ func (h *AuthHandler) ConfirmAccountDeletion(w http.ResponseWriter, r *http.Requ
// @Security BearerAuth // @Security BearerAuth
// @Success 200 {object} AuthResponse "Logged out successfully" // @Success 200 {object} AuthResponse "Logged out successfully"
// @Failure 401 {object} AuthResponse "Authentication required" // @Failure 401 {object} AuthResponse "Authentication required"
// @Router /auth/logout [post] // @Router /api/auth/logout [post]
func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request) {
SendSuccessResponse(w, "Logged out successfully", nil) SendSuccessResponse(w, "Logged out successfully", nil)
} }
@@ -700,7 +700,7 @@ func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request) {
// @Failure 401 {object} AuthResponse "Invalid or expired refresh token" // @Failure 401 {object} AuthResponse "Invalid or expired refresh token"
// @Failure 403 {object} AuthResponse "Account is locked" // @Failure 403 {object} AuthResponse "Account is locked"
// @Failure 500 {object} AuthResponse "Internal server error" // @Failure 500 {object} AuthResponse "Internal server error"
// @Router /auth/refresh [post] // @Router /api/auth/refresh [post]
func (h *AuthHandler) RefreshToken(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) RefreshToken(w http.ResponseWriter, r *http.Request) {
var req RefreshTokenRequest var req RefreshTokenRequest
@@ -732,7 +732,7 @@ func (h *AuthHandler) RefreshToken(w http.ResponseWriter, r *http.Request) {
// @Failure 400 {object} AuthResponse "Invalid request body or missing refresh token" // @Failure 400 {object} AuthResponse "Invalid request body or missing refresh token"
// @Failure 401 {object} AuthResponse "Invalid or expired access token" // @Failure 401 {object} AuthResponse "Invalid or expired access token"
// @Failure 500 {object} AuthResponse "Internal server error" // @Failure 500 {object} AuthResponse "Internal server error"
// @Router /auth/revoke [post] // @Router /api/auth/revoke [post]
func (h *AuthHandler) RevokeToken(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) RevokeToken(w http.ResponseWriter, r *http.Request) {
var req RevokeTokenRequest var req RevokeTokenRequest
@@ -763,7 +763,7 @@ func (h *AuthHandler) RevokeToken(w http.ResponseWriter, r *http.Request) {
// @Success 200 {object} AuthResponse "All tokens revoked successfully" // @Success 200 {object} AuthResponse "All tokens revoked successfully"
// @Failure 401 {object} AuthResponse "Invalid or expired access token" // @Failure 401 {object} AuthResponse "Invalid or expired access token"
// @Failure 500 {object} AuthResponse "Internal server error" // @Failure 500 {object} AuthResponse "Internal server error"
// @Router /auth/revoke-all [post] // @Router /api/auth/revoke-all [post]
func (h *AuthHandler) RevokeAllTokens(w http.ResponseWriter, r *http.Request) { func (h *AuthHandler) RevokeAllTokens(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {

View File

@@ -51,7 +51,7 @@ type UpdatePostRequest struct {
// @Success 200 {object} PostResponse "Posts retrieved successfully with vote statistics" // @Success 200 {object} PostResponse "Posts retrieved successfully with vote statistics"
// @Failure 400 {object} PostResponse "Invalid pagination parameters" // @Failure 400 {object} PostResponse "Invalid pagination parameters"
// @Failure 500 {object} PostResponse "Internal server error" // @Failure 500 {object} PostResponse "Internal server error"
// @Router /posts [get] // @Router /api/posts [get]
func (h *PostHandler) GetPosts(w http.ResponseWriter, r *http.Request) { func (h *PostHandler) GetPosts(w http.ResponseWriter, r *http.Request) {
limit, offset := parsePagination(r) limit, offset := parsePagination(r)
@@ -87,7 +87,7 @@ func (h *PostHandler) GetPosts(w http.ResponseWriter, r *http.Request) {
// @Failure 400 {object} PostResponse "Invalid post ID" // @Failure 400 {object} PostResponse "Invalid post ID"
// @Failure 404 {object} PostResponse "Post not found" // @Failure 404 {object} PostResponse "Post not found"
// @Failure 500 {object} PostResponse "Internal server error" // @Failure 500 {object} PostResponse "Internal server error"
// @Router /posts/{id} [get] // @Router /api/posts/{id} [get]
func (h *PostHandler) GetPost(w http.ResponseWriter, r *http.Request) { func (h *PostHandler) GetPost(w http.ResponseWriter, r *http.Request) {
postID, ok := ParseUintParam(w, r, "id", "Post") postID, ok := ParseUintParam(w, r, "id", "Post")
if !ok { if !ok {
@@ -118,7 +118,7 @@ func (h *PostHandler) GetPost(w http.ResponseWriter, r *http.Request) {
// @Failure 409 {object} PostResponse "URL already submitted" // @Failure 409 {object} PostResponse "URL already submitted"
// @Failure 502 {object} PostResponse "Failed to fetch title from URL" // @Failure 502 {object} PostResponse "Failed to fetch title from URL"
// @Failure 500 {object} PostResponse "Internal server error" // @Failure 500 {object} PostResponse "Internal server error"
// @Router /posts [post] // @Router /api/posts [post]
func (h *PostHandler) CreatePost(w http.ResponseWriter, r *http.Request) { func (h *PostHandler) CreatePost(w http.ResponseWriter, r *http.Request) {
var req struct { var req struct {
Title string `json:"title"` Title string `json:"title"`
@@ -218,7 +218,7 @@ func (h *PostHandler) CreatePost(w http.ResponseWriter, r *http.Request) {
// @Success 200 {object} PostResponse "Search results with vote statistics" // @Success 200 {object} PostResponse "Search results with vote statistics"
// @Failure 400 {object} PostResponse "Invalid search parameters" // @Failure 400 {object} PostResponse "Invalid search parameters"
// @Failure 500 {object} PostResponse "Internal server error" // @Failure 500 {object} PostResponse "Internal server error"
// @Router /posts/search [get] // @Router /api/posts/search [get]
func (h *PostHandler) SearchPosts(w http.ResponseWriter, r *http.Request) { func (h *PostHandler) SearchPosts(w http.ResponseWriter, r *http.Request) {
query := strings.TrimSpace(r.URL.Query().Get("q")) query := strings.TrimSpace(r.URL.Query().Get("q"))
limit, offset := parsePagination(r) limit, offset := parsePagination(r)
@@ -264,7 +264,7 @@ func (h *PostHandler) SearchPosts(w http.ResponseWriter, r *http.Request) {
// @Failure 403 {object} PostResponse "Not authorized to update this post" // @Failure 403 {object} PostResponse "Not authorized to update this post"
// @Failure 404 {object} PostResponse "Post not found" // @Failure 404 {object} PostResponse "Post not found"
// @Failure 500 {object} PostResponse "Internal server error" // @Failure 500 {object} PostResponse "Internal server error"
// @Router /posts/{id} [put] // @Router /api/posts/{id} [put]
func (h *PostHandler) UpdatePost(w http.ResponseWriter, r *http.Request) { func (h *PostHandler) UpdatePost(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -343,7 +343,7 @@ func (h *PostHandler) UpdatePost(w http.ResponseWriter, r *http.Request) {
// @Failure 403 {object} PostResponse "Not authorized to delete this post" // @Failure 403 {object} PostResponse "Not authorized to delete this post"
// @Failure 404 {object} PostResponse "Post not found" // @Failure 404 {object} PostResponse "Post not found"
// @Failure 500 {object} PostResponse "Internal server error" // @Failure 500 {object} PostResponse "Internal server error"
// @Router /posts/{id} [delete] // @Router /api/posts/{id} [delete]
func (h *PostHandler) DeletePost(w http.ResponseWriter, r *http.Request) { func (h *PostHandler) DeletePost(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -388,7 +388,7 @@ func (h *PostHandler) DeletePost(w http.ResponseWriter, r *http.Request) {
// @Failure 400 {object} PostResponse "Invalid URL or URL parameter missing" // @Failure 400 {object} PostResponse "Invalid URL or URL parameter missing"
// @Failure 501 {object} PostResponse "Title fetching is not available" // @Failure 501 {object} PostResponse "Title fetching is not available"
// @Failure 502 {object} PostResponse "Failed to fetch title from URL" // @Failure 502 {object} PostResponse "Failed to fetch title from URL"
// @Router /posts/title [get] // @Router /api/posts/title [get]
func (h *PostHandler) FetchTitleFromURL(w http.ResponseWriter, r *http.Request) { func (h *PostHandler) FetchTitleFromURL(w http.ResponseWriter, r *http.Request) {
if h.titleFetcher == nil { if h.titleFetcher == nil {
SendErrorResponse(w, "Title fetching is not available", http.StatusNotImplemented) SendErrorResponse(w, "Title fetching is not available", http.StatusNotImplemented)

View File

@@ -36,7 +36,7 @@ type UserResponse = CommonResponse
// @Success 200 {object} UserResponse "Users retrieved successfully" // @Success 200 {object} UserResponse "Users retrieved successfully"
// @Failure 401 {object} UserResponse "Authentication required" // @Failure 401 {object} UserResponse "Authentication required"
// @Failure 500 {object} UserResponse "Internal server error" // @Failure 500 {object} UserResponse "Internal server error"
// @Router /users [get] // @Router /api/users [get]
func (h *UserHandler) GetUsers(w http.ResponseWriter, r *http.Request) { func (h *UserHandler) GetUsers(w http.ResponseWriter, r *http.Request) {
limit, offset := parsePagination(r) limit, offset := parsePagination(r)
@@ -68,7 +68,7 @@ func (h *UserHandler) GetUsers(w http.ResponseWriter, r *http.Request) {
// @Failure 401 {object} UserResponse "Authentication required" // @Failure 401 {object} UserResponse "Authentication required"
// @Failure 404 {object} UserResponse "User not found" // @Failure 404 {object} UserResponse "User not found"
// @Failure 500 {object} UserResponse "Internal server error" // @Failure 500 {object} UserResponse "Internal server error"
// @Router /users/{id} [get] // @Router /api/users/{id} [get]
func (h *UserHandler) GetUser(w http.ResponseWriter, r *http.Request) { func (h *UserHandler) GetUser(w http.ResponseWriter, r *http.Request) {
userID, ok := ParseUintParam(w, r, "id", "User") userID, ok := ParseUintParam(w, r, "id", "User")
if !ok { if !ok {
@@ -97,7 +97,7 @@ func (h *UserHandler) GetUser(w http.ResponseWriter, r *http.Request) {
// @Failure 401 {object} UserResponse "Authentication required" // @Failure 401 {object} UserResponse "Authentication required"
// @Failure 409 {object} UserResponse "Username or email already exists" // @Failure 409 {object} UserResponse "Username or email already exists"
// @Failure 500 {object} UserResponse "Internal server error" // @Failure 500 {object} UserResponse "Internal server error"
// @Router /users [post] // @Router /api/users [post]
func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request) { func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request) {
var req struct { var req struct {
Username string `json:"username"` Username string `json:"username"`
@@ -155,7 +155,7 @@ func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request) {
// @Failure 400 {object} UserResponse "Invalid user ID or pagination parameters" // @Failure 400 {object} UserResponse "Invalid user ID or pagination parameters"
// @Failure 401 {object} UserResponse "Authentication required" // @Failure 401 {object} UserResponse "Authentication required"
// @Failure 500 {object} UserResponse "Internal server error" // @Failure 500 {object} UserResponse "Internal server error"
// @Router /users/{id}/posts [get] // @Router /api/users/{id}/posts [get]
func (h *UserHandler) GetUserPosts(w http.ResponseWriter, r *http.Request) { func (h *UserHandler) GetUserPosts(w http.ResponseWriter, r *http.Request) {
userID, ok := ParseUintParam(w, r, "id", "User") userID, ok := ParseUintParam(w, r, "id", "User")
if !ok { if !ok {

View File

@@ -70,7 +70,7 @@ type VoteResponse = CommonResponse
// @Failure 500 {object} VoteResponse "Internal server error" // @Failure 500 {object} VoteResponse "Internal server error"
// @Example 200 {"success": true, "message": "Vote cast successfully", "data": {"post_id": 1, "type": "up", "up_votes": 5, "down_votes": 2, "score": 3, "is_anonymous": false}} // @Example 200 {"success": true, "message": "Vote cast successfully", "data": {"post_id": 1, "type": "up", "up_votes": 5, "down_votes": 2, "score": 3, "is_anonymous": false}}
// @Example 400 {"success": false, "error": "Invalid vote type. Must be 'up', 'down', or 'none'"} // @Example 400 {"success": false, "error": "Invalid vote type. Must be 'up', 'down', or 'none'"}
// @Router /posts/{id}/vote [post] // @Router /api/posts/{id}/vote [post]
func (h *VoteHandler) CastVote(w http.ResponseWriter, r *http.Request) { func (h *VoteHandler) CastVote(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -140,7 +140,7 @@ func (h *VoteHandler) CastVote(w http.ResponseWriter, r *http.Request) {
// @Failure 400 {object} VoteResponse "Invalid post ID" // @Failure 400 {object} VoteResponse "Invalid post ID"
// @Failure 404 {object} VoteResponse "Post not found" // @Failure 404 {object} VoteResponse "Post not found"
// @Failure 500 {object} VoteResponse "Internal server error" // @Failure 500 {object} VoteResponse "Internal server error"
// @Router /posts/{id}/vote [delete] // @Router /api/posts/{id}/vote [delete]
func (h *VoteHandler) RemoveVote(w http.ResponseWriter, r *http.Request) { func (h *VoteHandler) RemoveVote(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -198,7 +198,7 @@ func (h *VoteHandler) RemoveVote(w http.ResponseWriter, r *http.Request) {
// @Failure 500 {object} VoteResponse "Internal server error" // @Failure 500 {object} VoteResponse "Internal server error"
// @Example 200 {"success": true, "message": "Vote retrieved successfully", "data": {"has_vote": true, "vote": {"type": "up", "user_id": 123}, "is_anonymous": false}} // @Example 200 {"success": true, "message": "Vote retrieved successfully", "data": {"has_vote": true, "vote": {"type": "up", "user_id": 123}, "is_anonymous": false}}
// @Example 200 {"success": true, "message": "No vote found", "data": {"has_vote": false, "vote": null, "is_anonymous": false}} // @Example 200 {"success": true, "message": "No vote found", "data": {"has_vote": false, "vote": null, "is_anonymous": false}}
// @Router /posts/{id}/vote [get] // @Router /api/posts/{id}/vote [get]
func (h *VoteHandler) GetUserVote(w http.ResponseWriter, r *http.Request) { func (h *VoteHandler) GetUserVote(w http.ResponseWriter, r *http.Request) {
userID, ok := RequireAuth(w, r) userID, ok := RequireAuth(w, r)
if !ok { if !ok {
@@ -253,7 +253,7 @@ func (h *VoteHandler) GetUserVote(w http.ResponseWriter, r *http.Request) {
// @Failure 401 {object} VoteResponse "Authentication required" // @Failure 401 {object} VoteResponse "Authentication required"
// @Failure 500 {object} VoteResponse "Internal server error" // @Failure 500 {object} VoteResponse "Internal server error"
// @Example 200 {"success": true, "message": "Votes retrieved successfully", "data": {"votes": [{"type": "up", "user_id": 123}, {"type": "down", "vote_hash": "abc123"}], "count": 2}} // @Example 200 {"success": true, "message": "Votes retrieved successfully", "data": {"votes": [{"type": "up", "user_id": 123}, {"type": "down", "vote_hash": "abc123"}], "count": 2}}
// @Router /posts/{id}/votes [get] // @Router /api/posts/{id}/votes [get]
func (h *VoteHandler) GetPostVotes(w http.ResponseWriter, r *http.Request) { func (h *VoteHandler) GetPostVotes(w http.ResponseWriter, r *http.Request) {
postID, ok := ParseUintParam(w, r, "id", "Post") postID, ok := ParseUintParam(w, r, "id", "Post")
if !ok { if !ok {