package Database import ( "errors" "git.tovijaeschke.xyz/tovi/SuddenImpactRecords/Models" "gorm.io/gorm" ) func GetUsers(page, pageSize int) ([]Models.User, error) { var ( users []Models.User err error ) if page == 0 { page = 1 } switch { case pageSize > 100: pageSize = 100 case pageSize <= 0: pageSize = 10 } err = DB.Offset(page). Limit(pageSize). Find(&users). Error return users, err } func CheckUniqueEmail(email string) error { var ( exists bool err error ) err = DB.Model(Models.User{}). Select("count(*) > 0"). Where("email = ?", email). Find(&exists). Error if err != nil { return err } if exists { return errors.New("Invalid email") } return nil } func CreateUser(userData *Models.User) error { return DB.Session(&gorm.Session{FullSaveAssociations: true}). Create(userData). Error }