Minor changes to fix group methods after refactor.
This commit is contained in:
parent
c273d061b5
commit
728bbd038a
2 changed files with 8 additions and 24 deletions
|
@ -26,16 +26,14 @@ func main() {
|
||||||
router.GET("/auth/callback", api.AuthCallback)
|
router.GET("/auth/callback", api.AuthCallback)
|
||||||
router.GET("/auth/login", api.AuthLoginRedirect)
|
router.GET("/auth/login", api.AuthLoginRedirect)
|
||||||
router.GET("/auth/logout", api.AuthLogoutRedirect)
|
router.GET("/auth/logout", api.AuthLogoutRedirect)
|
||||||
|
// User methods
|
||||||
router.GET("/user/token/generate", api.CreateAPIToken)
|
router.GET("/user/token/generate", api.CreateAPIToken)
|
||||||
router.GET("/user/info", api.GetDiscordUser)
|
router.GET("/user/info", api.GetDiscordUser)
|
||||||
router.GET("/user/authorized", api.GetUserLoggedIn)
|
router.GET("/user/authorized", api.GetUserLoggedIn)
|
||||||
// Create
|
// Object Requests
|
||||||
router.POST("/:object", api.ObjectRequest)
|
router.POST("/:object", api.ObjectRequest)
|
||||||
// Update
|
|
||||||
router.PUT("/:object", api.ObjectRequest)
|
router.PUT("/:object", api.ObjectRequest)
|
||||||
// Read
|
|
||||||
router.GET("/:object", api.ObjectRequest)
|
router.GET("/:object", api.ObjectRequest)
|
||||||
// Delete
|
|
||||||
router.DELETE("/:object", api.ObjectRequest)
|
router.DELETE("/:object", api.ObjectRequest)
|
||||||
router.Run(":31337")
|
router.Run(":31337")
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (group Group) update(db *gorm.DB) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (group Group) delete(db *gorm.DB) error {
|
func (group Group) delete(db *gorm.DB) error {
|
||||||
result := db.Delete(&group)
|
result := db.Unscoped().Delete(&group)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
|
@ -71,18 +71,9 @@ func (group Group) create(db *gorm.DB) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Create(db *gorm.DB, context *gin.Context) error {
|
func Create(db *gorm.DB, params groupParams) error {
|
||||||
body, err := io.ReadAll(context.Request.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var newGroup Group
|
|
||||||
err = json.Unmarshal(body, &newGroup)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return Group{
|
return Group{
|
||||||
Name: newGroup.Name,
|
Name: params.Name,
|
||||||
}.create(db)
|
}.create(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,12 +90,7 @@ func Get(db *gorm.DB, inputGroups []uint) *[]Group {
|
||||||
return &outputGroups
|
return &outputGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(db *gorm.DB, context *gin.Context) error {
|
func Update(db *gorm.DB, params groupParams) error {
|
||||||
var params groupParams
|
|
||||||
err := params.validate(context)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
uintID, err := strconv.Atoi(params.ID)
|
uintID, err := strconv.Atoi(params.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -159,9 +145,9 @@ func HandleRequest(db *gorm.DB, context *gin.Context) error {
|
||||||
"result": result,
|
"result": result,
|
||||||
})
|
})
|
||||||
case "POST":
|
case "POST":
|
||||||
err = Create(db, context)
|
err = Create(db, params)
|
||||||
case "PUT":
|
case "PUT":
|
||||||
err = Update(db, context)
|
err = Update(db, params)
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
err = Delete(db, idUintArray)
|
err = Delete(db, idUintArray)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue