-
Notifications
You must be signed in to change notification settings - Fork 15
/
list.go
42 lines (37 loc) · 1.03 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package schedule
import (
"context"
"github.com/cockroachdb/errors"
"github.com/data-preservation-programs/singularity/model"
"gorm.io/gorm"
)
// @ID ListSchedules
// @Summary List all deal making schedules
// @Tags Deal Schedule
// @Produce json
// @Success 200 {array} model.Schedule
// @Failure 400 {object} api.HTTPError
// @Failure 500 {object} api.HTTPError
// @Router /schedule [get]
func _() {}
// ListHandler retrieves all the schedules from the database.
//
// Parameters:
// - ctx: The context for the operation, which can include cancellation signals, timeout details, etc.
// - db: The database connection used for CRUD operations.
//
// Returns:
// - A slice of Schedule models if successful.
// - An error if there are issues during the operation.
func (DefaultHandler) ListHandler(
ctx context.Context,
db *gorm.DB,
) ([]model.Schedule, error) {
db = db.WithContext(ctx)
var schedules []model.Schedule
err := db.Find(&schedules).Error
if err != nil {
return nil, errors.WithStack(err)
}
return schedules, nil
}