Skip to content

Commit

Permalink
feat: change config key name (#759)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Oct 27, 2021
1 parent e296e12 commit 433aaf1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manager/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package model

type Config struct {
Model
Key string `gorm:"column:key;type:varchar(256);index:uk_config_key,unique;not null;comment:config key" json:"key"`
Name string `gorm:"column:name;type:varchar(256);index:uk_config_name,unique;not null;comment:config name" json:"name"`
Value string `gorm:"column:value;type:varchar(1024);not null;comment:config value" json:"value"`
BIO string `gorm:"column:bio;type:varchar(1024);comment:biography" json:"bio"`
UserID uint `gorm:"comment:user id" json:"user_id"`
Expand Down
8 changes: 4 additions & 4 deletions manager/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func (s *rest) CreateConfig(ctx context.Context, json types.CreateConfigRequest) (*model.Config, error) {
config := model.Config{
Key: json.Key,
Name: json.Name,
Value: json.Value,
BIO: json.BIO,
UserID: json.UserID,
Expand Down Expand Up @@ -54,7 +54,7 @@ func (s *rest) DestroyConfig(ctx context.Context, id uint) error {
func (s *rest) UpdateConfig(ctx context.Context, id uint, json types.UpdateConfigRequest) (*model.Config, error) {
config := model.Config{}
if err := s.db.WithContext(ctx).First(&config, id).Updates(model.Config{
Key: json.Key,
Name: json.Name,
Value: json.Value,
BIO: json.BIO,
UserID: json.UserID,
Expand All @@ -77,7 +77,7 @@ func (s *rest) GetConfig(ctx context.Context, id uint) (*model.Config, error) {
func (s *rest) GetConfigs(ctx context.Context, q types.GetConfigsQuery) (*[]model.Config, error) {
configs := []model.Config{}
if err := s.db.WithContext(ctx).Scopes(model.Paginate(q.Page, q.PerPage)).Where(&model.Config{
Key: q.Key,
Name: q.Name,
Value: q.Value,
UserID: q.UserID,
}).Find(&configs).Error; err != nil {
Expand All @@ -90,7 +90,7 @@ func (s *rest) GetConfigs(ctx context.Context, q types.GetConfigsQuery) (*[]mode
func (s *rest) ConfigTotalCount(ctx context.Context, q types.GetConfigsQuery) (int64, error) {
var count int64
if err := s.db.WithContext(ctx).Model(&model.Config{}).Where(&model.Config{
Key: q.Key,
Name: q.Name,
Value: q.Value,
UserID: q.UserID,
}).Count(&count).Error; err != nil {
Expand Down
6 changes: 3 additions & 3 deletions manager/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ type ConfigParams struct {
}

type CreateConfigRequest struct {
Key string `json:"key" binding:"required"`
Name string `json:"name" binding:"required"`
Value string `json:"value" binding:"required"`
BIO string `json:"bio" binding:"omitempty"`
UserID uint `json:"user_id" binding:"required"`
}

type UpdateConfigRequest struct {
Key string `json:"key" binding:"omitempty"`
Name string `json:"name" binding:"omitempty"`
Value string `json:"value" binding:"omitempty"`
BIO string `json:"bio" binding:"omitempty"`
UserID uint `json:"user_id" binding:"omitempty"`
}

type GetConfigsQuery struct {
Key string `form:"key" binding:"omitempty"`
Name string `form:"name" binding:"omitempty"`
Value string `form:"value" binding:"omitempty"`
UserID uint `form:"user_id" binding:"omitempty"`
Page int `form:"page" binding:"omitempty,gte=1"`
Expand Down

0 comments on commit 433aaf1

Please sign in to comment.