chore: regenerated swagger;
chore: removed deprecated and unused stuff
This commit is contained in:
@@ -18,26 +18,6 @@ const docTemplate = `{
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/account/changePassword": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Account"
|
||||
],
|
||||
"summary": "Change account password",
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/auth/changePassword": {
|
||||
"post": {
|
||||
"security": [
|
||||
@@ -289,113 +269,6 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/profile": {
|
||||
"patch": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Update profile",
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/profile/me": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Get own profile when authorized",
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/profile/privacy": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Get profile privacy settings",
|
||||
"responses": {}
|
||||
},
|
||||
"patch": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Update profile privacy settings",
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/profile/{username}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Get someone's profile details",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Username",
|
||||
"name": "username",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/service/health": {
|
||||
"get": {
|
||||
"description": "Used internally for checking service health",
|
||||
|
||||
@@ -14,26 +14,6 @@
|
||||
},
|
||||
"basePath": "/api/",
|
||||
"paths": {
|
||||
"/account/changePassword": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Account"
|
||||
],
|
||||
"summary": "Change account password",
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/auth/changePassword": {
|
||||
"post": {
|
||||
"security": [
|
||||
@@ -285,113 +265,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/profile": {
|
||||
"patch": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Update profile",
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/profile/me": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Get own profile when authorized",
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/profile/privacy": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Get profile privacy settings",
|
||||
"responses": {}
|
||||
},
|
||||
"patch": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Update profile privacy settings",
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/profile/{username}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"JWT": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Profile"
|
||||
],
|
||||
"summary": "Get someone's profile details",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Username",
|
||||
"name": "username",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/service/health": {
|
||||
"get": {
|
||||
"description": "Used internally for checking service health",
|
||||
|
||||
@@ -126,18 +126,6 @@ info:
|
||||
title: Easywish client API
|
||||
version: "1.0"
|
||||
paths:
|
||||
/account/changePassword:
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
responses: {}
|
||||
security:
|
||||
- JWT: []
|
||||
summary: Change account password
|
||||
tags:
|
||||
- Account
|
||||
/auth/changePassword:
|
||||
post:
|
||||
consumes:
|
||||
@@ -297,71 +285,6 @@ paths:
|
||||
summary: Confirm with code, finish creating the account
|
||||
tags:
|
||||
- Auth
|
||||
/profile:
|
||||
patch:
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
responses: {}
|
||||
security:
|
||||
- JWT: []
|
||||
summary: Update profile
|
||||
tags:
|
||||
- Profile
|
||||
/profile/{username}:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: Username
|
||||
in: path
|
||||
name: username
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses: {}
|
||||
security:
|
||||
- JWT: []
|
||||
summary: Get someone's profile details
|
||||
tags:
|
||||
- Profile
|
||||
/profile/me:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
responses: {}
|
||||
security:
|
||||
- JWT: []
|
||||
summary: Get own profile when authorized
|
||||
tags:
|
||||
- Profile
|
||||
/profile/privacy:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
responses: {}
|
||||
security:
|
||||
- JWT: []
|
||||
summary: Get profile privacy settings
|
||||
tags:
|
||||
- Profile
|
||||
patch:
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
responses: {}
|
||||
security:
|
||||
- JWT: []
|
||||
summary: Update profile privacy settings
|
||||
tags:
|
||||
- Profile
|
||||
/service/health:
|
||||
get:
|
||||
consumes:
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
// Copyright (c) 2025 Nikolai Papin
|
||||
//
|
||||
// This file is part of Easywish
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
// the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"easywish/internal/dto"
|
||||
"easywish/internal/utils/enums"
|
||||
"easywish/internal/validation"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
const requestKey = "request"
|
||||
|
||||
// Deprecated: no longer used, embedded into controllers.GetRequest instead
|
||||
func ClientInfoFromContext(c *gin.Context) (*dto.ClientInfo, bool) {
|
||||
|
||||
var ok bool
|
||||
|
||||
ip := c.ClientIP()
|
||||
userAgent := c.Request.UserAgent()
|
||||
|
||||
sessionInfoFromCtx, ok := c.Get("session_info"); if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
sessionInfo := sessionInfoFromCtx.(dto.SessionInfo)
|
||||
|
||||
if sessionInfo.Username == "" {
|
||||
return &dto.ClientInfo{
|
||||
SessionInfo: sessionInfo,
|
||||
IP: ip,
|
||||
UserAgent: userAgent,
|
||||
}, true
|
||||
}
|
||||
|
||||
return &dto.ClientInfo{
|
||||
SessionInfo: sessionInfo,
|
||||
IP: ip,
|
||||
UserAgent: userAgent,
|
||||
}, true
|
||||
}
|
||||
|
||||
// Deprecated: no longer used, see controllers.GetRequest
|
||||
func RequestFromContext[T any](c *gin.Context) dto.Request[T] {
|
||||
return c.Value(requestKey).(dto.Request[T])
|
||||
}
|
||||
|
||||
// Deprecated: no longer used, see controllers.GetRequest
|
||||
func RequestMiddleware[T any](role enums.Role) gin.HandlerFunc {
|
||||
return gin.HandlerFunc(func(c *gin.Context) {
|
||||
|
||||
clientInfo, ok := ClientInfoFromContext(c)
|
||||
|
||||
if !ok {
|
||||
c.Status(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if clientInfo.Role < role {
|
||||
c.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
var body T
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
validate := validation.NewValidator()
|
||||
|
||||
if err := validate.Struct(body); err != nil {
|
||||
errorList := err.(validator.ValidationErrors)
|
||||
c.String(http.StatusBadRequest, fmt.Sprintf("Validation error: %s", errorList))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
request := dto.Request[T]{
|
||||
User: *clientInfo,
|
||||
Body: body,
|
||||
}
|
||||
|
||||
c.Set(requestKey, request)
|
||||
c.Next()
|
||||
})
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
// Copyright (c) 2025 Nikolai Papin
|
||||
//
|
||||
// This file is part of Easywish
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
// the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"easywish/internal/controllers"
|
||||
"easywish/internal/middleware"
|
||||
"easywish/internal/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Deprecated: no longer used, see controllers
|
||||
func NewRouter(engine *gin.Engine, log *zap.Logger, auth services.AuthService, groups []RouteGroup) *gin.Engine {
|
||||
apiGroup := engine.Group("/api")
|
||||
apiGroup.Use(middleware.AuthMiddleware(log, auth))
|
||||
for _, group := range groups {
|
||||
subgroup := apiGroup.Group(group.BasePath)
|
||||
subgroup.Use(group.Middleware...)
|
||||
group.Router.RegisterRoutes(subgroup)
|
||||
}
|
||||
return engine
|
||||
}
|
||||
|
||||
// Deprecated: no longer used, see controllers
|
||||
type RouteGroup struct {
|
||||
BasePath string
|
||||
Middleware []gin.HandlerFunc
|
||||
Router controllers.Router
|
||||
}
|
||||
|
||||
// func NewRouteGroups(
|
||||
// authController controllers.AuthController,
|
||||
// serviceController controllers.ServiceController,
|
||||
// profileController controllers.ProfileController,
|
||||
// ) []RouteGroup {
|
||||
// return []RouteGroup{
|
||||
// {
|
||||
// BasePath: "/auth",
|
||||
// Router: authController,
|
||||
// },
|
||||
// {
|
||||
// BasePath: "/service",
|
||||
// Router: serviceController,
|
||||
// },
|
||||
// {
|
||||
// BasePath: "/profile",
|
||||
// Router: profileController,
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
@@ -1,30 +0,0 @@
|
||||
// Copyright (c) 2025 Nikolai Papin
|
||||
//
|
||||
// This file is part of Easywish
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
// the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package routes
|
||||
|
||||
import (
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// Deprecated: no longer used, see controllers
|
||||
var Module = fx.Module("routes",
|
||||
// fx.Provide(
|
||||
// NewRouteGroups,
|
||||
// ),
|
||||
// fx.Invoke(NewRouter),
|
||||
)
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) 2025 Nikolai Papin
|
||||
//
|
||||
// This file is part of Easywish
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
// the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"easywish/internal/dto"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Deprecated: use controllers.GetRequest method for the new controllers
|
||||
func GetRequest[T any](c *gin.Context) (*dto.Request[T], bool) {
|
||||
|
||||
req, ok := c.Get("request")
|
||||
request := req.(dto.Request[T])
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return &request, true
|
||||
}
|
||||
Reference in New Issue
Block a user