aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-19 15:47:01 +0200
committertranstrike <transtrike@gmail.com>2020-12-19 15:47:01 +0200
commitfa09c0cc6cf99034dcc1301692ccb4d019087213 (patch)
treea5d453243884a315e061ef7e3723fbf7bb68d43f /src/DevHive.Web
parent3fc676497f4a4b1671e31cc3b8cd3e4c6ac96920 (diff)
downloadDevHive-fa09c0cc6cf99034dcc1301692ccb4d019087213.tar
DevHive-fa09c0cc6cf99034dcc1301692ccb4d019087213.tar.gz
DevHive-fa09c0cc6cf99034dcc1301692ccb4d019087213.zip
Moved Friends to User(you no longer have friends)
Diffstat (limited to 'src/DevHive.Web')
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs3
-rw-r--r--src/DevHive.Web/Controllers/FriendsController.cs59
-rw-r--r--src/DevHive.Web/Controllers/UserController.cs28
-rw-r--r--src/DevHive.Web/Startup.cs2
4 files changed, 30 insertions, 62 deletions
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs
index 7ef144c..b42ae05 100644
--- a/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs
+++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs
@@ -16,8 +16,7 @@ namespace DevHive.Web.Configurations.Extensions
public static void DatabaseConfiguration(this IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext<DevHiveContext>(options =>
- options.UseNpgsql(configuration.GetConnectionString("DEV"),
- x => x.MigrationsAssembly("DevHive.Web")));
+ options.UseNpgsql(configuration.GetConnectionString("DEV")));
services.AddIdentity<User, Role>()
.AddEntityFrameworkStores<DevHiveContext>();
diff --git a/src/DevHive.Web/Controllers/FriendsController.cs b/src/DevHive.Web/Controllers/FriendsController.cs
deleted file mode 100644
index 1b9b9c5..0000000
--- a/src/DevHive.Web/Controllers/FriendsController.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using AutoMapper;
-using DevHive.Common.Models;
-using DevHive.Data.Repositories;
-using DevHive.Services.Models.Identity.User;
-using DevHive.Services.Options;
-using DevHive.Services.Services;
-using DevHive.Web.Models.Identity.User;
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Mvc;
-
-namespace DevHive.Web.Controllers
-{
- [ApiController]
- [Route("/api")]
- [Authorize(Roles = "User")]
- public class FriendsController
- {
- private readonly FriendsService _friendsService;
- private readonly IMapper _friendsMapper;
-
- public FriendsController(FriendsService friendsService, IMapper mapper)
- {
- this._friendsService = friendsService;
- this._friendsMapper = mapper;
- }
-
- //Create
- [HttpPost]
- [Route("AddAFriend")]
- public async Task<IActionResult> AddAFriend(Guid userId, [FromBody] IdModel friendIdModel)
- {
- return await this._friendsService.AddFriend(userId, friendIdModel.Id) ?
- new OkResult() :
- new BadRequestResult();
- }
-
- //Read
- [HttpGet]
- [Route("GetAFriend")]
- public async Task<IActionResult> GetAFriend(Guid friendId)
- {
- UserServiceModel friendServiceModel = await this._friendsService.GetFriendById(friendId);
- UserWebModel friend = this._friendsMapper.Map<UserWebModel>(friendServiceModel);
-
- return new OkObjectResult(friend);
- }
-
- //Delete
- [HttpDelete]
- [Route("RemoveAFriend")]
- public async Task<IActionResult> RemoveAFriend(Guid userId, Guid friendId)
- {
- await this._friendsService.RemoveFriend(userId, friendId);
- return new OkResult();
- }
- }
-} \ No newline at end of file
diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs
index b23fdee..ad2656c 100644
--- a/src/DevHive.Web/Controllers/UserController.cs
+++ b/src/DevHive.Web/Controllers/UserController.cs
@@ -9,6 +9,7 @@ using DevHive.Web.Models.Identity.User;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using DevHive.Common.Models.Identity;
+using DevHive.Common.Models;
namespace DevHive.Web.Controllers
{
@@ -53,6 +54,15 @@ namespace DevHive.Web.Controllers
return new CreatedResult("Register", tokenWebModel);
}
+ [HttpPost]
+ [Route("AddAFriend")]
+ public async Task<IActionResult> AddAFriend(Guid userId, [FromBody] IdModel friendIdModel)
+ {
+ return await this._userService.AddFriend(userId, friendIdModel.Id) ?
+ new OkResult() :
+ new BadRequestResult();
+ }
+
//Read
[HttpGet]
public async Task<IActionResult> GetById(Guid id, [FromHeader] string authorization)
@@ -66,6 +76,16 @@ namespace DevHive.Web.Controllers
return new OkObjectResult(userWebModel);
}
+ [HttpGet]
+ [Route("GetAFriend")]
+ public async Task<IActionResult> GetAFriend(Guid friendId)
+ {
+ UserServiceModel friendServiceModel = await this._userService.GetFriendById(friendId);
+ UserWebModel friend = this._userMapper.Map<UserWebModel>(friendServiceModel);
+
+ return new OkObjectResult(friend);
+ }
+
//Update
[HttpPut]
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateUserWebModel updateModel, [FromHeader] string authorization)
@@ -93,5 +113,13 @@ namespace DevHive.Web.Controllers
await this._userService.DeleteUser(id);
return new OkResult();
}
+
+ [HttpDelete]
+ [Route("RemoveAFriend")]
+ public async Task<IActionResult> RemoveAFriend(Guid userId, Guid friendId)
+ {
+ await this._userService.RemoveFriend(userId, friendId);
+ return new OkResult();
+ }
}
}
diff --git a/src/DevHive.Web/Startup.cs b/src/DevHive.Web/Startup.cs
index 66fde9e..12f72f7 100644
--- a/src/DevHive.Web/Startup.cs
+++ b/src/DevHive.Web/Startup.cs
@@ -45,7 +45,7 @@ namespace DevHive.Web
}
else
{
- app.UseExceptionHandler("/api/HttpError");
+ app.UseExceptionHandler("/api/Error");
app.UseHsts();
}