mirror of
https://github.com/fergalmoran/podnoms.git
synced 2025-12-25 18:58:12 +00:00
Broken but need to create generic repository!
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Lib.Net.Http.WebPush;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -6,8 +7,10 @@ using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Options;
|
||||
using PodNoms.Api.Models;
|
||||
using PodNoms.Api.Models.Settings;
|
||||
using PodNoms.Api.Models.ViewModels;
|
||||
using PodNoms.Api.Persistence;
|
||||
using PodNoms.Api.Services;
|
||||
using PodNoms.Api.Services.Auth;
|
||||
using PodNoms.Api.Services.Hubs;
|
||||
@@ -19,18 +22,34 @@ namespace PodNoms.Api.Controllers {
|
||||
[Authorize]
|
||||
public class ChatController : BaseAuthController {
|
||||
private readonly ISupportChatService _supportChatService;
|
||||
private readonly IChatRepository _chatRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public ChatController(IHttpContextAccessor contextAccessor, UserManager<ApplicationUser> userManager,
|
||||
ISupportChatService supportChatService) :
|
||||
IMapper mapper, IUnitOfWork unitOfWork, IChatRepository chatRepository, ISupportChatService supportChatService) :
|
||||
base(contextAccessor, userManager) {
|
||||
this._chatRepository = chatRepository;
|
||||
this._unitOfWork = unitOfWork;
|
||||
this._mapper = mapper;
|
||||
this._supportChatService = supportChatService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<ChatViewModel>> Get() {
|
||||
var chats = await _chatRepository.GetAllChats(_userId);
|
||||
var response = _mapper.Map<ChatViewModel>(chats);
|
||||
return Ok(response);
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ChatViewModel>> Post([FromBody]ChatViewModel message) {
|
||||
//need to lookup the current support host and notify them
|
||||
message.FromUserName = _applicationUser.FullName;
|
||||
message.FromUserId = _applicationUser.Id;
|
||||
var chat = _mapper.Map<ChatMessage>(message);
|
||||
await _chatRepository.AddOrUpdateChat(chat);
|
||||
await this._unitOfWork.CompleteAsync();
|
||||
|
||||
if (await _supportChatService.InitiateSupportRequest(_userId, message)) {
|
||||
return Ok(message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user