forked from GDGVIT/vitty-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
774383e
commit ac51148
Showing
5 changed files
with
163 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/GDGVIT/vitty-backend/vitty-backend-api/internal/database" | ||
) | ||
|
||
func findEmptyClassRooms(slot string) ([]string, error) { | ||
var freeClasses []string | ||
total := 0 | ||
offset := 0 | ||
limit := 1000 | ||
|
||
query := database.DB. | ||
Table("joindata"). | ||
Where("NOT (slots @> '[\"?\"]')", database.DB.Raw(slot)). | ||
Where("slots::text !~ '\\[\"L.*\"\\]'") | ||
|
||
err := query. | ||
Select("COUNT(class)"). | ||
Scan(&total).Error | ||
|
||
if err != nil { | ||
return freeClasses, err | ||
} | ||
|
||
for total >= 0 { | ||
err := query. | ||
Select("class"). | ||
Limit(limit). | ||
Offset(offset). | ||
Find(&freeClasses).Error | ||
|
||
if err != nil { | ||
return freeClasses, err | ||
} | ||
|
||
total -= limit | ||
offset += limit | ||
} | ||
|
||
return freeClasses, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters