aboutsummaryrefslogtreecommitdiff
path: root/Backend/Api/Api/Controllers/LocationController.cs
blob: bb0b0ab5088a2a995c34896424d8173e6edb7c95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Api.Interfaces;
using Api.Models;
using Microsoft.AspNetCore.Authorization;
using System.Data;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LocationController : ControllerBase
    {
        private readonly ILocationService _locationService;
        public LocationController(ILocationService locationService)
        {
            _locationService = locationService;
        }

        [HttpPost("add")]
        [Authorize(Roles = "User")]
        public async Task<ActionResult<Location>> addPost([FromBody] Location loc)
        {
            var res = await _locationService.add(loc);
            if (res != null)
            {
                return Ok(res);
            }
            return BadRequest();
        }
        [HttpGet]
        [Authorize(Roles = "User")]
        public async Task<ActionResult<List<Location>>> getAllPosts()
        {
            var res = await _locationService.getAllLocation();
            if (res != null)
            {
                return Ok(res);
            }
            return BadRequest();
        }
        [HttpGet("loc /{id}")]
        [Authorize(Roles = "User")]
        public async Task<ActionResult<Location>> getLocationByid(string id)
        {
            var res = await _locationService.getById(id);
            if (res != null)
            {
                return Ok(res);
            }
            return BadRequest();
        }
    }
}