using Microsoft.AspNetCore.Mvc; using Stylist.Data.Models.Entities; using Stylist.Domain.Repositories.Interfaces; namespace Stylist.Web.Controllers { public class SalonsController : ApiController { private readonly ISalonRepository _salonRepository; public SalonsController(ISalonRepository salonRepository) { _salonRepository = salonRepository; } [HttpPost(ApiEndpoints.Salons.Create)] public async Task<IActionResult> Create([FromBody] Salon request) { var salon = request; var response = await _salonRepository.CreateAsync(salon); return Ok(response); } [HttpGet(ApiEndpoints.Salons.Get)] public async Task<IActionResult> Get([FromRoute] int id) { var salon = await _salonRepository.GetByIdAsync(id); if(salon is null) return NotFound(); var response = salon; return Ok(response); } [HttpGet(ApiEndpoints.Salons.GetAllRecomended)] public async Task<IActionResult> GetAllRecomended() { return Ok(await _salonRepository.GetAllRecommendedAsync()); } [HttpGet(ApiEndpoints.Salons.GetAll)] public async Task<IActionResult> GetAll() { return Ok(await _salonRepository.GetAllAsync()); } [HttpPut(ApiEndpoints.Salons.Update)] public async Task<IActionResult> Update([FromRoute] int id, [FromBody] Salon request) { var salon = request; var updatedSalon = await _salonRepository.UpdateAsync(id, salon); if (!updatedSalon) return NotFound(id); var response = updatedSalon; return Ok(response); } [HttpDelete(ApiEndpoints.Salons.Delete)] public async Task<IActionResult> Delete([FromRoute] int id) { var result = await _salonRepository.DeleteAsync(id); if(!result) return NotFound(); return Ok(result); } } }