diff --git a/Controllers/AssignmentsController.cs b/Controllers/AssignmentsController.cs deleted file mode 100644 index 67f39e1..0000000 --- a/Controllers/AssignmentsController.cs +++ /dev/null @@ -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>> GetAssignments() - { - return await _context.Assignments.ToListAsync(); - } - - // GET: api/Assignments/5 - [HttpGet("{id}")] - public async Task> 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 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> 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> 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); - } - } -} diff --git a/Controllers/FilesController.cs b/Controllers/FilesController.cs deleted file mode 100644 index 3b422d8..0000000 --- a/Controllers/FilesController.cs +++ /dev/null @@ -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>> GetFiles() - { - return await _context.Files.ToListAsync(); - } - - // GET: api/Files/5 - [HttpGet("{id}")] - public async Task> 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 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> 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> 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); - } - } -} diff --git a/Controllers/NotesController.cs b/Controllers/NotesController.cs deleted file mode 100644 index 20fe5dc..0000000 --- a/Controllers/NotesController.cs +++ /dev/null @@ -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>> GetNotes() - { - return await _context.Notes.ToListAsync(); - } - - // GET: api/Notes/5 - [HttpGet("{id}")] - public async Task> 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 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> 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> 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); - } - } -} diff --git a/Controllers/ProjectsController.cs b/Controllers/ProjectsController.cs index 3a8476d..083eae4 100644 --- a/Controllers/ProjectsController.cs +++ b/Controllers/ProjectsController.cs @@ -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" /// } /// /// + /// Identifier of the project + /// Updated project /// Request was succesful but no content is changed /// If the required project is null + /// If id does not match project's [HttpPut("{id}")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task PutProject([FromRoute] int id, [FromBody] Project project) { if (id != project.Id) diff --git a/Startup.cs b/Startup.cs index 6e88040..699c91a 100644 --- a/Startup.cs +++ b/Startup.cs @@ -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();