Генерирование роутов для учеток пользователей
This commit is contained in:
parent
550da898b4
commit
a163388557
|
@ -11,18 +11,22 @@ licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
host: example.com
|
host: example.com
|
||||||
basePath: /api
|
basePath: /api
|
||||||
db:
|
db:
|
||||||
|
sqlite: true
|
||||||
tables:
|
tables:
|
||||||
- name: test___test_1
|
- name: test___test_1
|
||||||
pk: uuid
|
pk: uuid
|
||||||
fields:
|
fields:
|
||||||
- name: f1
|
- name: f1
|
||||||
|
recursive: true
|
||||||
- name: test2
|
- name: test2
|
||||||
pk: int
|
pk: int
|
||||||
fields:
|
fields:
|
||||||
- name: f1
|
- name: f1
|
||||||
- name: f2
|
- name: f2
|
||||||
fks:
|
fks:
|
||||||
- name: test1
|
- name: test___test_1
|
||||||
|
tableName: test___test_1
|
||||||
|
|
||||||
backend:
|
backend:
|
||||||
config:
|
config:
|
||||||
- name: nominatim
|
- name: nominatim
|
||||||
|
@ -31,3 +35,5 @@ backend:
|
||||||
- name: tile_server
|
- name: tile_server
|
||||||
type: string
|
type: string
|
||||||
help: Tile server for download tiles map
|
help: Tile server for download tiles map
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
|
|
@ -127,7 +127,7 @@ func generateModelBase() {
|
||||||
if err := PrepareTmplFile("tmpl/backend/main.tmpl", Project, filepath.Join(AppConfig.OutdirBackend, "main.go")); err != nil {
|
if err := PrepareTmplFile("tmpl/backend/main.tmpl", Project, filepath.Join(AppConfig.OutdirBackend, "main.go")); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := PrepareTmplFile("tmpl/backend/lib/config.tmpl", Project.Backend, filepath.Join(AppConfig.OutdirBackend, "lib", "config.go")); err != nil {
|
if err := PrepareTmplFile("tmpl/backend/lib/config.tmpl", Project, filepath.Join(AppConfig.OutdirBackend, "lib", "config.go")); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,9 @@ func execCommands() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
strs := strings.Split(string(buff), "\n")
|
strs := strings.Split(string(buff), "\n")
|
||||||
|
if Project.DB.SQLite {
|
||||||
|
strs = append(strs, "gorm.io/driver/sqlite")
|
||||||
|
}
|
||||||
if len(strs) > 0 {
|
if len(strs) > 0 {
|
||||||
for _, str := range strs {
|
for _, str := range strs {
|
||||||
cmd := exec.Command("go", "get", str)
|
cmd := exec.Command("go", "get", str)
|
||||||
|
|
|
@ -40,7 +40,7 @@ func PrepareMetadata(project *structs.Project) {
|
||||||
}
|
}
|
||||||
if project.DB.Tables[i].Recursive {
|
if project.DB.Tables[i].Recursive {
|
||||||
project.DB.Tables[i].FkFields = append(project.DB.Tables[i].FkFields, structs.Field{
|
project.DB.Tables[i].FkFields = append(project.DB.Tables[i].FkFields, structs.Field{
|
||||||
Name: "parent_id",
|
Name: "parent",
|
||||||
Description: "Recursive foreign key for self table",
|
Description: "Recursive foreign key for self table",
|
||||||
})
|
})
|
||||||
switch project.DB.Tables[i].Pk {
|
switch project.DB.Tables[i].Pk {
|
||||||
|
@ -61,8 +61,13 @@ func PrepareMetadata(project *structs.Project) {
|
||||||
}
|
}
|
||||||
if project.DB.Tables[i].FKs[j].TableID == uuid.Nil && project.DB.Tables[i].FKs[j].TableName != "" {
|
if project.DB.Tables[i].FKs[j].TableID == uuid.Nil && project.DB.Tables[i].FKs[j].TableName != "" {
|
||||||
for k := range project.DB.Tables {
|
for k := range project.DB.Tables {
|
||||||
if project.DB.Tables[i].Name == project.DB.Tables[i].FKs[j].TableName {
|
if project.DB.Tables[k].Name == project.DB.Tables[i].FKs[j].TableName {
|
||||||
project.DB.Tables[i].FKs[j].TableID = project.DB.Tables[k].ID
|
project.DB.Tables[i].FKs[j].TableID = project.DB.Tables[k].ID
|
||||||
|
project.DB.Tables[i].FKs[j].Type = project.DB.Tables[k].Pk
|
||||||
|
/*project.DB.Tables[i].FkFields = append(project.DB.Tables[i].FkFields, structs.Field{
|
||||||
|
Name: fmt.Sprintf("%s", project.DB.Tables[k].Name),
|
||||||
|
Type: project.DB.Tables[k].Pk,
|
||||||
|
})*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +75,7 @@ func PrepareMetadata(project *structs.Project) {
|
||||||
for k := range project.DB.Tables {
|
for k := range project.DB.Tables {
|
||||||
if project.DB.Tables[k].ID == project.DB.Tables[i].FKs[j].TableID {
|
if project.DB.Tables[k].ID == project.DB.Tables[i].FKs[j].TableID {
|
||||||
project.DB.Tables[i].FKs[j].TableName = project.DB.Tables[k].Name
|
project.DB.Tables[i].FKs[j].TableName = project.DB.Tables[k].Name
|
||||||
|
project.DB.Tables[k].Children = append(project.DB.Tables[k].Children, project.DB.Tables[i].Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,8 +83,9 @@ func PrepareMetadata(project *structs.Project) {
|
||||||
log.Fatalf("Error foreign key for '%s' table", project.DB.Tables[i].FKs[j].TableID.String())
|
log.Fatalf("Error foreign key for '%s' table", project.DB.Tables[i].FKs[j].TableID.String())
|
||||||
}
|
}
|
||||||
project.DB.Tables[i].FkFields = append(project.DB.Tables[i].FkFields, structs.Field{
|
project.DB.Tables[i].FkFields = append(project.DB.Tables[i].FkFields, structs.Field{
|
||||||
Name: fmt.Sprintf("%s_id", strings.ToLower(project.DB.Tables[i].FKs[j].TableName)),
|
Name: fmt.Sprintf("%s", strings.ToLower(project.DB.Tables[i].FKs[j].TableName)),
|
||||||
Description: fmt.Sprintf("Foreign key for \"%s\" table", project.DB.Tables[i].FKs[j].TableName),
|
Type: project.DB.Tables[i].Pk,
|
||||||
|
Description: fmt.Sprintf("Foreign key for \\\"%s\\\" table", project.DB.Tables[i].FKs[j].TableName),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,8 @@ func fieldType(field *structs.Field) string {
|
||||||
return "*int"
|
return "*int"
|
||||||
case "bigint":
|
case "bigint":
|
||||||
return "*int64"
|
return "*int64"
|
||||||
|
case "uuid":
|
||||||
|
return "*uuid.UUID"
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Unknow format %s", field.Type)
|
log.Fatalf("Unknow format %s", field.Type)
|
||||||
}
|
}
|
||||||
|
@ -124,6 +126,8 @@ func fieldTypeDB(field *structs.Field) string {
|
||||||
return "INT"
|
return "INT"
|
||||||
case "bigint":
|
case "bigint":
|
||||||
return "BIGINT"
|
return "BIGINT"
|
||||||
|
case "uuid":
|
||||||
|
return "UUID"
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Unknow format %s", field.Type)
|
log.Fatalf("Unknow format %s", field.Type)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"gorm.io/driver/mysql"
|
"gorm.io/driver/mysql"
|
||||||
"gorm.io/driver/postgres"
|
"gorm.io/driver/postgres"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
{{ if .DB.SQLite }}"gorm.io/driver/sqlite"{{ end }}
|
||||||
"gorm.io/gorm/logger"
|
"gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,6 +54,14 @@ func DBConnect() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
{{ if .DB.SQLite }}
|
||||||
|
case "sqlite":
|
||||||
|
dsn := lib.AppConfig.DbPath
|
||||||
|
DB, err = gorm.Open(sqlite.Open(dsn), &conf)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
{{ end }}
|
||||||
default:
|
default:
|
||||||
log.Fatal("Server DB not set")
|
log.Fatal("Server DB not set")
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,11 @@
|
||||||
|
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
type BaseInt struct {
|
type BaseInt struct {
|
||||||
ID uint64 `gorm:"type:autoIncrement;primaryKey" json:"id,omitempty"`
|
ID uint64 `gorm:"primaryKey" json:"id,omitempty"`
|
||||||
CreatedAt time.Time `json:"createdAt,omitempty"`
|
CreatedAt time.Time `json:"createdAt,omitempty"`
|
||||||
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
||||||
DeletedAt gorm.DeletedAt `sql:"index" json:"deletedAt"`
|
// DeletedAt *time.Time `sql:"index" json:"deletedAt"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ type Base struct {
|
||||||
ID uuid.UUID `gorm:"type:uuid;primary_key;" json:"id,omitempty"`
|
ID uuid.UUID `gorm:"type:uuid;primary_key;" json:"id,omitempty"`
|
||||||
CreatedAt time.Time `json:"createdAt,omitempty"`
|
CreatedAt time.Time `json:"createdAt,omitempty"`
|
||||||
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
||||||
DeletedAt gorm.DeletedAt `sql:"index" json:"deletedAt"`
|
// DeletedAt *time.Time `sql:"index" json:"deletedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeforeCreate will set a UUID rather than numeric ID.
|
// BeforeCreate will set a UUID rather than numeric ID.
|
||||||
|
|
|
@ -3,20 +3,30 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
// "time"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// {{ fieldNamePrepare .Name }} {{ .Description}}
|
||||||
type {{ fieldNamePrepare .Name }} struct {
|
type {{ fieldNamePrepare .Name }} struct {
|
||||||
{{ if eq .Pk "uuid" }}
|
{{ if eq .Pk "uuid" }}
|
||||||
Base
|
Base
|
||||||
{{ else }}
|
{{ else }}
|
||||||
BaseInt
|
BaseInt
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ range $index, $field := .Fields }}
|
{{ range $index, $field := .Fields }}
|
||||||
{{ fieldName $field }} {{ fieldType $field }} {{ fieldDescript $field }}
|
{{ fieldName $field }} {{ fieldType $field }} {{ fieldDescript $field }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ range $index, $field := .Children }}
|
||||||
|
{{ fieldNamePrepare $field }} []{{ fieldNamePrepare $field }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ range $index, $field := .FkFields }}
|
||||||
|
{{ fieldName $field }}ID {{ fieldType $field }} {{ fieldDescript $field }}
|
||||||
|
{{ fieldName $field }} *{{ if eq $field.Name "Parent" }}{{ fieldNamePrepare $.Name }}{{ else }}{{ fieldName $field }}{{ end }} {{ fieldDescript $field }}
|
||||||
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ $varNameField := fieldNamePrepare .Name }}
|
{{ $varNameField := fieldNamePrepare .Name }}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
// Роли пользователей
|
// Role Роли пользователей
|
||||||
type Role struct {
|
type Role struct {
|
||||||
Base
|
Base
|
||||||
Name string `gorm:"type:varchar(20);comment:Название роли" json:"name"`
|
Name string `gorm:"type:varchar(20);comment:Название роли" json:"name"`
|
||||||
|
|
|
@ -2,7 +2,7 @@ package model
|
||||||
|
|
||||||
import uuid "github.com/satori/go.uuid"
|
import uuid "github.com/satori/go.uuid"
|
||||||
|
|
||||||
// Связь пользователя и роли
|
// UserRole Связь пользователя и роли
|
||||||
type UserRole struct {
|
type UserRole struct {
|
||||||
Base
|
Base
|
||||||
UserID uuid.UUID `gorm:"column:id_user"`
|
UserID uuid.UUID `gorm:"column:id_user"`
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// User Пользователи
|
||||||
type User struct {
|
type User struct {
|
||||||
Base
|
Base
|
||||||
Login string `json:"login"`
|
Login string `json:"login"`
|
||||||
|
|
|
@ -3,8 +3,11 @@ package lib
|
||||||
var AppConfig struct {
|
var AppConfig struct {
|
||||||
Env string `arg:"-e,env:ENV" default:"prod" help:"Environment for application. dev or prod. Default prod"`
|
Env string `arg:"-e,env:ENV" default:"prod" help:"Environment for application. dev or prod. Default prod"`
|
||||||
MigrateDB bool `arg:"-m,--migrate,env:DB_MIGRATE" default:"false" help:"Run migrate Database"`
|
MigrateDB bool `arg:"-m,--migrate,env:DB_MIGRATE" default:"false" help:"Run migrate Database"`
|
||||||
DBInstance string `arg:"--db-instance,env:DB_INSTANCE" default:"postgres" help:"postgres (PostgreSQL) or mysql (MySQL/MariaDB)"`
|
DBInstance string `arg:"--db-instance,env:DB_INSTANCE" default:"{{ if .DB.SQLite }}sqlite{{ else }}postgres{{ end }}" help:"postgres (PostgreSQL) or mysql (MySQL/MariaDB){{ if .DB.SQLite }} or sqlite (SQLite3){{ end }}"`
|
||||||
DbName string `arg:"--db-name,env:DB_NAME" default:"dbname" help:"Database name for connect"`
|
DbName string `arg:"--db-name,env:DB_NAME" default:"dbname" help:"Database name for connect"`
|
||||||
|
{{ if .DB.SQLite }}
|
||||||
|
DbPath string `arg:"--db-path,env:DB_PATH" default:"./{{ .Name }}.db" help:"Path to database for SQLite3"`
|
||||||
|
{{ end }}
|
||||||
DbAddress string `arg:"--db-host,env:DB_HOST" default:"localhost" help:"Database host for connect"`
|
DbAddress string `arg:"--db-host,env:DB_HOST" default:"localhost" help:"Database host for connect"`
|
||||||
DbPort string `arg:"--db-port,env:DB_PORT" default:"5432" help:"Database port for connect"`
|
DbPort string `arg:"--db-port,env:DB_PORT" default:"5432" help:"Database port for connect"`
|
||||||
DbLogin string `arg:"--db-login,env:DB_LOGIN" default:"db" help:"Database login for connect"`
|
DbLogin string `arg:"--db-login,env:DB_LOGIN" default:"db" help:"Database login for connect"`
|
||||||
|
@ -17,7 +20,7 @@ var AppConfig struct {
|
||||||
LdapPassword string `arg:"--ldap-pwd,env:LDAP_PWD" help:"Ldap password for credential"`
|
LdapPassword string `arg:"--ldap-pwd,env:LDAP_PWD" help:"Ldap password for credential"`
|
||||||
LdapSearchBase string `arg:"--ldap-search-base,env:LDAP_SEARCH_BASE" help:"Ldap search base for search users"`
|
LdapSearchBase string `arg:"--ldap-search-base,env:LDAP_SEARCH_BASE" help:"Ldap search base for search users"`
|
||||||
|
|
||||||
{{ range $index, $field := .Config }}
|
{{ range $index, $field := .Backend.Config }}
|
||||||
{{ configParamName $field }} {{ configParamType $field }} {{ configParamTag $field }}
|
{{ configParamName $field }} {{ configParamType $field }} {{ configParamTag $field }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
}
|
}
|
|
@ -39,6 +39,11 @@ var e *echo.Echo
|
||||||
|
|
||||||
// @host {{ .Host }}
|
// @host {{ .Host }}
|
||||||
// @BasePath {{ .BasePath }}
|
// @BasePath {{ .BasePath }}
|
||||||
|
|
||||||
|
// @securityDefinitions.apikey BearerAuth
|
||||||
|
// @in header
|
||||||
|
// @name Authorization
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
arg.MustParse(&lib.AppConfig)
|
arg.MustParse(&lib.AppConfig)
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,18 @@ func Init(c *echo.Group) {
|
||||||
c.POST("/login", login)
|
c.POST("/login", login)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Authenticate auth
|
||||||
|
// @Summary Authenticate in system
|
||||||
|
// @Description Get authentication data
|
||||||
|
// @Tags users
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body model.User true "query params"
|
||||||
|
// @Success 200 {object} structs.Result
|
||||||
|
// @Failure 400 {object} structs.Result
|
||||||
|
// @Failure 404 {object} structs.Result
|
||||||
|
// @Failure 500 {object} structs.Result
|
||||||
|
// @Router /api/auth [post]
|
||||||
func login(c echo.Context) error {
|
func login(c echo.Context) error {
|
||||||
var err error
|
var err error
|
||||||
var userForm model.User
|
var userForm model.User
|
||||||
|
|
|
@ -13,6 +13,20 @@ import (
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DeleteUser deleteUser
|
||||||
|
// @Summary Удаление пользователя
|
||||||
|
// @Description Удаление информации о пользователе
|
||||||
|
// @Tags users
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path string true "Идентификатор пользователя"
|
||||||
|
// @Success 200 {object} structs.Result
|
||||||
|
// @Failure 400 {object} structs.Result
|
||||||
|
// @Failure 401 {object} structs.Result
|
||||||
|
// @Failure 404 {object} structs.Result
|
||||||
|
// @Failure 500 {object} structs.Result
|
||||||
|
// @Router /api/user/{id} [delete]
|
||||||
|
// @Security BearerAuth
|
||||||
func delete(c echo.Context) error {
|
func delete(c echo.Context) error {
|
||||||
|
|
||||||
user := c.Get("user").(*jwt.Token)
|
user := c.Get("user").(*jwt.Token)
|
||||||
|
|
|
@ -11,6 +11,20 @@ import (
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetUser getUser
|
||||||
|
// @Summary Получить пользователя
|
||||||
|
// @Description Получения информации о пользователе по его id
|
||||||
|
// @Tags users
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path string true "Идентификатор пользователя"
|
||||||
|
// @Success 200 {object} model.User
|
||||||
|
// @Failure 400 {object} structs.Result
|
||||||
|
// @Failure 401 {object} structs.Result
|
||||||
|
// @Failure 404 {object} structs.Result
|
||||||
|
// @Failure 500 {object} structs.Result
|
||||||
|
// @Router /api/user/{id} [get]
|
||||||
|
// @Security BearerAuth
|
||||||
func get(c echo.Context) error {
|
func get(c echo.Context) error {
|
||||||
|
|
||||||
id := uuid.FromStringOrNil(c.Param("id"))
|
id := uuid.FromStringOrNil(c.Param("id"))
|
||||||
|
|
|
@ -12,6 +12,19 @@ import (
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ListUsers listUsers
|
||||||
|
// @Summary Получить пользователя
|
||||||
|
// @Description Возвращает список пользователей
|
||||||
|
// @Tags users
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} []model.User
|
||||||
|
// @Failure 400 {object} structs.Result
|
||||||
|
// @Failure 401 {object} structs.Result
|
||||||
|
// @Failure 404 {object} structs.Result
|
||||||
|
// @Failure 500 {object} structs.Result
|
||||||
|
// @Router /api/user [get]
|
||||||
|
// @Security BearerAuth
|
||||||
func listUsers(c echo.Context) error {
|
func listUsers(c echo.Context) error {
|
||||||
|
|
||||||
user := c.Get("user").(*jwt.Token)
|
user := c.Get("user").(*jwt.Token)
|
||||||
|
|
|
@ -14,6 +14,20 @@ import (
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CreateUser createUser
|
||||||
|
// @Summary Создать пользователя
|
||||||
|
// @Description Добавление нового пользователя в систему
|
||||||
|
// @Tags users
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body model.User true "Описание нового пользователя"
|
||||||
|
// @Success 200 {object} model.User
|
||||||
|
// @Failure 400 {object} structs.Result
|
||||||
|
// @Failure 401 {object} structs.Result
|
||||||
|
// @Failure 404 {object} structs.Result
|
||||||
|
// @Failure 500 {object} structs.Result
|
||||||
|
// @Router /api/user [post]
|
||||||
|
// @Security BearerAuth
|
||||||
func post(c echo.Context) error {
|
func post(c echo.Context) error {
|
||||||
|
|
||||||
user := c.Get("user").(*jwt.Token)
|
user := c.Get("user").(*jwt.Token)
|
||||||
|
|
|
@ -15,6 +15,21 @@ import (
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// UpdateUser updateUser
|
||||||
|
// @Summary Обновление пользователя
|
||||||
|
// @Description Обновление информации о пользователе, а так же смена пароля при необходимости
|
||||||
|
// @Tags users
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param id path string true "Идентификатор пользователя"
|
||||||
|
// @Param body body model.User true "Описание существующего пользователя"
|
||||||
|
// @Success 200 {object} model.User
|
||||||
|
// @Failure 400 {object} structs.Result
|
||||||
|
// @Failure 401 {object} structs.Result
|
||||||
|
// @Failure 404 {object} structs.Result
|
||||||
|
// @Failure 500 {object} structs.Result
|
||||||
|
// @Router /api/user/{id} [post]
|
||||||
|
// @Security BearerAuth
|
||||||
func put(c echo.Context) error {
|
func put(c echo.Context) error {
|
||||||
|
|
||||||
user := c.Get("user").(*jwt.Token)
|
user := c.Get("user").(*jwt.Token)
|
||||||
|
|
|
@ -16,6 +16,19 @@ func Init(c *echo.Group) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListRoles listRoles
|
||||||
|
// @Summary Список ролей для пользователей в системе
|
||||||
|
// @Description Получить список пролей для отображения и назначения пользователям
|
||||||
|
// @Tags users
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} structs.Result
|
||||||
|
// @Failure 400 {object} structs.Result
|
||||||
|
// @Failure 401 {object} structs.Result
|
||||||
|
// @Failure 404 {object} structs.Result
|
||||||
|
// @Failure 500 {object} structs.Result
|
||||||
|
// @Router /api/user/roles [get]
|
||||||
|
// @Security BearerAuth
|
||||||
func listRoles(c echo.Context) error {
|
func listRoles(c echo.Context) error {
|
||||||
var err error
|
var err error
|
||||||
tx := db.BeginTransation()
|
tx := db.BeginTransation()
|
||||||
|
|
1
main.go
1
main.go
|
@ -42,6 +42,7 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
log.Fatal("Ошибка открытия файла")
|
log.Fatal("Ошибка открытия файла")
|
||||||
}
|
}
|
||||||
|
lib.PrepareMetadata(lib.Project)
|
||||||
|
|
||||||
lib.Generate()
|
lib.Generate()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package structs
|
||||||
import uuid "github.com/satori/go.uuid"
|
import uuid "github.com/satori/go.uuid"
|
||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
|
SQLite bool `yaml:"sqlite,omitempty"`
|
||||||
Tables []Table `yaml:"tables,omitempty"`
|
Tables []Table `yaml:"tables,omitempty"`
|
||||||
Description string `yaml:"description,omitempty" json:"nescription,omitempty"`
|
Description string `yaml:"description,omitempty" json:"nescription,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -18,6 +19,7 @@ type Table struct {
|
||||||
Recursive bool `yaml:"recursive,omitempty" json:"recursive,omitempty"` // Рекурсивная таблица
|
Recursive bool `yaml:"recursive,omitempty" json:"recursive,omitempty"` // Рекурсивная таблица
|
||||||
FKs []FK `yaml:"fks,omitempty" json:"fks,omitempty"` // Внешние ключи
|
FKs []FK `yaml:"fks,omitempty" json:"fks,omitempty"` // Внешние ключи
|
||||||
FkFields []Field `yaml:"-" json:"-"` // Поля с описанием внешних ключей
|
FkFields []Field `yaml:"-" json:"-"` // Поля с описанием внешних ключей
|
||||||
|
Children []string `yaml:"-" json:"-"` // Дочерние (подчиненные) таблицы
|
||||||
}
|
}
|
||||||
|
|
||||||
// Описание поля
|
// Описание поля
|
||||||
|
@ -34,6 +36,7 @@ type Field struct {
|
||||||
type FK struct {
|
type FK struct {
|
||||||
ID uuid.UUID `yaml:"id,omitempty" json:"id,omitempty"` // Идентификатор внешнего ключа
|
ID uuid.UUID `yaml:"id,omitempty" json:"id,omitempty"` // Идентификатор внешнего ключа
|
||||||
Name string `yaml:"name,omitempty" json:"name,omitempty"` // Название ключа
|
Name string `yaml:"name,omitempty" json:"name,omitempty"` // Название ключа
|
||||||
|
Type string `yaml:"-"` // Тип первичного ключа
|
||||||
TableID uuid.UUID `yaml:"idTable,omitempty" json:"idTable,omitempty"` // Идентификатор таблицы, на которую ссылаемся
|
TableID uuid.UUID `yaml:"idTable,omitempty" json:"idTable,omitempty"` // Идентификатор таблицы, на которую ссылаемся
|
||||||
TableName string `yaml:"tableName,omitempty" json:"tableName,omitempty"` // Название таблицы, на которую ссылаемся
|
TableName string `yaml:"tableName,omitempty" json:"tableName,omitempty"` // Название таблицы, на которую ссылаемся
|
||||||
Description string `yaml:"description,omitempty" json:"description,omitempty"` // Описание внешнего ключа
|
Description string `yaml:"description,omitempty" json:"description,omitempty"` // Описание внешнего ключа
|
||||||
|
|
Loading…
Reference in New Issue
Block a user