Fix settings data

This commit is contained in:
Jamie Curnow
2021-07-26 13:50:44 +10:00
parent 93721ef2d8
commit 2326a95d2a
5 changed files with 18 additions and 11 deletions

View File

@@ -2,11 +2,7 @@
"type": "object", "type": "object",
"description": "SettingObject", "description": "SettingObject",
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": ["id", "name", "value"],
"id",
"name",
"value"
],
"properties": { "properties": {
"id": { "id": {
"type": "integer", "type": "integer",
@@ -25,6 +21,11 @@
"minLength": 2, "minLength": 2,
"maxLength": 100 "maxLength": 100
}, },
"description": {
"type": "string",
"minLength": 0,
"maxLength": 100
},
"value": { "value": {
"oneOf": [ "oneOf": [
{ {
@@ -38,6 +39,9 @@
}, },
{ {
"type": "integer" "type": "integer"
},
{
"type": "string"
} }
] ]
} }

View File

@@ -32,7 +32,7 @@ CREATE TABLE IF NOT EXISTS `setting`
created_on INTEGER NOT NULL DEFAULT 0, created_on INTEGER NOT NULL DEFAULT 0,
modified_on INTEGER NOT NULL DEFAULT 0, modified_on INTEGER NOT NULL DEFAULT 0,
name TEXT NOT NULL, name TEXT NOT NULL,
description TEXT NOT NULL, description TEXT NOT NULL DEFAULT "",
value TEXT NOT NULL, value TEXT NOT NULL,
UNIQUE (name) UNIQUE (name)
); );

View File

@@ -11,8 +11,8 @@ INSERT INTO `setting` (
strftime('%s', 'now'), strftime('%s', 'now'),
strftime('%s', 'now'), strftime('%s', 'now'),
"error-reporting", "error-reporting",
"If enabled, any application errors are reported to Sentry. Sensitive information is not sent. All information sent is also private.", "If enabled, any application errors are reported to Sentry. Sensitive information is not sent.",
"true" "true" -- remember this is json
); );
-- Default site -- Default site
@@ -27,7 +27,7 @@ INSERT INTO `setting` (
strftime('%s', 'now'), strftime('%s', 'now'),
"default-site", "default-site",
"What to show users who hit your Nginx server by default", "What to show users who hit your Nginx server by default",
"welcome" '"welcome"' -- remember this is json
); );
-- Default Certificate Authorities -- Default Certificate Authorities

View File

@@ -8,6 +8,7 @@ import (
"npm/internal/database" "npm/internal/database"
"npm/internal/entity" "npm/internal/entity"
"npm/internal/errors" "npm/internal/errors"
"npm/internal/logger"
"npm/internal/model" "npm/internal/model"
) )
@@ -100,6 +101,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (ListResponse, error)
var totalRows int var totalRows int
queryErr := countRow.Scan(&totalRows) queryErr := countRow.Scan(&totalRows)
if queryErr != nil && queryErr != sql.ErrNoRows { if queryErr != nil && queryErr != sql.ErrNoRows {
logger.Debug("%+v", queryErr)
return result, queryErr return result, queryErr
} }
@@ -108,6 +110,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (ListResponse, error)
query, params = entity.ListQueryBuilder(exampleModel, tableName, &pageInfo, defaultSort, filters, getFilterMapFunctions(), false) query, params = entity.ListQueryBuilder(exampleModel, tableName, &pageInfo, defaultSort, filters, getFilterMapFunctions(), false)
err := db.Select(&items, query, params...) err := db.Select(&items, query, params...)
if err != nil { if err != nil {
logger.Debug("%+v", err)
return result, err return result, err
} }

View File

@@ -4,7 +4,7 @@ import (
"npm/internal/model" "npm/internal/model"
) )
// ListResponse is the JSON response for users list // ListResponse is the JSON response for settings list
type ListResponse struct { type ListResponse struct {
Total int `json:"total"` Total int `json:"total"`
Offset int `json:"offset"` Offset int `json:"offset"`