From c3d00b5dec150a69f31c3c965ea5bce08b3e7a0f Mon Sep 17 00:00:00 2001 From: FedorovVladimir Date: Sun, 9 Apr 2023 13:31:01 +0700 Subject: [PATCH] add products --- cmd/valera/main.go | 2 +- .../{calories => states/eat_bot_state}/calories.go | 12 +++++++----- .../eat_bot_state}/calories_test.go | 4 ++-- internal/states/eat_bot_state/eat_bot_state.go | 3 +-- internal/{pause => states/pause_bot_state}/pause.go | 4 ++-- internal/states/pause_bot_state/pause_bot_state.go | 3 +-- 6 files changed, 14 insertions(+), 14 deletions(-) rename internal/{calories => states/eat_bot_state}/calories.go (69%) rename internal/{calories => states/eat_bot_state}/calories_test.go (92%) rename internal/{pause => states/pause_bot_state}/pause.go (78%) diff --git a/cmd/valera/main.go b/cmd/valera/main.go index d8b4996..4139192 100644 --- a/cmd/valera/main.go +++ b/cmd/valera/main.go @@ -19,7 +19,7 @@ import ( ) const ( - version = "v1.7.0" + version = "v1.7.2" ) func main() { diff --git a/internal/calories/calories.go b/internal/states/eat_bot_state/calories.go similarity index 69% rename from internal/calories/calories.go rename to internal/states/eat_bot_state/calories.go index 57b8257..1dc83f4 100644 --- a/internal/calories/calories.go +++ b/internal/states/eat_bot_state/calories.go @@ -1,4 +1,4 @@ -package calories +package eat_bot_state import ( "strconv" @@ -10,13 +10,15 @@ var ( caloriesIn100G int awgWeightG int }{ - "чай": {caloriesIn100G: 65, awgWeightG: 200}, - "яблоко": {caloriesIn100G: 52, awgWeightG: 242}, - "хлеб": {caloriesIn100G: 245, awgWeightG: 35}, + "чай": {caloriesIn100G: 65, awgWeightG: 200}, + "яблоко": {caloriesIn100G: 52, awgWeightG: 242}, + "хлеб": {caloriesIn100G: 245, awgWeightG: 35}, + "огурец": {caloriesIn100G: 15, awgWeightG: 20}, + "помидор": {caloriesIn100G: 18, awgWeightG: 18}, } ) -func CalcCalories(text string) (int, error) { +func calcCalories(text string) (int, error) { product, ok := productsMap[strings.ToLower(text)] if ok { return product.caloriesIn100G * product.awgWeightG / 100, nil diff --git a/internal/calories/calories_test.go b/internal/states/eat_bot_state/calories_test.go similarity index 92% rename from internal/calories/calories_test.go rename to internal/states/eat_bot_state/calories_test.go index c5ef165..d79677c 100644 --- a/internal/calories/calories_test.go +++ b/internal/states/eat_bot_state/calories_test.go @@ -1,4 +1,4 @@ -package calories +package eat_bot_state import ( "fmt" @@ -49,7 +49,7 @@ func TestCalcCalories(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - count, err := CalcCalories(tt.text) + count, err := calcCalories(tt.text) if (err != nil) != tt.wantErr { t.Errorf("error calc calories: %v", err) return diff --git a/internal/states/eat_bot_state/eat_bot_state.go b/internal/states/eat_bot_state/eat_bot_state.go index 86de266..b89b48d 100644 --- a/internal/states/eat_bot_state/eat_bot_state.go +++ b/internal/states/eat_bot_state/eat_bot_state.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "net/http" - "valera/internal/calories" "valera/internal/db" "valera/internal/states" @@ -30,7 +29,7 @@ func NewEatBotState(bot *tgbot.BotAPI, dataBase *db.DB) states.BotState { func (s *eatBotState) Do(text string, chatInfo *db.ChatInfo, username string) error { if chatInfo.Status == string(db.UserStateEat) { - count, err := calories.CalcCalories(text) + count, err := calcCalories(text) if err != nil { log.Println(err) return nil diff --git a/internal/pause/pause.go b/internal/states/pause_bot_state/pause.go similarity index 78% rename from internal/pause/pause.go rename to internal/states/pause_bot_state/pause.go index e05307a..5cce04f 100644 --- a/internal/pause/pause.go +++ b/internal/states/pause_bot_state/pause.go @@ -1,4 +1,4 @@ -package pause +package pause_bot_state import ( "strconv" @@ -6,7 +6,7 @@ import ( "time" ) -func GetDuration(text string) (time.Duration, error) { +func getDuration(text string) (time.Duration, error) { d := strings.TrimSuffix(text, "ч") d = strings.TrimSuffix(d, "д") count, err := strconv.Atoi(d) diff --git a/internal/states/pause_bot_state/pause_bot_state.go b/internal/states/pause_bot_state/pause_bot_state.go index ae381c3..5f76ec4 100644 --- a/internal/states/pause_bot_state/pause_bot_state.go +++ b/internal/states/pause_bot_state/pause_bot_state.go @@ -5,7 +5,6 @@ import ( "log" "net/http" "valera/internal/db" - "valera/internal/pause" "valera/internal/states" tgbot "github.com/go-telegram-bot-api/telegram-bot-api" @@ -30,7 +29,7 @@ func NewPauseBotState(bot *tgbot.BotAPI, dataBase *db.DB) states.BotState { func (s *pauseBotState) Do(text string, chatInfo *db.ChatInfo, username string) error { if chatInfo.Status == string(db.UserStatePause) { - duration, err := pause.GetDuration(text) + duration, err := getDuration(text) if err != nil { log.Println(err) return nil