using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Sufi.Demo.PeopleDirectory.Application.Features.Contacts.Commands; using Sufi.Demo.PeopleDirectory.Application.Features.Contacts.Queries.GetAll; using Sufi.Demo.PeopleDirectory.Application.Features.Contacts.Queries.GetById; using System.ComponentModel.DataAnnotations; namespace Sufi.Demo.PeopleDirectory.UI.Server.Controllers.v1 { /// /// A controller for manipulating contact data. /// [ApiVersion(1.0)] public class ContactsController : BaseApiController { /// /// Get all contacts. /// /// [HttpGet] public async Task GetAll() => Ok(await Mediator.Send(new GetAllContactsQuery())); /// /// Get a contact by id. /// /// /// [HttpGet("{id}")] public async Task Get(int id) => Ok(await Mediator.Send(new GetContactByIdQuery { Id = id })); /// /// Create/Update a contact. /// /// /// [HttpPost] public async Task Post(AddEditContactCommand request) => Ok(await Mediator.Send(request)); /// /// Delete a contact. /// /// /// [HttpDelete("{id}")] public async Task Delete([Required] int id) { var command = new DeleteContactCommand { Id = id }; return Ok(await Mediator.Send(command)); } } }