-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathJobsController.cs
63 lines (56 loc) · 1.79 KB
/
JobsController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Collections.Generic;
using System.Threading.Tasks;
using Events;
using Jobs.Api.Models;
using Jobs.Api.Services;
using MassTransit;
using Microsoft.AspNetCore.Mvc;
namespace Jobs.api.Controllers
{
[Route("api/[controller]")]
public class JobsController : Controller
{
private readonly IJobRepository _jobRepository;
private readonly IBus _bus;
public JobsController(IJobRepository jobRepository, IBus bus)
{
_jobRepository = jobRepository;
_bus = bus;
}
// GET api/jobs
[HttpGet]
public async Task<IEnumerable<Job>> Get()
{
return await _jobRepository.GetAll();
}
// GET api/jobs/5
[HttpGet("{id}")]
public async Task<Job> Get(int id)
{
return await _jobRepository.Get(id);
}
// POST api/values
[HttpPost("/api/jobs/applicants")]
public async Task<IActionResult> Post([FromBody]JobApplicant model)
{
// fetch the job data
var job = await _jobRepository.Get(model.JobId);
var id = await _jobRepository.AddApplicant(model);
//var endpoint = await _bus.GetSendEndpoint(new Uri("rabbitmq://rabbitmq/dotnetgigs")); //?bind=true&queue=dotnetgigs
//await endpoint.Send<ApplicantAppliedEvent>(new { model.JobId,model.ApplicantId,job.Title});
await _bus.Publish<ApplicantAppliedEvent>(new { model.JobId, model.ApplicantId, job.Title });
return Ok(id);
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}