Adds insertplan to model
This commit is contained in:
parent
b6a6c9375f
commit
9c56ea56e2
@ -6,6 +6,7 @@ type Store interface {
|
||||
SelectActionByID(id int) (*Action, error)
|
||||
SelectPlans() ([]*Plan, error)
|
||||
SelectPlanByID(id int) (*Plan, error)
|
||||
InsertPlan(plan *Plan) (int, error)
|
||||
}
|
||||
|
||||
// Model represents a current model item.
|
||||
|
@ -27,6 +27,10 @@ func (ms *multiStore) SelectPlanByID(id int) (*models.Plan, error) {
|
||||
return ms.plans[0], nil
|
||||
}
|
||||
|
||||
func (ms *multiStore) InsertPlan(plan *models.Plan) (int, error) {
|
||||
return int(plan.PlanID), nil
|
||||
}
|
||||
|
||||
func TestModelActions(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
a1 := &models.Action{ActionID: 3}
|
||||
@ -53,3 +57,18 @@ func TestModelActions(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
assert.EqualValues(6, firstPlan.PlanID)
|
||||
}
|
||||
|
||||
func TestModelInsertPlan(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
p := &models.Plan{PlanID: 7}
|
||||
|
||||
ss := &multiStore{
|
||||
[]*models.Action{},
|
||||
[]*models.Plan{p},
|
||||
}
|
||||
m := models.New(ss)
|
||||
|
||||
planId, err := m.AddPlan(p)
|
||||
assert.Nil(err)
|
||||
assert.EqualValues(7, planId)
|
||||
}
|
||||
|
@ -19,3 +19,8 @@ func (m *Model) Plans() ([]*Plan, error) {
|
||||
func (m *Model) Plan(id int) (*Plan, error) {
|
||||
return m.SelectPlanByID(id)
|
||||
}
|
||||
|
||||
// AddPlan inserts a given plan into the store, returning the generated PlanID. The provided PlanID is ignored.
|
||||
func (m *Model) AddPlan(plan *Plan) (int, error) {
|
||||
return m.InsertPlan(plan)
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"fmt"
|
||||
"gitea.deepak.science/deepak/gogmagog/models"
|
||||
"gitea.deepak.science/deepak/gogmagog/util"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type postgresStore struct {
|
||||
@ -53,3 +53,7 @@ func (store *postgresStore) SelectPlanByID(id int) (*models.Plan, error) {
|
||||
}
|
||||
return &plan, nil
|
||||
}
|
||||
|
||||
func (store *postgresStore) InsertPlan(plan *models.Plan) (int, error) {
|
||||
return 0, fmt.Errorf("Unimplemented method")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user