-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathAccountController.cs
More file actions
118 lines (104 loc) · 4.65 KB
/
AccountController.cs
File metadata and controls
118 lines (104 loc) · 4.65 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Net;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using HwProj.AuthService.API.Services;
using HwProj.Models.AuthService.DTO;
using HwProj.Models.AuthService.ViewModels;
using HwProj.Models.Result;
using Google.Apis.Auth;
namespace HwProj.AuthService.API.Controllers
{
[Route("api/account")]
[ApiController]
public class AccountController : ControllerBase
{
private readonly IAccountService _accountService;
private readonly IUserManager _userManager;
private readonly IMapper _mapper;
public AccountController(IAccountService accountService, IUserManager userManager, IMapper mapper)
{
_accountService = accountService;
_userManager = userManager;
_mapper = mapper;
}
[HttpGet("getUserData/{userId}")]
[ProducesResponseType(typeof(AccountDataDto), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetUserDataById(string userId)
{
var accountData = await _accountService.GetAccountDataAsync(userId).ConfigureAwait(false);
return accountData != null
? Ok(accountData)
: NotFound() as IActionResult;
}
[HttpPost("register")]
[ProducesResponseType(typeof(Result<TokenCredentials>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Register([FromBody] RegisterViewModel model)
{
var newModel = _mapper.Map<RegisterDataDTO>(model);
var result = await _accountService.RegisterUserAsync(newModel).ConfigureAwait(false);
return Ok(result);
}
[HttpPost("login")]
[ProducesResponseType(typeof(Result<TokenCredentials>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Login([FromBody] LoginViewModel model)
{
var tokenMeta = await _accountService.LoginUserAsync(model).ConfigureAwait(false);
return Ok(tokenMeta);
}
[HttpPut("edit/{userId}")]
[ProducesResponseType(typeof(Result), (int)HttpStatusCode.OK)]
public async Task<IActionResult> Edit([FromBody] EditAccountViewModel model, string userId)
{
var newModel = _mapper.Map<EditDataDTO>(model);
var result = await _accountService.EditAccountAsync(userId, newModel).ConfigureAwait(false);
return Ok(result);
}
[HttpPost("inviteNewLecturer")]
[ProducesResponseType(typeof(Result), (int)HttpStatusCode.OK)]
public async Task<IActionResult> InviteNewLecturer(InviteLecturerViewModel model)
{
var result = await _accountService.InviteNewLecturer(model.Email).ConfigureAwait(false);
return Ok(result);
}
[HttpPost("google/{tokenId}")]
[ProducesResponseType(typeof(Result<TokenCredentials>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GoogleRegister(string tokenId)
{
var payload = await GoogleJsonWebSignature.ValidateAsync(tokenId, new GoogleJsonWebSignature.ValidationSettings());
var result = await _accountService.LoginUserByGoogleAsync(payload).ConfigureAwait(false);
return Ok(result);
}
[HttpPut("editExternal/{userId}")]
[ProducesResponseType(typeof(Result), (int)HttpStatusCode.OK)]
public async Task<IActionResult> EditExternal([FromBody] EditExternalViewModel model, string userId)
{
var newModel = _mapper.Map<EditDataDTO>(model);
var result = await _accountService.EditAccountAsync(userId, newModel).ConfigureAwait(false);
return Ok(result);
}
[HttpGet("findByEmail/{email}")]
[ProducesResponseType(typeof(UserViewModel), (int)HttpStatusCode.OK)]
public async Task<IActionResult> FindByEmail(string email)
{
var user = await _userManager.FindByEmailAsync(email);
return Ok(user);
}
[HttpPost("getRole")]
[ProducesResponseType(typeof(string), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetRolesAsync([FromBody] UserViewModel userViewModel)
{
var roles = await _userManager.GetRolesAsync(userViewModel);
return Ok(roles[0]);
}
[HttpGet("getAllStudents")]
[ProducesResponseType(typeof(AccountDataDto[]), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetAllStudents()
{
var result = await _accountService.GetAllStudents();
return result == null
? NotFound()
: Ok(result) as IActionResult;
}
}
}