44 lines
831 B
Go
44 lines
831 B
Go
package job
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/jobs-scraper/internal/dto"
|
|
"github.com/jobs-scraper/internal/infrastructure/rabbitmq"
|
|
"github.com/jobs-scraper/libs/repo"
|
|
)
|
|
|
|
type ApplyForJob struct {
|
|
jobRepo *repo.JobRepository
|
|
rmq *rabbitmq.RabbitMQClient
|
|
}
|
|
|
|
func NewApplyForJobHandler(jobRepo *repo.JobRepository, rmq *rabbitmq.RabbitMQClient) *ApplyForJob {
|
|
return &ApplyForJob{
|
|
jobRepo: jobRepo,
|
|
rmq: rmq,
|
|
}
|
|
}
|
|
|
|
func (aj *ApplyForJob) Handle(jobId int) error {
|
|
job, err := aj.jobRepo.GetJobWithDescription(jobId)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
jobDTO := dto.JobWithDescriptionFromDomain(*job)
|
|
jsonData, err := json.Marshal(jobDTO)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = aj.rmq.Publish(rabbitmq.JobApplierQueue, rabbitmq.ScraperExchange, jsonData)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|