Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #21 from nicjohnson145/feat/under-development-desi…
Browse files Browse the repository at this point in the history
…gnation

Feat/under development designation
  • Loading branch information
nicjohnson145 authored Jul 24, 2022
2 parents 0284679 + 8c3b812 commit c25fa0f
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 48 deletions.
2 changes: 1 addition & 1 deletion cmd/mixer-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/nicjohnson145/mixer-service/pkg/drink"
"github.com/nicjohnson145/mixer-service/pkg/health"
"github.com/nicjohnson145/mixer-service/pkg/settings"
"github.com/nicjohnson145/mixer-service/pkg/user"
"github.com/nicjohnson145/mixer-service/pkg/slow"
"github.com/nicjohnson145/mixer-service/pkg/user"
log "github.com/sirupsen/logrus"
)

Expand Down
22 changes: 11 additions & 11 deletions cmd/register/main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package main

import (
"context"
"flag"
"os"
"github.com/carlmjohnson/requests"
log "github.com/sirupsen/logrus"
"github.com/nicjohnson145/mixer-service/pkg/auth"
"github.com/nicjohnson145/mixer-service/pkg/common"
"github.com/nicjohnson145/mixer-service/pkg/jwt"
"context"
log "github.com/sirupsen/logrus"
"os"
)

var (
username string
newUser string
username string
newUser string
newPassword string
host string
host string
)

