chore: build
ci-api / test (push) Failing after 8m7s
ci-web / test (push) Failing after 5m5s

This commit is contained in:
Xor290
2026-09-20 12:18:33 +02:00
parent 8f4c7fa47a
commit 919c807004
174 changed files with 9669 additions and 1308 deletions
+5 -8
View File
@@ -21,7 +21,6 @@ type settingsResponse struct {
BotTokenConfigured bool `json:"bot_token_configured"`
ChatID string `json:"chat_id"`
NotifyNewOrder bool `json:"notify_new_order"`
NotifyStatusChange bool `json:"notify_status_change"`
}
func toResponse(s *Settings) settingsResponse {
@@ -30,7 +29,6 @@ func toResponse(s *Settings) settingsResponse {
BotTokenConfigured: s.BotToken != "",
ChatID: s.ChatID,
NotifyNewOrder: s.NotifyNewOrder,
NotifyStatusChange: s.NotifyStatusChange,
}
}
@@ -44,11 +42,10 @@ func (h *Handler) Get(c *gin.Context) {
}
type updateRequest struct {
Enabled bool `json:"enabled"`
BotToken string `json:"bot_token"`
ChatID string `json:"chat_id" binding:"required_if=Enabled true"`
NotifyNewOrder bool `json:"notify_new_order"`
NotifyStatusChange bool `json:"notify_status_change"`
Enabled bool `json:"enabled"`
BotToken string `json:"bot_token"`
ChatID string `json:"chat_id" binding:"required_if=Enabled true"`
NotifyNewOrder bool `json:"notify_new_order"`
}
func (h *Handler) Update(c *gin.Context) {
@@ -57,7 +54,7 @@ func (h *Handler) Update(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "validation error", "details": err.Error()})
return
}
settings, err := h.service.Update(c.Request.Context(), req.Enabled, req.BotToken, req.ChatID, req.NotifyNewOrder, req.NotifyStatusChange)
settings, err := h.service.Update(c.Request.Context(), req.Enabled, req.BotToken, req.ChatID, req.NotifyNewOrder)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to update telegram settings"})
return
+7 -8
View File
@@ -9,14 +9,13 @@ package telegram
import "time"
type Settings struct {
ID int16 `gorm:"primaryKey"`
Enabled bool
BotToken string
ChatID string
NotifyNewOrder bool
NotifyStatusChange bool
CreatedAt time.Time
UpdatedAt time.Time
ID int16 `gorm:"primaryKey"`
Enabled bool
BotToken string
ChatID string
NotifyNewOrder bool
CreatedAt time.Time
UpdatedAt time.Time
}
func (Settings) TableName() string { return "telegram_settings" }
@@ -30,10 +30,9 @@ func (r *gormRepository) Get(ctx context.Context) (*Settings, error) {
func (r *gormRepository) Update(ctx context.Context, s *Settings) error {
s.ID = 1
updates := map[string]any{
"enabled": s.Enabled,
"chat_id": s.ChatID,
"notify_new_order": s.NotifyNewOrder,
"notify_status_change": s.NotifyStatusChange,
"enabled": s.Enabled,
"chat_id": s.ChatID,
"notify_new_order": s.NotifyNewOrder,
}
// bot_token is only overwritten when explicitly provided (see service.go):
// a blank value in the update request means "keep the existing secret".
+5 -10
View File
@@ -23,13 +23,12 @@ func (s *Service) Get(ctx context.Context) (*Settings, error) {
// Update persists the settings. botToken == "" means "leave the currently
// stored token untouched" -- the admin never has to re-type the secret just
// to flip a checkbox, and the API never has to echo it back.
func (s *Service) Update(ctx context.Context, enabled bool, botToken, chatID string, notifyNewOrder, notifyStatusChange bool) (*Settings, error) {
func (s *Service) Update(ctx context.Context, enabled bool, botToken, chatID string, notifyNewOrder bool) (*Settings, error) {
settings := &Settings{
Enabled: enabled,
BotToken: botToken,
ChatID: chatID,
NotifyNewOrder: notifyNewOrder,
NotifyStatusChange: notifyStatusChange,
Enabled: enabled,
BotToken: botToken,
ChatID: chatID,
NotifyNewOrder: notifyNewOrder,
}
if err := s.repo.Update(ctx, settings); err != nil {
return nil, err
@@ -56,10 +55,6 @@ func (s *Service) NotifyNewOrder(ctx context.Context, summary string) {
s.notify(ctx, func(st *Settings) bool { return st.NotifyNewOrder }, summary)
}
func (s *Service) NotifyOrderStatusChange(ctx context.Context, summary string) {
s.notify(ctx, func(st *Settings) bool { return st.NotifyStatusChange }, summary)
}
func (s *Service) notify(ctx context.Context, shouldSend func(*Settings) bool, text string) {
settings, err := s.repo.Get(ctx)
if err != nil {