Add Gear controller/service/repo and relations in db between Jumps and others objects
This commit is contained in:
66
Back/skydiveLogs-api/Controllers/GearController.cs
Normal file
66
Back/skydiveLogs-api/Controllers/GearController.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class GearController : ControllerBase
|
||||
{
|
||||
public GearController(IGearService gearService,
|
||||
IMapper mapper)
|
||||
{
|
||||
_gearService = gearService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
// GET: api/Gear
|
||||
[HttpGet]
|
||||
public IEnumerable<GearResp> Get()
|
||||
{
|
||||
var result = _gearService.GetAllGears();
|
||||
return _mapper.Map<IEnumerable<GearResp>>(result);
|
||||
}
|
||||
|
||||
// GET: api/Gear/5
|
||||
[HttpGet("{id}")]
|
||||
public GearResp Get(int id)
|
||||
{
|
||||
var result = _gearService.GetGearById(id);
|
||||
return _mapper.Map<GearResp>(result);
|
||||
}
|
||||
|
||||
// POST: api/Gear
|
||||
[HttpPost]
|
||||
public void Post([FromBody] GearReq value)
|
||||
{
|
||||
_gearService.AddNewGear(_mapper.Map<Gear>(value));
|
||||
}
|
||||
|
||||
// PUT: api/Gear/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] GearReq value)
|
||||
{
|
||||
_gearService.UpdateGear(id, _mapper.Map<Gear>(value));
|
||||
}
|
||||
|
||||
// DELETE: api/ApiWithActions/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
_gearService.DeleteGearById(id);
|
||||
}
|
||||
|
||||
private readonly IGearService _gearService;
|
||||
|
||||
private readonly IMapper _mapper;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,11 @@ namespace skydiveLogs_api.Controllers
|
||||
[HttpPost]
|
||||
public void Post([FromBody] JumpReq value)
|
||||
{
|
||||
_jumpService.AddNewJump(_mapper.Map<Jump>(value));
|
||||
_jumpService.AddNewJump(value.AircraftId,
|
||||
value.DropZoneId,
|
||||
value.JumpTypeId,
|
||||
value.GearId,
|
||||
_mapper.Map<Jump>(value));
|
||||
}
|
||||
|
||||
// PUT: api/Jump/5
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
Back/skydiveLogs-api/Data/LiteDB.Studio.exe
Normal file
BIN
Back/skydiveLogs-api/Data/LiteDB.Studio.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user