func init() {
Expand Down Expand Up @@ -63,11 +63,11 @@ func main() {
}

err = requests.
URL(host + common.AuthV1 + "/register-user").
Header(jwt.AuthenticationHeader, loginResp.AccessToken).
BodyJSON(&registerRequest).
Fetch(context.Background())
URL(host+common.AuthV1+"/register-user").
Header(jwt.AuthenticationHeader, loginResp.AccessToken).
BodyJSON(&registerRequest).
Fetch(context.Background())

if err != nil {
log.Fatalf("Error registering user: %v", err)
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/db/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ func createMigrations() *migrate.MemoryMigrationSource {
`},
Down: []string{"DROP TABLE user_setting;"},
},
{
Id: nextId(),
Up: []string{`
ALTER TABLE
drink
ADD COLUMN
under_development
INTEGER
NOT NULL
DEFAULT
FALSE
;
`},
Down: []string{`
ALTER TABLE
drink
DROP COLUMN
under_development
;
`},
},
//{
// Id: nextId(),
// Up: []string{},
Expand Down
45 changes: 29 additions & 16 deletions pkg/drink/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ func fromDb(d Model) (Drink, error) {
return Drink{}, err
}

underDevelopment := false
if d.UnderDevelopment == 1 {
underDevelopment = true
}

return Drink{
ID: d.ID,
Username: d.Username,
DrinkData: DrinkData{
Name: d.Name,
PrimaryAlcohol: d.PrimaryAlcohol,
PreferredGlass: d.PreferredGlass,
Ingredients: ingredients,
Instructions: d.Instructions,
Notes: d.Notes,
Publicity: d.Publicity,
Name: d.Name,
PrimaryAlcohol: d.PrimaryAlcohol,
PreferredGlass: d.PreferredGlass,
Ingredients: ingredients,
Instructions: d.Instructions,
Notes: d.Notes,
Publicity: d.Publicity,
UnderDevelopment: underDevelopment,
},
}, nil
}
Expand All @@ -33,16 +39,22 @@ func toDb(d Drink) (Model, error) {
return Model{}, err
}

underDevelopment := 0
if d.UnderDevelopment {
underDevelopment = 1
}

return Model{
ID: d.ID,
Name: d.Name,
Username: d.Username,
PrimaryAlcohol: d.PrimaryAlcohol,
PreferredGlass: d.PreferredGlass,
Ingredients: ingredients,
Instructions: d.Instructions,
Notes: d.Notes,
Publicity: d.Publicity,
ID: d.ID,
Name: d.Name,
Username: d.Username,
PrimaryAlcohol: d.PrimaryAlcohol,
PreferredGlass: d.PreferredGlass,
Ingredients: ingredients,
Instructions: d.Instructions,
Notes: d.Notes,
Publicity: d.Publicity,
UnderDevelopment: underDevelopment,
}, nil
}

Expand Down Expand Up @@ -70,4 +82,5 @@ func setDrinkDataAttributes(obj DrinkDataSetter, data DrinkDataGetter) {
obj.SetInstructions(data.GetInstructions())
obj.SetNotes(data.GetNotes())
obj.SetPublicity(data.GetPublicity())
obj.SetUnderDevelopment(data.GetUnderDevelopment())
}
19 changes: 10 additions & 9 deletions pkg/drink/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ const (
)

type Model struct {
ID int64 `db:"id"`
Name string `db:"name" fieldtag:"required_insert"`
Username string `db:"username" fieldtag:"required_insert"`
PrimaryAlcohol string `db:"primary_alcohol" fieldtag:"required_insert"`
PreferredGlass string `db:"preferred_glass" fieldtag:"required_insert"`
Ingredients string `db:"ingredients" fieldtag:"required_insert"`
Instructions string `db:"instructions" fieldtag:"required_insert"`
Notes string `db:"notes" fieldtag:"required_insert"`
Publicity string `db:"publicity" fieldtag:"required_insert"`
ID int64 `db:"id"`
Name string `db:"name" fieldtag:"required_insert"`
Username string `db:"username" fieldtag:"required_insert"`
PrimaryAlcohol string `db:"primary_alcohol" fieldtag:"required_insert"`
PreferredGlass string `db:"preferred_glass" fieldtag:"required_insert"`
Ingredients string `db:"ingredients" fieldtag:"required_insert"`
Instructions string `db:"instructions" fieldtag:"required_insert"`
Notes string `db:"notes" fieldtag:"required_insert"`
Publicity string `db:"publicity" fieldtag:"required_insert"`
UnderDevelopment int `db:"under_development" fieldtag:"required_insert"`
}

func getByID(id int64, db *sql.DB) (*Model, error) {
Expand Down
25 changes: 18 additions & 7 deletions pkg/drink/drink_data.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package drink

type DrinkData struct {
Name string `json:"name" validate:"required"`
PrimaryAlcohol string `json:"primary_alcohol" validate:"required"`
PreferredGlass string `json:"preferred_glass,omitempty"`
Ingredients []string `json:"ingredients" validate:"required"`
Instructions string `json:"instructions,omitempty"`
Notes string `json:"notes,omitempty"`
Publicity string `json:"publicity" validate:"required"`
Name string `json:"name" validate:"required"`
PrimaryAlcohol string `json:"primary_alcohol" validate:"required"`
PreferredGlass string `json:"preferred_glass,omitempty"`
Ingredients []string `json:"ingredients" validate:"required"`
Instructions string `json:"instructions,omitempty"`
Notes string `json:"notes,omitempty"`
Publicity string `json:"publicity" validate:"required"`
UnderDevelopment bool `json:"under_development"`
}

func (d *DrinkData) SetName(v string) {
Expand Down Expand Up @@ -66,6 +67,14 @@ func (d DrinkData) GetPublicity() string {
return d.Publicity
}

func (d *DrinkData) SetUnderDevelopment(v bool) {
d.UnderDevelopment = v
}

func (d DrinkData) GetUnderDevelopment() bool {
return d.UnderDevelopment
}

type DrinkDataOperator interface {
DrinkDataSetter
DrinkDataGetter
Expand All @@ -79,6 +88,7 @@ type DrinkDataSetter interface {
SetInstructions(string)
SetNotes(string)
SetPublicity(string)
SetUnderDevelopment(bool)
}

type DrinkDataGetter interface {
Expand All @@ -89,4 +99,5 @@ type DrinkDataGetter interface {
GetInstructions() string
GetNotes() string
GetPublicity() string
GetUnderDevelopment() bool
}
6 changes: 4 additions & 2 deletions pkg/drink/drink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ func TestFullCRUDLoop(t *testing.T) {
"0.5 oz simple syrup",
"1 oz lime",
},
Publicity: DrinkPublicityPrivate,
Publicity: DrinkPublicityPrivate,
UnderDevelopment: true,
}
updatedDrinkData := DrinkData{
Name: "Daquari",
Expand All @@ -195,7 +196,8 @@ func TestFullCRUDLoop(t *testing.T) {
"0.5 oz simple syrup",
"0.75 oz lime",
},
Publicity: DrinkPublicityPrivate,
Publicity: DrinkPublicityPrivate,
UnderDevelopment: false,
}

body := CreateDrinkRequest{DrinkData: origDrinkData}
Expand Down
3 changes: 1 addition & 2 deletions pkg/slow/slowdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package slow

import (
"github.com/gofiber/fiber/v2"
"os"
log "github.com/sirupsen/logrus"
"os"
"time"
)


func SlowDown(app *fiber.App) {
val, ok := os.LookupEnv("SLOWDOWN_AMOUNT")
if !ok {
Expand Down

0 comments on commit c25fa0f

Please sign in to comment.