rename store functions to match go standards

pull/3149/head
Eoin McAfee 2021-09-30 15:01:01 +01:00
parent 3f8fae7d13
commit 8815afed32
12 changed files with 29 additions and 32 deletions

View File

@ -42,11 +42,11 @@ type CardData struct {
// CardStore manages repository cards.
type CardStore interface {
FindCardByBuild(ctx context.Context, build int64) ([]*Card, error)
FindCard(ctx context.Context, step int64) (*Card, error)
FindCardData(ctx context.Context, id int64) (io.ReadCloser, error)
CreateCard(ctx context.Context, card *Card, data io.ReadCloser) error
DeleteCard(ctx context.Context, id int64) error
FindByBuild(ctx context.Context, build int64) ([]*Card, error)
Find(ctx context.Context, step int64) (*Card, error)
FindData(ctx context.Context, id int64) (io.ReadCloser, error)
Create(ctx context.Context, card *Card, data io.ReadCloser) error
Delete(ctx context.Context, id int64) error
}
// Validate validates the required fields and formats.

View File

@ -102,7 +102,7 @@ func HandleCreate(
bytes.NewBuffer([]byte(in.Data)),
)
err = cardStore.CreateCard(r.Context(), c, data)
err = cardStore.Create(r.Context(), c, data)
if err != nil {
render.InternalError(w, err)
return

View File

@ -53,9 +53,6 @@ var (
Step: 1,
Schema: "https://myschema.com",
}
dummyCardNoData = &core.Card{
Schema: "https://myschema.com",
}
dummyCardList = []*core.Card{
dummyCard,
}

View File

@ -71,12 +71,12 @@ func HandleDelete(
return
}
card, err := cardStore.FindCard(r.Context(), step.ID)
card, err := cardStore.Find(r.Context(), step.ID)
if err != nil {
render.NotFound(w, err)
return
}
err = cardStore.DeleteCard(r.Context(), card.Id)
err = cardStore.Delete(r.Context(), card.Id)
if err != nil {
render.InternalError(w, err)
return

View File

@ -69,7 +69,7 @@ func HandleFind(
return
}
card, err := cardStore.FindCard(r.Context(), step.ID)
card, err := cardStore.Find(r.Context(), step.ID)
if err != nil {
render.NotFound(w, err)
return

View File

@ -45,7 +45,7 @@ func HandleFindAll(
return
}
list, err := cardStore.FindCardByBuild(r.Context(), build.ID)
list, err := cardStore.FindByBuild(r.Context(), build.ID)
if err != nil {
render.NotFound(w, err)
return

View File

@ -70,12 +70,12 @@ func HandleFindData(
return
}
card, err := cardStore.FindCard(r.Context(), step.ID)
card, err := cardStore.Find(r.Context(), step.ID)
if err != nil {
render.NotFound(w, err)
return
}
cardData, err := cardStore.FindCardData(r.Context(), card.Id)
cardData, err := cardStore.FindData(r.Context(), card.Id)
if err != nil {
render.NotFound(w, err)
return

View File

@ -26,7 +26,7 @@ type cardStore struct {
db *db.DB
}
func (c *cardStore) FindCardByBuild(ctx context.Context, build int64) ([]*core.Card, error) {
func (c *cardStore) FindByBuild(ctx context.Context, build int64) ([]*core.Card, error) {
var out []*core.Card
err := c.db.View(func(queryer db.Queryer, binder db.Binder) error {
params := map[string]interface{}{
@ -46,7 +46,7 @@ func (c *cardStore) FindCardByBuild(ctx context.Context, build int64) ([]*core.C
return out, err
}
func (c cardStore) FindCard(ctx context.Context, step int64) (*core.Card, error) {
func (c cardStore) Find(ctx context.Context, step int64) (*core.Card, error) {
out := &core.Card{Step: step}
err := c.db.View(func(queryer db.Queryer, binder db.Binder) error {
params, err := toParams(out)
@ -63,7 +63,7 @@ func (c cardStore) FindCard(ctx context.Context, step int64) (*core.Card, error)
return out, err
}
func (c cardStore) FindCardData(ctx context.Context, id int64) (io.ReadCloser, error) {
func (c cardStore) FindData(ctx context.Context, id int64) (io.ReadCloser, error) {
out := &core.CardData{}
err := c.db.View(func(queryer db.Queryer, binder db.Binder) error {
params := map[string]interface{}{
@ -81,7 +81,7 @@ func (c cardStore) FindCardData(ctx context.Context, id int64) (io.ReadCloser, e
), err
}
func (c cardStore) CreateCard(ctx context.Context, card *core.Card, data io.ReadCloser) error {
func (c cardStore) Create(ctx context.Context, card *core.Card, data io.ReadCloser) error {
if c.db.Driver() == db.Postgres {
return c.createPostgres(ctx, card, data)
}
@ -129,7 +129,7 @@ func (c *cardStore) createPostgres(ctx context.Context, card *core.Card, data io
})
}
func (c cardStore) DeleteCard(ctx context.Context, id int64) error {
func (c cardStore) Delete(ctx context.Context, id int64) error {
return c.db.Lock(func(execer db.Execer, binder db.Binder) error {
params := map[string]interface{}{
"card_id": id,

View File

@ -57,7 +57,7 @@ func testCardCreate(store *cardStore) func(t *testing.T) {
buf := ioutil.NopCloser(
bytes.NewBuffer([]byte("{\"type\": \"AdaptiveCard\"}")),
)
err := store.CreateCard(noContext, item, buf)
err := store.Create(noContext, item, buf)
if err != nil {
t.Error(err)
}
@ -66,15 +66,15 @@ func testCardCreate(store *cardStore) func(t *testing.T) {
}
t.Run("FindByBuild", testFindCardByBuild(store))
t.Run("FindCard", testFindCard(store))
t.Run("FindCardData", testFindCardData(store))
t.Run("Find", testFindCard(store))
t.Run("FindData", testFindCardData(store))
t.Run("Delete", testCardDelete(store))
}
}
func testFindCardByBuild(card *cardStore) func(t *testing.T) {
return func(t *testing.T) {
item, err := card.FindCardByBuild(noContext, 1)
item, err := card.FindByBuild(noContext, 1)
if err != nil {
t.Error(err)
} else {
@ -85,7 +85,7 @@ func testFindCardByBuild(card *cardStore) func(t *testing.T) {
func testFindCard(card *cardStore) func(t *testing.T) {
return func(t *testing.T) {
item, err := card.FindCard(noContext, 3)
item, err := card.Find(noContext, 3)
if err != nil {
t.Error(err)
} else {
@ -96,7 +96,7 @@ func testFindCard(card *cardStore) func(t *testing.T) {
func testFindCardData(card *cardStore) func(t *testing.T) {
return func(t *testing.T) {
r, err := card.FindCardData(noContext, 1)
r, err := card.FindData(noContext, 1)
if err != nil {
t.Error(err)
} else {
@ -114,17 +114,17 @@ func testFindCardData(card *cardStore) func(t *testing.T) {
func testCardDelete(store *cardStore) func(t *testing.T) {
return func(t *testing.T) {
card, err := store.FindCard(noContext, 3)
card, err := store.Find(noContext, 3)
if err != nil {
t.Error(err)
return
}
err = store.DeleteCard(noContext, card.Id)
err = store.Delete(noContext, card.Id)
if err != nil {
t.Error(err)
return
}
_, err = store.FindCard(noContext, card.Step)
_, err = store.Find(noContext, card.Step)
if got, want := sql.ErrNoRows, err; got != want {
t.Errorf("Want sql.ErrNoRows, got %v", got)
return

View File

@ -13,4 +13,4 @@ CREATE TABLE IF NOT EXISTS cards (
CREATE INDEX ix_cards_build ON cards (card_build);
-- name: create-index-cards-card_step
CREATE INDEX ix_cards_step ON cards (card_step);
CREATE UNIQUE INDEX ix_cards_step ON cards (card_step);

View File

@ -13,4 +13,4 @@ CREATE TABLE IF NOT EXISTS cards (
CREATE INDEX IF NOT EXISTS ix_cards_build ON cards (card_build);
-- name: create-index-cards-card_step
CREATE INDEX IF NOT EXISTS ix_cards_step ON cards (card_step);
CREATE UNIQUE INDEX IF NOT EXISTS ix_cards_step ON cards (card_step);

View File

@ -13,4 +13,4 @@ CREATE TABLE IF NOT EXISTS cards (
CREATE INDEX IF NOT EXISTS ix_cards_build ON cards (card_build);
-- name: create-index-cards-card_step
CREATE INDEX IF NOT EXISTS ix_cards_step ON cards (card_step);
CREATE UNIQUE INDEX IF NOT EXISTS ix_cards_step ON cards (card_step);