Add "Image" context to add images for the users
This commit is contained in:
45
Back/skydiveLogs-api.Business/ImageService.cs
Normal file
45
Back/skydiveLogs-api.Business/ImageService.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
using skydiveLogs_api.Data.Interface;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class ImageService : IImageService
|
||||
{
|
||||
public ImageService(IImageRepository imageRepository)
|
||||
{
|
||||
_imageRepository = imageRepository;
|
||||
}
|
||||
|
||||
public void AddNewImage(Image newImage)
|
||||
{
|
||||
_imageRepository.Add(newImage);
|
||||
}
|
||||
|
||||
public void DeleteImageById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Image GetImageById(int id)
|
||||
{
|
||||
return _imageRepository.GetById(id);
|
||||
}
|
||||
|
||||
public IEnumerable<Image> GetAllImages()
|
||||
{
|
||||
return _imageRepository.GetAll();
|
||||
}
|
||||
|
||||
public void UpdateImage(int id, Image Image)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IImageRepository _imageRepository;
|
||||
}
|
||||
}
|
||||
20
Back/skydiveLogs-api.Business/Interface/IImageService.cs
Normal file
20
Back/skydiveLogs-api.Business/Interface/IImageService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interface
|
||||
{
|
||||
public interface IImageService
|
||||
{
|
||||
IEnumerable<Image> GetAllImages();
|
||||
|
||||
Image GetImageById(int id);
|
||||
|
||||
void AddNewImage(Image Image);
|
||||
|
||||
void UpdateImage(int id, Image Image);
|
||||
|
||||
void DeleteImageById(int id);
|
||||
}
|
||||
}
|
||||
55
Back/skydiveLogs-api.Data/ImageRepository.cs
Normal file
55
Back/skydiveLogs-api.Data/ImageRepository.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Data.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class ImageRepository : IImageRepository
|
||||
{
|
||||
public ImageRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfImage;
|
||||
}
|
||||
|
||||
public IEnumerable<Image> GetAll()
|
||||
{
|
||||
return _col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public Image GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
public bool Update(Image image)
|
||||
{
|
||||
return _col.Update(image);
|
||||
}
|
||||
|
||||
public bool Add(Image newImage)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
try
|
||||
{
|
||||
_col.Insert(newImage);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<Image> _col;
|
||||
}
|
||||
}
|
||||
@@ -22,5 +22,7 @@ namespace skydiveLogs_api.Data.Interface
|
||||
ILiteCollection<Jump> CollOfJump { get; }
|
||||
|
||||
ILiteCollection<User> CollOfUser { get; }
|
||||
|
||||
ILiteCollection<Image> CollOfImage { get; }
|
||||
}
|
||||
}
|
||||
|
||||
9
Back/skydiveLogs-api.Data/Interface/IImageRepository.cs
Normal file
9
Back/skydiveLogs-api.Data/Interface/IImageRepository.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IImageRepository : IRepository<Image>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ namespace skydiveLogs_api.Data
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Aircraft, "Aircraft");
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.DropZone, "DropZone");
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Gear, "Gear");
|
||||
|
||||
BsonMapper.Global.Entity<Image>().DbRef(x => x.UserId, "User");
|
||||
}
|
||||
|
||||
public ILiteCollection<T> GetCollection<T>()
|
||||
@@ -39,5 +41,7 @@ namespace skydiveLogs_api.Data
|
||||
public ILiteCollection<Jump> CollOfJump => _db.GetCollection<Jump>();
|
||||
|
||||
public ILiteCollection<User> CollOfUser => _db.GetCollection<User>();
|
||||
|
||||
public ILiteCollection<Image> CollOfImage => _db.GetCollection<Image>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteDB" Version="5.0.7" />
|
||||
<PackageReference Include="LiteDB" Version="5.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace skydiveLogs_api.Model
|
||||
namespace skydiveLogs_api.Model
|
||||
{
|
||||
public class Aircraft
|
||||
{
|
||||
|
||||
13
Back/skydiveLogs-api.Model/Image.cs
Normal file
13
Back/skydiveLogs-api.Model/Image.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace skydiveLogs_api.Model
|
||||
{
|
||||
public class Image
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Data { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace skydiveLogs_api.Model
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Model
|
||||
{
|
||||
public class User
|
||||
{
|
||||
@@ -13,5 +15,7 @@
|
||||
public string Login { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public IEnumerable<Image> Images { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
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