Minor changes to fix group methods after refactor.

This commit is contained in:
Ada Werefox 2025-05-13 23:40:28 -05:00
parent c273d061b5
commit 728bbd038a
2 changed files with 8 additions and 24 deletions

View file

@ -26,16 +26,14 @@ func main() {
router.GET("/auth/callback", api.AuthCallback)
router.GET("/auth/login", api.AuthLoginRedirect)
router.GET("/auth/logout", api.AuthLogoutRedirect)
// User methods
router.GET("/user/token/generate", api.CreateAPIToken)
router.GET("/user/info", api.GetDiscordUser)
router.GET("/user/authorized", api.GetUserLoggedIn)
// Create
// Object Requests
router.POST("/:object", api.ObjectRequest)
// Update
router.PUT("/:object", api.ObjectRequest)
// Read
router.GET("/:object", api.ObjectRequest)
// Delete
router.DELETE("/:object", api.ObjectRequest)
router.Run(":31337")
}

View file

@ -56,7 +56,7 @@ func (group Group) update(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 {
return result.Error
}
@ -71,18 +71,9 @@ func (group Group) create(db *gorm.DB) error {
return nil
}
func Create(db *gorm.DB, context *gin.Context) 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
}
func Create(db *gorm.DB, params groupParams) error {
return Group{
Name: newGroup.Name,
Name: params.Name,
}.create(db)
}
@ -99,12 +90,7 @@ func Get(db *gorm.DB, inputGroups []uint) *[]Group {
return &outputGroups
}
func Update(db *gorm.DB, context *gin.Context) error {
var params groupParams
err := params.validate(context)
if err != nil {
return err
}
func Update(db *gorm.DB, params groupParams) error {
uintID, err := strconv.Atoi(params.ID)
if err != nil {
return err
@ -159,9 +145,9 @@ func HandleRequest(db *gorm.DB, context *gin.Context) error {
"result": result,
})
case "POST":
err = Create(db, context)
err = Create(db, params)
case "PUT":
err = Update(db, context)
err = Update(db, params)
case "DELETE":
err = Delete(db, idUintArray)
}