removed useless controllers edit Swagger doc

This commit is contained in:
Ruidy Nemausat 2020-02-27 18:40:44 +01:00
parent 02a123b247
commit e4fe81a45c
5 changed files with 11 additions and 351 deletions

View file

@ -1,124 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using TicketManager.Data;
using TicketManager.Models;
namespace TicketManager.Controllers
{
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class AssignmentsController : ControllerBase
{
private readonly AppDbContext _context;
public AssignmentsController(AppDbContext context)
{
_context = context;
}
// GET: api/Assignments
[HttpGet]
public async Task<ActionResult<IEnumerable<Assignment>>> GetAssignments()
{
return await _context.Assignments.ToListAsync();
}
// GET: api/Assignments/5
[HttpGet("{id}")]
public async Task<ActionResult<Assignment>> GetAssignment(int id)
{
var assignment = await _context.Assignments.FindAsync(id);
if (assignment == null)
{
return NotFound();
}
return assignment;
}
// PUT: api/Assignments/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
[HttpPut("{id}")]
public async Task<IActionResult> PutAssignment(int id, Assignment assignment)
{
if (id != assignment.ProjectId)
{
return BadRequest();
}
_context.Entry(assignment).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!AssignmentExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Assignments
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
[HttpPost]
public async Task<ActionResult<Assignment>> PostAssignment(Assignment assignment)
{
_context.Assignments.Add(assignment);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (AssignmentExists(assignment.ProjectId))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtAction("GetAssignment", new { id = assignment.ProjectId }, assignment);
}
// DELETE: api/Assignments/5
[HttpDelete("{id}")]
public async Task<ActionResult<Assignment>> DeleteAssignment(int id)
{
var assignment = await _context.Assignments.FindAsync(id);
if (assignment == null)
{
return NotFound();
}
_context.Assignments.Remove(assignment);
await _context.SaveChangesAsync();
return assignment;
}
private bool AssignmentExists(int id)
{
return _context.Assignments.Any(e => e.ProjectId == id);
}
}
}

View file

@ -1,110 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using TicketManager.Data;
using TicketManager.Models;
namespace TicketManager.Controllers
{
[Authorize]
[Route("api/v1/[controller]")]
[ApiController]
public class FilesController : ControllerBase
{
private readonly AppDbContext _context;
public FilesController(AppDbContext context)
{
_context = context;
}
// GET: api/Files
[HttpGet]
public async Task<ActionResult<IEnumerable<File>>> GetFiles()
{
return await _context.Files.ToListAsync();
}
// GET: api/Files/5
[HttpGet("{id}")]
public async Task<ActionResult<File>> GetFile(int id)
{
var file = await _context.Files.FindAsync(id);
if (file == null)
{
return NotFound();
}
return file;
}
// PUT: api/Files/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
[HttpPut("{id}")]
public async Task<IActionResult> PutFile(int id, File file)
{
if (id != file.Id)
{
return BadRequest();
}
_context.Entry(file).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!FileExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Files
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
[HttpPost]
public async Task<ActionResult<File>> PostFile(File file)
{
_context.Files.Add(file);
await _context.SaveChangesAsync();
return CreatedAtAction("GetFile", new { id = file.Id }, file);
}
// DELETE: api/Files/5
[HttpDelete("{id}")]
public async Task<ActionResult<File>> DeleteFile(int id)
{
var file = await _context.Files.FindAsync(id);
if (file == null)
{
return NotFound();
}
_context.Files.Remove(file);
await _context.SaveChangesAsync();
return file;
}
private bool FileExists(int id)
{
return _context.Files.Any(e => e.Id == id);
}
}
}

View file

@ -1,110 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using TicketManager.Data;
using TicketManager.Models;
namespace TicketManager.Controllers
{
[Authorize]
[Route("api/v1/[controller]")]
[ApiController]
public class NotesController : ControllerBase
{
private readonly AppDbContext _context;
public NotesController(AppDbContext context)
{
_context = context;
}
// GET: api/Notes
[HttpGet]
public async Task<ActionResult<IEnumerable<Note>>> GetNotes()
{
return await _context.Notes.ToListAsync();
}
// GET: api/Notes/5
[HttpGet("{id}")]
public async Task<ActionResult<Note>> GetNote(int id)
{
var note = await _context.Notes.FindAsync(id);
if (note == null)
{
return NotFound();
}
return note;
}
// PUT: api/Notes/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
[HttpPut("{id}")]
public async Task<IActionResult> PutNote(int id, Note note)
{
if (id != note.Id)
{
return BadRequest();
}
_context.Entry(note).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!NoteExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Notes
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
[HttpPost]
public async Task<ActionResult<Note>> PostNote(Note note)
{
_context.Notes.Add(note);
await _context.SaveChangesAsync();
return CreatedAtAction("GetNote", new { id = note.Id }, note);
}
// DELETE: api/Notes/5
[HttpDelete("{id}")]
public async Task<ActionResult<Note>> DeleteNote(int id)
{
var note = await _context.Notes.FindAsync(id);
if (note == null)
{
return NotFound();
}
_context.Notes.Remove(note);
await _context.SaveChangesAsync();
return note;
}
private bool NoteExists(int id)
{
return _context.Notes.Any(e => e.Id == id);
}
}
}

View file

@ -94,20 +94,23 @@ namespace TicketManager.Controllers
///
/// PUT: api/v1/Projects/3
/// {
/// "id": "357727fd-5262-4522-b8a3-38271d43de84",
/// "firstName": "Thomas",
/// "lastName": "Price",
/// "presentation": "New Team?!",
/// "email": "tp@mail.com",
/// "phone": "0198237645"
/// "id": 3,
/// "title": "Secret Project",
/// "description": "Shhttt! Don't tell anyone",
/// "endingDate": "2020-02-29T15:51:02.787373+01:00",
/// "managerId": "d7787286-9043-4b31-8e45-569d38295435"
/// }
///
/// </remarks>
/// <param name="id">Identifier of the project</param>
/// <param name="project">Updated project</param>
/// <response code="204">Request was succesful but no content is changed</response>
/// <response code="404">If the required project is null</response>
/// <response code="400">If id does not match project's</response>
[HttpPut("{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> PutProject([FromRoute] int id, [FromBody] Project project)
{
if (id != project.Id)

View file

@ -65,7 +65,7 @@ namespace TicketManager
{
Version = "v1",
Title = "Ticket Manager API",
Description = "Ticket Manger API for Teams",
Description = "Ticket Manger Web API for Teams",
Contact = new OpenApiContact
{
Name = "Ruidy Nemausat",
@ -101,6 +101,7 @@ namespace TicketManager
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Ticket Manager API v1");
c.DefaultModelsExpandDepth(-1);
});
app.UseSpaStaticFiles();