mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 10:35:30 +00:00
Basic new
This commit is contained in:
54
controllers/musenalm_id.go
Normal file
54
controllers/musenalm_id.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func nextEntryMusenalmID(app core.App) (int, error) {
|
||||
var entry dbmodels.Entry
|
||||
err := app.RecordQuery(dbmodels.ENTRIES_TABLE).
|
||||
OrderBy(dbmodels.MUSENALMID_FIELD + " DESC").
|
||||
Limit(1).
|
||||
One(&entry)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 1, nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return entry.MusenalmID() + 1, nil
|
||||
}
|
||||
|
||||
func nextSeriesMusenalmID(app core.App) (int, error) {
|
||||
var series dbmodels.Series
|
||||
err := app.RecordQuery(dbmodels.SERIES_TABLE).
|
||||
OrderBy(dbmodels.MUSENALMID_FIELD + " DESC").
|
||||
Limit(1).
|
||||
One(&series)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 1, nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return series.MusenalmID() + 1, nil
|
||||
}
|
||||
|
||||
func nextAgentMusenalmID(app core.App) (int, error) {
|
||||
var agent dbmodels.Agent
|
||||
err := app.RecordQuery(dbmodels.AGENTS_TABLE).
|
||||
OrderBy(dbmodels.MUSENALMID_FIELD + " DESC").
|
||||
Limit(1).
|
||||
One(&agent)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 1, nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return agent.MusenalmID() + 1, nil
|
||||
}
|
||||
Reference in New Issue
Block a user