/
LookupController.cs
154 lines (144 loc) · 4.93 KB
/
LookupController.cs
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using Altinn.AccessManagement.UI.Core.Services.Interfaces;
using Altinn.AccessManagement.UI.Filters;
using Altinn.Platform.Profile.Models;
using Altinn.Platform.Register.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Altinn.AccessManagement.UI.Controllers
{
/// <summary>
/// Controller responsible for all operations for lookup
/// </summary>
[ApiController]
[AutoValidateAntiforgeryTokenIfAuthCookie]
[Route("accessmanagement/api/v1/lookup/")]
public class LookupController : ControllerBase
{
private readonly ILogger _logger;
private readonly ILookupService _lookupService;
/// <summary>
/// Initializes a new instance of the <see cref="LookupController"/> class.
/// </summary>
/// <param name="logger">the logger.</param>
/// <param name="lookupService">service implementation for lookups</param>
public LookupController(
ILogger<LookupController> logger,
ILookupService lookupService)
{
_logger = logger;
_lookupService = lookupService;
}
/// <summary>
/// Endpoint for retrieving delegated rules between parties
/// </summary>
/// <response code="400">Bad Request</response>
/// <response code="500">Internal Server Error</response>
[HttpGet]
[Authorize]
[Route("org/{orgNummer}")]
public async Task<ActionResult<Party>> GetOrganisation(string orgNummer)
{
try
{
Party party = await _lookupService.GetPartyForOrganization(orgNummer);
if (party == null)
{
return new ObjectResult(ProblemDetailsFactory.CreateValidationProblemDetails(HttpContext, ModelState, 400));
}
else
{
return party;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "GetOrganisation failed to fetch organisation information");
return StatusCode(500);
}
}
/// <summary>
/// Endpoint for retrieving party if party exists in the authenticated users reporteelist
/// </summary>
/// <param name="partyId">The partyId for the reportee to look up</param>
/// <returns>Reportee if party is in authenticated users reporteelist</returns>
[HttpGet]
[Authorize]
[Route("reportee/{partyId}")]
public async Task<ActionResult<Party>> GetPartyFromReporteeListIfExists(int partyId)
{
try
{
Party party = await _lookupService.GetPartyFromReporteeListIfExists(partyId);
if (party != null)
{
return party;
}
else
{
return StatusCode(404);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "GetReportee failed to fetch reportee information");
return StatusCode(500);
}
}
/// <summary>
/// Endpoint for retrieving a party by uuid
/// </summary>
/// <param name="uuid">The uuid for the party to look up</param>
/// <returns>Party information</returns>
[HttpGet]
[Authorize]
[Route("party/{uuid}")]
public async Task<ActionResult<Party>> GetPartyByUUID(Guid uuid)
{
try
{
Party party = await _lookupService.GetPartyByUUID(uuid);
if (party != null)
{
return party;
}
else
{
return StatusCode(404);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "GetPartyByUUID failed to fetch reportee information");
return StatusCode(500);
}
}
/// <summary>
/// Endpoint for retrieving a user by uuid
/// </summary>
/// <param name="uuid">The uuid for the user to look up</param>
/// <returns>Party information</returns>
[HttpGet]
[Authorize]
[Route("user/{uuid}")]
public async Task<ActionResult<UserProfile>> GetUserByUUID(Guid uuid)
{
try
{
UserProfile user = await _lookupService.GetUserByUUID(uuid);
if (user != null)
{
return user;
}
else
{
return StatusCode(404);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "GetUserByUUID failed to fetch reportee information");
return StatusCode(500);
}
}
}
}