aboutsummaryrefslogtreecommitdiff
path: root/API/Controllers/UserController.cs
blob: b75d081032ff29f476be7f7e1f2b9ab17e4a4f96 (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
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using API.Database;
using API.Service;
using Microsoft.AspNetCore.Mvc;
using Models.Classes;
using Models.DTOs;

namespace API.Controllers
{
	[ApiController]
	[Route("/api/[controller]")]
	public class UserController: ControllerBase
	{
		private readonly UserService _service;

		public UserController(DevHiveContext context)
		{
			this._service = new UserService(context);
		}

		//Create
		[HttpPost]
		public async Task<HttpStatusCode> Create([FromBody] UserDTO userDTO)
		{
			HttpStatusCode returnStatusCode = await this._service.CreateUser(userDTO);

			return returnStatusCode;
		}

		//Read
		[HttpGet]
		public async Task<string> GetUserById(int id) 
		{
			return await this._service.GetUserById(id);
		}

		//Update
		[HttpPut]
		public async Task<HttpStatusCode> Update(int id, [FromBody] UserDTO userDTO)
		{
			return await this._service.UpdateUser(id, userDTO);
		}

		// //Delete
		// [HttpDelete]
	}
}