improve validation and exception handling in API Controllers
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
@ -13,12 +11,10 @@ namespace Oqtane.Controllers
|
||||
public class JobLogController : Controller
|
||||
{
|
||||
private readonly IJobLogRepository _jobLogs;
|
||||
private readonly ILogManager _logger;
|
||||
|
||||
public JobLogController(IJobLogRepository jobLogs, ILogManager logger)
|
||||
public JobLogController(IJobLogRepository jobLogs)
|
||||
{
|
||||
_jobLogs = jobLogs;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
@ -36,40 +32,5 @@ namespace Oqtane.Controllers
|
||||
{
|
||||
return _jobLogs.GetJobLog(id);
|
||||
}
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public JobLog Post([FromBody] JobLog jobLog)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
jobLog = _jobLogs.AddJobLog(jobLog);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Job Log Added {JobLog}", jobLog);
|
||||
}
|
||||
return jobLog;
|
||||
}
|
||||
|
||||
// PUT api/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public JobLog Put(int id, [FromBody] JobLog jobLog)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
jobLog = _jobLogs.UpdateJobLog(jobLog);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Job Log Updated {JobLog}", jobLog);
|
||||
}
|
||||
return jobLog;
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_jobLogs.DeleteJobLog(id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Job Log Deleted {JobLogId}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user