Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77cfb709d8 | |||
| aae68ba20e | |||
| 8883cdcb86 |
@@ -4,6 +4,7 @@ data/
|
|||||||
*.db-shm
|
*.db-shm
|
||||||
*.db-wal
|
*.db-wal
|
||||||
apocapoc-api
|
apocapoc-api
|
||||||
|
/api
|
||||||
dist/
|
dist/
|
||||||
bin/
|
bin/
|
||||||
.internal-notes/
|
.internal-notes/
|
||||||
|
|||||||
+29
-4
@@ -1,11 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"apocapoc-api/internal/application/commands"
|
"apocapoc-api/internal/application/commands"
|
||||||
@@ -155,11 +159,32 @@ func main() {
|
|||||||
router := httpInfra.NewRouter(cfg.AppURL, habitHandlers, authHandlers, statsHandlers, healthHandlers, userHandlers, exportHandlers, syncHandlers, jwtService, translator)
|
router := httpInfra.NewRouter(cfg.AppURL, habitHandlers, authHandlers, statsHandlers, healthHandlers, userHandlers, exportHandlers, syncHandlers, jwtService, translator)
|
||||||
|
|
||||||
addr := fmt.Sprintf("0.0.0.0:%s", cfg.Port)
|
addr := fmt.Sprintf("0.0.0.0:%s", cfg.Port)
|
||||||
logger.Info().Str("address", addr).Msg("Server starting")
|
server := &http.Server{
|
||||||
|
Addr: addr,
|
||||||
if err := http.ListenAndServe(addr, router); err != nil {
|
Handler: router,
|
||||||
logger.Fatal().Err(err).Msg("Server failed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shutdown := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
logger.Info().Str("address", addr).Msg("Server starting")
|
||||||
|
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
|
logger.Fatal().Err(err).Msg("Server failed")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-shutdown
|
||||||
|
logger.Info().Msg("Shutting down gracefully...")
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
if err := server.Shutdown(ctx); err != nil {
|
||||||
|
logger.Fatal().Err(err).Msg("Server forced to shutdown")
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info().Msg("Server stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseJWTExpiry(expiry string) (int, error) {
|
func parseJWTExpiry(expiry string) (int, error) {
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type mockHabitRepoForBatch struct {
|
type mockHabitRepoForBatch struct {
|
||||||
habits map[string]*entities.Habit
|
habits map[string]*entities.Habit
|
||||||
createFunc func(ctx context.Context, habit *entities.Habit) error
|
createFunc func(ctx context.Context, habit *entities.Habit) error
|
||||||
updateFunc func(ctx context.Context, habit *entities.Habit) error
|
updateFunc func(ctx context.Context, habit *entities.Habit) error
|
||||||
softDeleteFunc func(ctx context.Context, id string) error
|
softDeleteFunc func(ctx context.Context, id string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,12 +124,12 @@ type SyncHabitDTO struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SyncHabitEntryDTO struct {
|
type SyncHabitEntryDTO struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
HabitID string `json:"habit_id"`
|
HabitID string `json:"habit_id"`
|
||||||
ScheduledDate time.Time `json:"scheduled_date"`
|
ScheduledDate time.Time `json:"scheduled_date"`
|
||||||
CompletedAt time.Time `json:"completed_at"`
|
CompletedAt time.Time `json:"completed_at"`
|
||||||
Value *float64 `json:"value,omitempty"`
|
Value *float64 `json:"value,omitempty"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HabitChangesDTO struct {
|
type HabitChangesDTO struct {
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SyncHandlers struct {
|
type SyncHandlers struct {
|
||||||
getSyncChangesHandler *queries.GetSyncChangesHandler
|
getSyncChangesHandler *queries.GetSyncChangesHandler
|
||||||
applySyncBatchHandler *commands.ApplySyncBatchHandler
|
applySyncBatchHandler *commands.ApplySyncBatchHandler
|
||||||
translator *i18n.Translator
|
translator *i18n.Translator
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSyncHandlers(
|
func NewSyncHandlers(
|
||||||
|
|||||||
Reference in New Issue
Block a user