Add "Image" context to add images for the users
This commit is contained in:
68
Back/skydiveLogs-api/Controllers/ImageController.cs
Normal file
68
Back/skydiveLogs-api/Controllers/ImageController.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
public class ImageController : Base
|
||||
{
|
||||
public ImageController(IImageService imageService,
|
||||
IMapper mapper)
|
||||
{
|
||||
_imageService = imageService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
// GET: api/Image
|
||||
[HttpGet]
|
||||
[EnableCors]
|
||||
public IEnumerable<ImageResp> Get()
|
||||
{
|
||||
var result = _imageService.GetAllImages();
|
||||
return _mapper.Map<IEnumerable<ImageResp>>(result);
|
||||
}
|
||||
|
||||
// GET: api/Image/5
|
||||
[HttpGet("{id}")]
|
||||
[EnableCors]
|
||||
public ImageResp Get(int id)
|
||||
{
|
||||
var result = _imageService.GetImageById(id);
|
||||
return _mapper.Map<ImageResp>(result);
|
||||
}
|
||||
|
||||
// POST: api/Image
|
||||
[HttpPost]
|
||||
[EnableCors]
|
||||
public void Post([FromBody] ImageReq value)
|
||||
{
|
||||
_imageService.AddNewImage(_mapper.Map<Image>(value));
|
||||
}
|
||||
|
||||
// PUT: api/Image/5
|
||||
[HttpPut("{id}")]
|
||||
[EnableCors]
|
||||
public void Put(int id, [FromBody] ImageReq value)
|
||||
{
|
||||
_imageService.UpdateImage(id, _mapper.Map<Image>(value));
|
||||
}
|
||||
|
||||
// DELETE: api/Image/5
|
||||
[HttpDelete("{id}")]
|
||||
[EnableCors]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_imageService.DeleteImageById(id);
|
||||
}
|
||||
|
||||
private readonly IImageService _imageService;
|
||||
private readonly IMapper _mapper;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user