From 2b3e8644f4e581874d54ac3950603edafba72bd6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 10 Dec 2020 11:54:03 +0200 Subject: Implemented User get query; disabled friends list --- API/Controllers/UserController.cs | 8 ++++++-- API/Service/UserService.cs | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'API') diff --git a/API/Controllers/UserController.cs b/API/Controllers/UserController.cs index b3da7fc..ed3d917 100644 --- a/API/Controllers/UserController.cs +++ b/API/Controllers/UserController.cs @@ -30,7 +30,11 @@ namespace API.Controllers } //Read - // [HttpGet] + [HttpGet] + public async Task GetUserById(int id) + { + return await this._service.GetUserById(id); + } // //Update // [HttpPut] @@ -38,4 +42,4 @@ namespace API.Controllers // //Delete // [HttpDelete] } -} \ No newline at end of file +} diff --git a/API/Service/UserService.cs b/API/Service/UserService.cs index a2d671a..b9fe91d 100644 --- a/API/Service/UserService.cs +++ b/API/Service/UserService.cs @@ -29,5 +29,12 @@ namespace API.Service //await this._dbRepository.AddAsync(newUser); return HttpStatusCode.OK; } + + [HttpGet] + public async Task GetUserById(int id) + { + User user = await this._dbRepository.FindByIdAsync(id); + return JsonConvert.SerializeObject(user); + } } -} \ No newline at end of file +} -- cgit v1.2.3 From 68edd82480a4107ec32adaeefa479c6364b0c841 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 10 Dec 2020 12:11:48 +0200 Subject: Implemented User put (update) query (that works with test values, needs mapper) --- API/Controllers/UserController.cs | 8 ++++++-- API/Service/UserService.cs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'API') diff --git a/API/Controllers/UserController.cs b/API/Controllers/UserController.cs index ed3d917..b75d081 100644 --- a/API/Controllers/UserController.cs +++ b/API/Controllers/UserController.cs @@ -36,8 +36,12 @@ namespace API.Controllers return await this._service.GetUserById(id); } - // //Update - // [HttpPut] + //Update + [HttpPut] + public async Task Update(int id, [FromBody] UserDTO userDTO) + { + return await this._service.UpdateUser(id, userDTO); + } // //Delete // [HttpDelete] diff --git a/API/Service/UserService.cs b/API/Service/UserService.cs index b9fe91d..e678b17 100644 --- a/API/Service/UserService.cs +++ b/API/Service/UserService.cs @@ -36,5 +36,21 @@ namespace API.Service User user = await this._dbRepository.FindByIdAsync(id); return JsonConvert.SerializeObject(user); } + + [HttpPut] + public async Task UpdateUser(int id, UserDTO userDTO) + { + // TODO: add mapper (UserDTO to User) + User user = new User{ + Id = id, + FirstName = "Misho", + LastName = "Mishov", + UserName = "cheese" + }; + await this._dbRepository.EditAsync(id, user); + + return HttpStatusCode.OK; + } + } } -- cgit v1.2.3 From 7a262ddb5c9b14250e7cdfaf4cb8f9f197bf381d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 10 Dec 2020 12:12:26 +0200 Subject: Improved User get query method name --- API/Controllers/UserController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'API') diff --git a/API/Controllers/UserController.cs b/API/Controllers/UserController.cs index b75d081..c2d6f2c 100644 --- a/API/Controllers/UserController.cs +++ b/API/Controllers/UserController.cs @@ -31,7 +31,7 @@ namespace API.Controllers //Read [HttpGet] - public async Task GetUserById(int id) + public async Task GetById(int id) { return await this._service.GetUserById(id); } -- cgit v1.2.3