snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s
Some checks failed
build / build (push) Failing after 3s
This commit is contained in:
23
timespan/remove.go
Normal file
23
timespan/remove.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package timespan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/traggo/server/auth"
|
||||
"github.com/traggo/server/generated/gqlmodel"
|
||||
"github.com/traggo/server/model"
|
||||
)
|
||||
|
||||
// RemoveTimeSpan removes a timespan.
|
||||
func (r *ResolverForTimeSpan) RemoveTimeSpan(ctx context.Context, id int) (*gqlmodel.TimeSpan, error) {
|
||||
timeSpan := model.TimeSpan{ID: id}
|
||||
if r.DB.Preload("Tags").Where("user_id = ?", auth.GetUser(ctx).ID).Find(&timeSpan).RecordNotFound() {
|
||||
return nil, fmt.Errorf("timespan with id %d does not exist", timeSpan.ID)
|
||||
}
|
||||
|
||||
remove := r.DB.Where(&model.TimeSpan{ID: id}).Delete(new(model.TimeSpan))
|
||||
|
||||
external := timeSpanToExternal(timeSpan)
|
||||
return external, remove.Error
|
||||
}
|
||||
Reference in New Issue
Block a user