-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductizerController.cs
More file actions
116 lines (105 loc) · 5.94 KB
/
ProductizerController.cs
File metadata and controls
116 lines (105 loc) · 5.94 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
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using VirtualFinland.UserAPI.Activities.Productizer.Operations.BasicInformation;
using VirtualFinland.UserAPI.Activities.Productizer.Operations.JobApplicantProfile;
using VirtualFinland.UserAPI.Activities.Productizer.Operations.User;
using VirtualFinland.UserAPI.Exceptions;
using VirtualFinland.UserAPI.Helpers;
using VirtualFinland.UserAPI.Helpers.Services;
namespace VirtualFinland.UserAPI.Activities.Productizer;
[ApiController]
[Authorize]
[Authorize(Policy = "RequestFromDataspace")]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[Produces("application/json")]
public class ProductizerController : ApiControllerBase
{
private readonly TestbedConsentSecurityService _consentSecurityService;
private readonly string _userProfileDataSourceURI;
public ProductizerController(
IMediator mediator,
AuthenticationService authenticationService,
TestbedConsentSecurityService consentSecurityService,
IConfiguration configuration) : base(mediator, authenticationService)
{
_consentSecurityService = consentSecurityService;
_userProfileDataSourceURI = configuration["ConsentDataSources:UserProfile"] ?? throw new ArgumentNullException("ConsentDataSources:UserProfile");
}
[HttpPost("/productizer/test/lassipatanen/User/Profile")]
[SwaggerOperation(Summary = "Get the current logged user personal profile (Testbed Productizer)",
Description = "Returns the current logged user own personal details and his default search profile.")]
[ProducesResponseType(typeof(GetUserProfile.User), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesErrorResponseType(typeof(ProblemDetails))]
public async Task<IActionResult> GetTestbedIdentityUser()
{
await _consentSecurityService.VerifyConsentTokenRequestHeaders(Request.Headers, _userProfileDataSourceURI);
var requestAuthenticatedUser = await _authenticationService.Authenticate(HttpContext);
return Ok(await _mediator.Send(new GetUserProfile.Query(requestAuthenticatedUser)));
}
[HttpPost("/productizer/test/lassipatanen/User/Profile/Write")]
[SwaggerOperation(Summary = "Updates the current logged user personal profile (Testbed Productizer)",
Description = "Updates the current logged user own personal details and his default search profile.")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesErrorResponseType(typeof(ProblemDetails))]
public async Task<IActionResult> UpdateUser(UpdateUserProfile.Command command)
{
await _consentSecurityService.VerifyConsentTokenRequestHeaders(Request.Headers, _userProfileDataSourceURI);
var requestAuthenticatedUser = await _authenticationService.Authenticate(HttpContext);
command.SetAuth(requestAuthenticatedUser);
return Ok(await _mediator.Send(command));
}
[HttpPost("productizer/Person/BasicInformation_v0.1")]
[HttpPost("productizer/Person/BasicInformation_v1.0")]
[SwaggerOperation(Summary = "Get person basic information",
Description = "Gets data product matching endpoint path from Testbed")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesErrorResponseType(typeof(ProblemDetails))]
public async Task<IActionResult> GetPersonBasicInformation()
{
var requestAuthenticatedUser = await _authenticationService.Authenticate(HttpContext);
var result = await _mediator.Send(new GetPersonBasicInformation.Query(requestAuthenticatedUser));
if (!ProductizerProfileValidator.IsPersonBasicInformationCreated(result)) throw new NotFoundException("Person not found");
return Ok(result);
}
[HttpPost("productizer/Person/BasicInformation/Write_v0.1")]
[HttpPost("productizer/Person/BasicInformation/Write_v1.0")]
[SwaggerOperation(Summary = "Update person basic information",
Description = "Updates data product matching endpoint path from Testbed")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesErrorResponseType(typeof(ProblemDetails))]
public async Task<IActionResult> SaveOrUpdatePersonBasicInformation(
UpdatePersonBasicInformation.Command command)
{
var requestAuthenticatedUser = await AuthenticateOrRegisterPerson();
command.SetAuth(requestAuthenticatedUser);
return Ok(await _mediator.Send(command));
}
[HttpPost("productizer/Person/JobApplicantProfile_v0.1")]
[HttpPost("productizer/Person/JobApplicantProfile_v1.0")]
[SwaggerOperation(Summary = "Get person job applicant profile",
Description = "Gets data product matching endpoint path from Testbed")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesErrorResponseType(typeof(ProblemDetails))]
public async Task<IActionResult> GetPersonJobApplicantInformation()
{
var requestAuthenticatedUser = await _authenticationService.Authenticate(HttpContext);
var result = await _mediator.Send(new GetJobApplicantProfile.Query(requestAuthenticatedUser));
if (!ProductizerProfileValidator.IsJobApplicantProfileCreated(result)) throw new NotFoundException("Job applicant profile not found");
return Ok(result);
}
[HttpPost("productizer/Person/JobApplicantProfile/Write_v0.1")]
[HttpPost("productizer/Person/JobApplicantProfile/Write_v1.0")]
[SwaggerOperation(Summary = "Update person job applicant profile",
Description = "Updates data product matching endpoint path from Testbed")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesErrorResponseType(typeof(ProblemDetails))]
public async Task<IActionResult> SaveOrUpdatePersonJobApplicantProfile(UpdateJobApplicantProfile.Command command)
{
var requestAuthenticatedUser = await AuthenticateOrRegisterPerson();
command.SetAuth(requestAuthenticatedUser);
return Ok(await _mediator.Send(command));
}
}