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;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
11
Back/skydiveLogs-api/DataContract/ImageReq.cs
Normal file
11
Back/skydiveLogs-api/DataContract/ImageReq.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace skydiveLogs_api.DataContract
|
||||
{
|
||||
public class ImageReq
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Data { get; set; }
|
||||
}
|
||||
}
|
||||
11
Back/skydiveLogs-api/DataContract/ImageResp.cs
Normal file
11
Back/skydiveLogs-api/DataContract/ImageResp.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace skydiveLogs_api.DataContract
|
||||
{
|
||||
public class ImageResp
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Data { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ namespace skydiveLogs_api.Mapper
|
||||
CreateMap<DataContract.DropZoneReq, Model.DropZone>();
|
||||
CreateMap<DataContract.GearReq, Model.Gear>();
|
||||
CreateMap<DataContract.UserReq, Model.User>();
|
||||
CreateMap<DataContract.ImageReq, Model.Image>();
|
||||
|
||||
CreateMap<Model.Gear, DataContract.GearResp>();
|
||||
CreateMap<Model.Jump, DataContract.JumpResp>();
|
||||
@@ -20,6 +21,7 @@ namespace skydiveLogs_api.Mapper
|
||||
CreateMap<Model.DropZone ,DataContract.DropZoneResp>();
|
||||
CreateMap<Model.Statistic ,DataContract.StatisticResp>();
|
||||
CreateMap<Model.User, DataContract.UserResp>();
|
||||
CreateMap<Model.Image, DataContract.ImageResp>();
|
||||
|
||||
CreateMap<Model.SimpleSummary, DataContract.SimpleSummaryResp>();
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="9.0.0" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.5.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user