normaliseeol
This commit is contained in:
+53
-53
@@ -1,53 +1,53 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"gotemplate/internal/document"
|
||||
"gotemplate/internal/queue"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
)
|
||||
|
||||
type DocumentController struct {
|
||||
document document.Service
|
||||
}
|
||||
|
||||
func NewDocumentController(svc document.Service) *DocumentController {
|
||||
return &DocumentController{
|
||||
document: svc,
|
||||
}
|
||||
}
|
||||
|
||||
type DocumentQueryEvent struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (s *DocumentController) Sync(ctx context.Context, config *queue.QueueConfig, msg *types.Message) error {
|
||||
var body document.Document
|
||||
err := json.Unmarshal([]byte(*msg.Body), &body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.document.Sync(ctx, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryEvent := DocumentQueryEvent{
|
||||
ID: body.ID,
|
||||
}
|
||||
|
||||
err = queue.Send(ctx, config, "DOCQUERY", queryEvent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = queue.Delete(ctx, config, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"gotemplate/internal/document"
|
||||
"gotemplate/internal/queue"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
)
|
||||
|
||||
type DocumentController struct {
|
||||
document document.Service
|
||||
}
|
||||
|
||||
func NewDocumentController(svc document.Service) *DocumentController {
|
||||
return &DocumentController{
|
||||
document: svc,
|
||||
}
|
||||
}
|
||||
|
||||
type DocumentQueryEvent struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (s *DocumentController) Sync(ctx context.Context, config *queue.QueueConfig, msg *types.Message) error {
|
||||
var body document.Document
|
||||
err := json.Unmarshal([]byte(*msg.Body), &body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.document.Sync(ctx, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryEvent := DocumentQueryEvent{
|
||||
ID: body.ID,
|
||||
}
|
||||
|
||||
err = queue.Send(ctx, config, "DOCQUERY", queryEvent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = queue.Delete(ctx, config, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user