mirror of
https://git.freecumextremist.com/grumbulon/pomme.git
synced 2024-11-22 05:03:45 +00:00
updated swagger docs to look more like Gitea, moved all structs to types.go, removed username from response struct, removed other unnecessary code
This commit is contained in:
parent
3e839fdf5f
commit
277de26561
12 changed files with 5497 additions and 182 deletions
57
docs/docs.go
57
docs/docs.go
|
@ -50,13 +50,13 @@ const docTemplate = `{
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpSuccess"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Unauthorized",
|
||||
"description": "authFailed is a 401 error when logging in fails, includes realm",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpError"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,13 +100,13 @@ const docTemplate = `{
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpSuccess"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"description": "internalServerError is a 500 server error with a logged error call back",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpInternalServerError"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,13 +150,13 @@ const docTemplate = `{
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpSuccess"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"description": "internalServerError is a 500 server error with a logged error call back",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpInternalServerError"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,42 +164,27 @@ const docTemplate = `{
|
|||
}
|
||||
},
|
||||
"definitions": {
|
||||
"api.httpError": {
|
||||
"internal.GenericResponse-internal_Response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"example": 401
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"example": "Status bad request"
|
||||
"response": {
|
||||
"description": "Response items",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/internal.Response"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.httpInternalServerError": {
|
||||
"internal.Response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"example": 500
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"example": "Internal Server Error"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.httpSuccess": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"example": 200
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"example": "Success"
|
||||
"status": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,13 +41,13 @@
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpSuccess"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Unauthorized",
|
||||
"description": "authFailed is a 401 error when logging in fails, includes realm",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpError"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,13 +91,13 @@
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpSuccess"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"description": "internalServerError is a 500 server error with a logged error call back",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpInternalServerError"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -141,13 +141,13 @@
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpSuccess"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"description": "internalServerError is a 500 server error with a logged error call back",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.httpInternalServerError"
|
||||
"$ref": "#/definitions/internal.GenericResponse-internal_Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,42 +155,27 @@
|
|||
}
|
||||
},
|
||||
"definitions": {
|
||||
"api.httpError": {
|
||||
"internal.GenericResponse-internal_Response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"example": 401
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"example": "Status bad request"
|
||||
"response": {
|
||||
"description": "Response items",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/internal.Response"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.httpInternalServerError": {
|
||||
"internal.Response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"example": 500
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"example": "Internal Server Error"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.httpSuccess": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"example": 200
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"example": "Success"
|
||||
"status": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,17 @@
|
|||
definitions:
|
||||
api.httpError:
|
||||
internal.GenericResponse-internal_Response:
|
||||
properties:
|
||||
code:
|
||||
example: 401
|
||||
type: integer
|
||||
message:
|
||||
example: Status bad request
|
||||
type: string
|
||||
response:
|
||||
allOf:
|
||||
- $ref: '#/definitions/internal.Response'
|
||||
description: Response items
|
||||
type: object
|
||||
api.httpInternalServerError:
|
||||
internal.Response:
|
||||
properties:
|
||||
code:
|
||||
example: 500
|
||||
type: integer
|
||||
message:
|
||||
example: Internal Server Error
|
||||
type: string
|
||||
type: object
|
||||
api.httpSuccess:
|
||||
properties:
|
||||
code:
|
||||
example: 200
|
||||
status:
|
||||
type: integer
|
||||
message:
|
||||
example: Success
|
||||
type: string
|
||||
type: object
|
||||
info:
|
||||
contact: {}
|
||||
|
@ -57,11 +44,11 @@ paths:
|
|||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/api.httpSuccess'
|
||||
$ref: '#/definitions/internal.GenericResponse-internal_Response'
|
||||
"401":
|
||||
description: Unauthorized
|
||||
description: authFailed is a 401 error when logging in fails, includes realm
|
||||
schema:
|
||||
$ref: '#/definitions/api.httpError'
|
||||
$ref: '#/definitions/internal.GenericResponse-internal_Response'
|
||||
summary: authenticate as a regular user
|
||||
tags:
|
||||
- accounts
|
||||
|
@ -90,11 +77,12 @@ paths:
|
|||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/api.httpSuccess'
|
||||
$ref: '#/definitions/internal.GenericResponse-internal_Response'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
description: internalServerError is a 500 server error with a logged error
|
||||
call back
|
||||
schema:
|
||||
$ref: '#/definitions/api.httpInternalServerError'
|
||||
$ref: '#/definitions/internal.GenericResponse-internal_Response'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: parse your zonefile
|
||||
|
@ -125,11 +113,12 @@ paths:
|
|||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/api.httpSuccess'
|
||||
$ref: '#/definitions/internal.GenericResponse-internal_Response'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
description: internalServerError is a 500 server error with a logged error
|
||||
call back
|
||||
schema:
|
||||
$ref: '#/definitions/api.httpInternalServerError'
|
||||
$ref: '#/definitions/internal.GenericResponse-internal_Response'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: upload a zonefile
|
||||
|
|
5366
frontend/package-lock.json
generated
Normal file
5366
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -49,7 +49,6 @@ func setDBMiddleware(next http.Handler) http.Handler {
|
|||
|
||||
// handlers for very common errors.
|
||||
func authFailed(w http.ResponseWriter, r *http.Request, realm string) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Header().Add("WWW-Authenticate", fmt.Sprintf(`Realm="%s"`, realm))
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
|
|
|
@ -10,25 +10,6 @@ import (
|
|||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// These are used for documentation, might be removed later
|
||||
// nolint: unused
|
||||
type httpError struct {
|
||||
Message string `json:"message" example:"Status bad request"`
|
||||
Code int `json:"code" example:"401"`
|
||||
}
|
||||
|
||||
// nolint: unused
|
||||
type httpSuccess struct {
|
||||
Message string `json:"message" example:"Success"`
|
||||
Code int `json:"code" example:"200"`
|
||||
}
|
||||
|
||||
// nolint: unused
|
||||
type httpInternalServerError struct {
|
||||
Message string `json:"message" example:"Internal Server Error"`
|
||||
Code int `json:"code" example:"500"`
|
||||
}
|
||||
|
||||
// Auth godoc
|
||||
//
|
||||
// @Summary authenticate as a regular user
|
||||
|
@ -41,8 +22,8 @@ type httpInternalServerError struct {
|
|||
// @Produce json
|
||||
// @Param username query string true "Username"
|
||||
// @Param password query string true "Password"
|
||||
// @Success 200 {object} httpSuccess
|
||||
// @Failure 401 {object} httpError
|
||||
// @Success 200 {object} internal.GenericResponse[internal.Response]
|
||||
// @failure 401 {object} internal.GenericResponse[internal.Response] "authFailed is a 401 error when logging in fails, includes realm"
|
||||
// @Router /api/login [post]
|
||||
func Login(w http.ResponseWriter, r *http.Request) {
|
||||
var result internal.User
|
||||
|
|
File diff suppressed because one or more lines are too long
18
internal/api/types.go
Normal file
18
internal/api/types.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package api
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
// ZoneRequest represents a Zone file request.
|
||||
type ZoneRequest struct {
|
||||
*Zone
|
||||
|
||||
User string `json:"user,omitempty" gorm:"foreignKey:username;references:User"`
|
||||
}
|
||||
|
||||
// Zone struct represents a zonefile.
|
||||
type Zone struct {
|
||||
gorm.Model
|
||||
FileName string `json:"name"`
|
||||
RawFileName string `json:"rawname"`
|
||||
Body string `json:"body,omitempty"`
|
||||
}
|
|
@ -82,7 +82,6 @@ func NewUser(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err = json.NewEncoder(w).Encode(
|
||||
internal.Response{
|
||||
Username: username,
|
||||
HTTPResponse: http.StatusCreated,
|
||||
Message: "Successfully created account and logged in",
|
||||
})
|
||||
|
|
|
@ -18,21 +18,6 @@ import (
|
|||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// ZoneRequest represents a Zone file request.
|
||||
type ZoneRequest struct {
|
||||
*Zone
|
||||
|
||||
User string `json:"user,omitempty" gorm:"foreignKey:username;references:User"`
|
||||
}
|
||||
|
||||
// Zone struct represents a zonefile.
|
||||
type Zone struct {
|
||||
gorm.Model
|
||||
FileName string `json:"name"`
|
||||
RawFileName string `json:"rawname"`
|
||||
Body string `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// Upload godoc
|
||||
//
|
||||
// @Summary upload a zonefile
|
||||
|
@ -45,8 +30,8 @@ type Zone struct {
|
|||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Param file formData file true "Zonefile to upload"
|
||||
// @Success 200 {object} httpSuccess
|
||||
// @Failure 500 {object} httpInternalServerError
|
||||
// @Success 200 {object} internal.GenericResponse[internal.Response]
|
||||
// @Failure 500 {object} internal.GenericResponse[internal.Response] "internalServerError is a 500 server error with a logged error call back"
|
||||
// @Param Authorization header string true "Bearer Token"
|
||||
//
|
||||
// @Security Bearer
|
||||
|
@ -134,8 +119,8 @@ func ReceiveFile(w http.ResponseWriter, r *http.Request) {
|
|||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Param filename query string true "Zonefile name"
|
||||
// @Success 200 {object} httpSuccess
|
||||
// @Failure 500 {object} httpInternalServerError
|
||||
// @Success 200 {object} internal.GenericResponse[internal.Response]
|
||||
// @Failure 500 {object} internal.GenericResponse[internal.Response] "internalServerError is a 500 server error with a logged error call back"
|
||||
// @Param Authorization header string true "Bearer Token"
|
||||
//
|
||||
// @Security Bearer
|
||||
|
|
|
@ -7,46 +7,8 @@ import (
|
|||
|
||||
"github.com/adrg/xdg"
|
||||
"gopkg.in/yaml.v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// User struct represents a user in the database.
|
||||
type User struct {
|
||||
gorm.Model
|
||||
Username string
|
||||
HashedPassword string
|
||||
}
|
||||
|
||||
// Response struct represents a json response.
|
||||
type Response struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
HTTPResponse int `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// ZoneRequest represents a Zone file request.
|
||||
type ZoneRequest struct {
|
||||
*Zone
|
||||
|
||||
User string `json:"user,omitempty" gorm:"foreignKey:username;references:User"`
|
||||
}
|
||||
|
||||
// Zone struct represents a zonefile in the database.
|
||||
type Zone struct {
|
||||
gorm.Model
|
||||
FileName string `json:"name"`
|
||||
RawFileName string `json:"rawfilename"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Server string
|
||||
HashingSecret string
|
||||
Port string
|
||||
DB string
|
||||
TestDB string
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
||||
func ReadConfig() (*Config, error) {
|
||||
|
|
46
internal/types.go
Normal file
46
internal/types.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package internal
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
// User struct represents a user in the database.
|
||||
type User struct {
|
||||
gorm.Model
|
||||
Username string
|
||||
HashedPassword string
|
||||
}
|
||||
|
||||
// Response struct represents a json response.
|
||||
type Response struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
HTTPResponse int `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// ZoneRequest represents a Zone file request.
|
||||
type ZoneRequest struct {
|
||||
*Zone
|
||||
|
||||
User string `json:"user,omitempty" gorm:"foreignKey:username;references:User"`
|
||||
}
|
||||
|
||||
// Zone struct represents a zonefile in the database.
|
||||
type Zone struct {
|
||||
gorm.Model
|
||||
FileName string `json:"name"`
|
||||
RawFileName string `json:"rawfilename"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Server string
|
||||
HashingSecret string
|
||||
Port string
|
||||
DB string
|
||||
TestDB string
|
||||
}
|
||||
|
||||
// GenericNestedResponse[T]
|
||||
// @Description Some Generic List Response.
|
||||
type GenericResponse[T any] struct {
|
||||
// Response items
|
||||
Response T
|
||||
}
|
Loading…
Reference in a new issue