First Commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class AttachmentsController : ControllerBase
|
||||
{
|
||||
private readonly IWebHostEnvironment _env;
|
||||
public AttachmentsController(IWebHostEnvironment env) => _env = env;
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Upload([FromForm] IFormFileCollection files, [FromForm] int jobId)
|
||||
{
|
||||
var folder = Path.Combine(_env.ContentRootPath, "Attachments", jobId.ToString());
|
||||
Directory.CreateDirectory(folder);
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
var path = Path.Combine(folder, file.FileName);
|
||||
using var stream = new FileStream(path, FileMode.Create);
|
||||
await file.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using JobTrackerApi.Data;
|
||||
using JobTrackerApi.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JobTrackerApi.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CompaniesController : ControllerBase
|
||||
{
|
||||
private readonly JobTrackerContext _context;
|
||||
public CompaniesController(JobTrackerContext context) => _context = context;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<Company>> Get() =>
|
||||
await _context.Companies.Include(c => c.Jobs).ToListAsync();
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Company>> Post(Company company)
|
||||
{
|
||||
_context.Companies.Add(company);
|
||||
await _context.SaveChangesAsync();
|
||||
return CreatedAtAction(nameof(Get), new { id = company.Id }, company);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using JobTrackerApi.Data;
|
||||
using JobTrackerApi.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JobTrackerApi.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class JobApplicationsController : ControllerBase
|
||||
{
|
||||
private readonly JobTrackerContext _context;
|
||||
public JobApplicationsController(JobTrackerContext context) => _context = context;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<JobApplication>> Get() =>
|
||||
await _context.JobApplications.Include(j => j.Company).ToListAsync();
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<JobApplication>> Post(JobApplication job)
|
||||
{
|
||||
_context.JobApplications.Add(job);
|
||||
await _context.SaveChangesAsync();
|
||||
return CreatedAtAction(nameof(Get), new { id = job.Id }, job);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> Put(int id, JobApplication updatedJob)
|
||||
{
|
||||
var job = await _context.JobApplications.FindAsync(id);
|
||||
if (job == null) return NotFound();
|
||||
|
||||
job.JobTitle = updatedJob.JobTitle;
|
||||
job.Status = updatedJob.Status;
|
||||
job.ResponseReceived = updatedJob.ResponseReceived;
|
||||
job.ResponseDate = updatedJob.ResponseDate;
|
||||
job.Notes = updatedJob.Notes;
|
||||
job.CoverLetterText = updatedJob.CoverLetterText;
|
||||
job.JobUrl = updatedJob.JobUrl;
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user