完成重构数据库操作代码

This commit is contained in:
dushixiang
2021-03-19 20:22:04 +08:00
parent 8380d7d857
commit db6936321a
37 changed files with 294 additions and 329 deletions

View File

@ -11,7 +11,7 @@ import (
)
func PropertyGetEndpoint(c echo.Context) error {
properties := model.FindAllPropertiesMap()
properties := propertyRepository.FindAllMap()
return Success(c, properties)
}
@ -32,13 +32,15 @@ func PropertyUpdateEndpoint(c echo.Context) error {
Value: value,
}
_, err := model.FindPropertyByName(key)
_, err := propertyRepository.FindByName(key)
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
if err := model.CreateNewProperty(&property); err != nil {
if err := propertyRepository.Create(&property); err != nil {
return err
}
} else {
model.UpdatePropertyByName(&property, key)
if err := propertyRepository.UpdateByName(&property, key); err != nil {
return err
}
}
}
return Success(c, nil)