66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using skydiveLogs_api.Business.Interface;
|
|
using skydiveLogs_api.DataContract;
|
|
using AutoMapper;
|
|
using skydiveLogs_api.Model;
|
|
|
|
namespace skydiveLogs_api.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class JumpController : ControllerBase
|
|
{
|
|
public JumpController(IJumpService jumpService,
|
|
IMapper mapper)
|
|
{
|
|
_jumpService = jumpService;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
// GET: api/Jump
|
|
[HttpGet]
|
|
public IEnumerable<JumpResp> Get()
|
|
{
|
|
var result = _jumpService.GetAllJumps();
|
|
return _mapper.Map<IEnumerable<JumpResp>>(result);
|
|
}
|
|
|
|
// GET: api/Jump/5
|
|
[HttpGet("{id}")]
|
|
public JumpResp Get(int id)
|
|
{
|
|
var result = _jumpService.GetJumpById(id);
|
|
return _mapper.Map<JumpResp>(result);
|
|
}
|
|
|
|
// POST: api/Jump
|
|
[HttpPost]
|
|
public void Post([FromBody] JumpReq value)
|
|
{
|
|
_jumpService.AddNewJump(_mapper.Map<Jump>(value));
|
|
}
|
|
|
|
// PUT: api/Jump/5
|
|
[HttpPut("{id}")]
|
|
public void Put(int id, [FromBody] JumpReq value)
|
|
{
|
|
_jumpService.UpdateJump(id, _mapper.Map<Jump>(value));
|
|
}
|
|
|
|
// DELETE: api/ApiWithActions/5
|
|
[HttpDelete("{id}")]
|
|
public void Delete(int id)
|
|
{
|
|
_jumpService.DeleteJumpById(id);
|
|
}
|
|
|
|
private readonly IJumpService _jumpService;
|
|
private readonly IMapper _mapper;
|
|
}
|
|
}
|