diff --git a/pkg/controller/event_controller.go b/pkg/controller/event_controller.go index 59ea993..2719222 100644 --- a/pkg/controller/event_controller.go +++ b/pkg/controller/event_controller.go @@ -2,17 +2,15 @@ package controller import ( "bikefest/pkg/model" - "bikefest/pkg/service" - "github.com/gin-gonic/gin" ) type EventController struct { eventService model.EventService - asynqService service.AsynqServiceImpl + asynqService model.AsynqNotificationService } -func NewEventController(eventService model.EventService, asynqService service.AsynqServiceImpl) *EventController { +func NewEventController(eventService model.EventService, asynqService model.AsynqNotificationService) *EventController { return &EventController{ eventService: eventService, asynqService: asynqService, diff --git a/pkg/model/event.go b/pkg/model/event.go index 36ad67d..ae8f4e9 100644 --- a/pkg/model/event.go +++ b/pkg/model/event.go @@ -52,3 +52,7 @@ type EventService interface { Delete(ctx context.Context, event *Event) (rowAffected int64, err error) DeleteByUser(ctx context.Context, userID string, eventID string) (rowAffected int64, err error) } + +type AsynqNotificationService interface { + EnqueueEvent(user_id, event_id, event_start_time string) +} diff --git a/pkg/router/route.go b/pkg/router/route.go index abeac00..822f48b 100644 --- a/pkg/router/route.go +++ b/pkg/router/route.go @@ -5,13 +5,12 @@ import ( "bikefest/pkg/controller" "bikefest/pkg/middleware" "bikefest/pkg/model" - "bikefest/pkg/service" ) type Services struct { UserService model.UserService EventService model.EventService - AsynqService service.AsynqServiceImpl + AsynqService model.AsynqNotificationService } func RegisterRoutes(app *bootstrap.Application, services *Services) { diff --git a/pkg/service/asynq_client.go b/pkg/service/asynq_client.go index 811997c..3192137 100644 --- a/pkg/service/asynq_client.go +++ b/pkg/service/asynq_client.go @@ -2,6 +2,7 @@ package service import ( "bikefest/pkg/bootstrap" + "bikefest/pkg/model" "encoding/json" "log" "time" @@ -41,6 +42,7 @@ func (as *AsynqServiceImpl) EnqueueEvent(user_id, event_id, event_start_time str location, _ := time.LoadLocation(as.env.Server.TimeZone) timeForm := "2006/01/02 15:04:05" + //TODO: currently we only set the process time 30 minutes before the event start time process_time, _ := time.ParseInLocation(timeForm, event_start_time, location) process_time = process_time.Add(-time.Minute * 30) @@ -51,8 +53,8 @@ func (as *AsynqServiceImpl) EnqueueEvent(user_id, event_id, event_start_time str log.Printf(" [*] Successfully enqueued task: %+v\nThe task should be executed at %s", info, process_time.String()) } -func NewAsynqService(client *asynq.Client, env *bootstrap.Env) AsynqServiceImpl { - return AsynqServiceImpl{ +func NewAsynqService(client *asynq.Client, env *bootstrap.Env) model.AsynqNotificationService { + return &AsynqServiceImpl{ client: client, env: env, }