First Commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using JobTrackerApi.Data;
|
||||
using JobTrackerApi.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JobTrackerApi.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CorrespondenceController : ControllerBase
|
||||
{
|
||||
private readonly JobTrackerContext _context;
|
||||
public CorrespondenceController(JobTrackerContext context) => _context = context;
|
||||
|
||||
// GET all messages for a job
|
||||
[HttpGet("{jobId}")]
|
||||
public async Task<IEnumerable<Correspondence>> GetForJob(int jobId)
|
||||
{
|
||||
return await _context.Correspondences
|
||||
.Where(c => c.JobApplicationId == jobId)
|
||||
.OrderBy(c => c.Date)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
// POST new message
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Correspondence>> Post(Correspondence message)
|
||||
{
|
||||
_context.Correspondences.Add(message);
|
||||
await _context.SaveChangesAsync();
|
||||
return CreatedAtAction(nameof(GetForJob), new { jobId = message.JobApplicationId }, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user