Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format all files #804

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
447 changes: 447 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

42 changes: 27 additions & 15 deletions src/CareTogether.Api/Controllers/CommunicationsController.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
using CareTogether.Managers.Communications;
using System;
using System.Collections.Immutable;
using System.Threading.Tasks;
using CareTogether.Managers.Communications;
using CareTogether.Utilities.Telephony;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Immutable;
using System.Threading.Tasks;

namespace CareTogether.Api.Controllers
{
public sealed record SendSmsToFamilyPrimaryContactsRequest(
ImmutableList<Guid> FamilyIds, string SourceNumber, string Message);
ImmutableList<Guid> FamilyIds,
string SourceNumber,
string Message
);

[ApiController]
[Route("/api/{organizationId:guid}/{locationId:guid}/[controller]")]
[Authorize(Policies.ForbidAnonymous, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class CommunicationsController : ControllerBase
{
private readonly ICommunicationsManager communicationsManager;
readonly ICommunicationsManager _CommunicationsManager;

public CommunicationsController(
ICommunicationsManager communicationsManager)
public CommunicationsController(ICommunicationsManager communicationsManager)
{
this.communicationsManager = communicationsManager;
_CommunicationsManager = communicationsManager;
}


[HttpPost("sendSmsToFamilyPrimaryContacts")]
public async Task<ActionResult<ImmutableList<(Guid FamilyId, SmsMessageResult? Result)>>>
SendSmsToFamilyPrimaryContactsAsync(Guid organizationId, Guid locationId,
[FromBody] SendSmsToFamilyPrimaryContactsRequest request)
public async Task<
ActionResult<ImmutableList<(Guid FamilyId, SmsMessageResult? Result)>>
> SendSmsToFamilyPrimaryContactsAsync(
Guid organizationId,
Guid locationId,
[FromBody] SendSmsToFamilyPrimaryContactsRequest request
)
{
var result = await communicationsManager.SendSmsToFamilyPrimaryContactsAsync(organizationId, locationId,
User, request.FamilyIds, request.SourceNumber, request.Message);
ImmutableList<(Guid FamilyId, SmsMessageResult? Result)>? result =
await _CommunicationsManager.SendSmsToFamilyPrimaryContactsAsync(
organizationId,
locationId,
User,
request.FamilyIds,
request.SourceNumber,
request.Message
);
return Ok(result);
}
}
Expand Down
69 changes: 40 additions & 29 deletions src/CareTogether.Api/Controllers/ConfigurationController.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,81 @@
using CareTogether.Engines.Authorization;
using System;
using System.Threading.Tasks;
using CareTogether.Engines.Authorization;
using CareTogether.Resources.Policies;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.FeatureManagement;
using System;
using System.Threading.Tasks;

namespace CareTogether.Api.Controllers
{
public sealed record CurrentFeatureFlags(
bool InviteUser,
bool FamilyScreenV2,
bool FamilyScreenPageVersionSwitch
);
public sealed record CurrentFeatureFlags(bool InviteUser, bool FamilyScreenV2, bool FamilyScreenPageVersionSwitch);

[ApiController]
[Authorize(Policies.ForbidAnonymous, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class ConfigurationController : ControllerBase
{
private readonly IPoliciesResource policiesResource;
private readonly IFeatureManager featureManager;
private readonly IAuthorizationEngine authorizationEngine;

readonly IAuthorizationEngine _AuthorizationEngine;
readonly IFeatureManager _FeatureManager;
readonly IPoliciesResource _PoliciesResource;

public ConfigurationController(IPoliciesResource policiesResource,
IFeatureManager featureManager, IAuthorizationEngine authorizationEngine)
public ConfigurationController(
IPoliciesResource policiesResource,
IFeatureManager featureManager,
IAuthorizationEngine authorizationEngine
)
{
//TODO: Delegate this controller's methods to a manager service
this.policiesResource = policiesResource;
this.featureManager = featureManager;
this.authorizationEngine = authorizationEngine;
_PoliciesResource = policiesResource;
_FeatureManager = featureManager;
_AuthorizationEngine = authorizationEngine;
}


[HttpGet("/api/{organizationId:guid}/[controller]")]
public async Task<ActionResult<OrganizationConfiguration>> GetOrganizationConfiguration(Guid organizationId)
{
var result = await policiesResource.GetConfigurationAsync(organizationId);
OrganizationConfiguration? result = await _PoliciesResource.GetConfigurationAsync(organizationId);
return Ok(result);
}

[HttpPut("/api/{organizationId:guid}/[controller]/roles/{roleName}")]
public async Task<ActionResult<OrganizationConfiguration>> PutRoleDefinition(Guid organizationId,
string roleName, [FromBody] RoleDefinition role)
public async Task<ActionResult<OrganizationConfiguration>> PutRoleDefinition(
Guid organizationId,
string roleName,
[FromBody] RoleDefinition role
)
{
if (!User.IsInRole(SystemConstants.ORGANIZATION_ADMINISTRATOR))
{
return Forbid();
var result = await policiesResource.UpsertRoleDefinitionAsync(organizationId, roleName, role);
}

OrganizationConfiguration? result = await _PoliciesResource.UpsertRoleDefinitionAsync(
organizationId,
roleName,
role
);
return Ok(result);
}

[HttpGet("/api/{organizationId:guid}/{locationId:guid}/[controller]/policy")]
public async Task<ActionResult<EffectiveLocationPolicy>> GetEffectiveLocationPolicy(Guid organizationId, Guid locationId)
public async Task<ActionResult<EffectiveLocationPolicy>> GetEffectiveLocationPolicy(
Guid organizationId,
Guid locationId
)
{
var result = await policiesResource.GetCurrentPolicy(organizationId, locationId);
EffectiveLocationPolicy? result = await _PoliciesResource.GetCurrentPolicy(organizationId, locationId);
return Ok(result);
}

[HttpGet("/api/{organizationId:guid}/{locationId:guid}/[controller]/flags")]
public async Task<ActionResult<CurrentFeatureFlags>> GetLocationFlags(Guid organizationId)
public async Task<ActionResult<CurrentFeatureFlags>> GetLocationFlags()
{
var result = new CurrentFeatureFlags(
InviteUser: await featureManager.IsEnabledAsync(nameof(FeatureFlags.InviteUser)),
FamilyScreenV2: await featureManager.IsEnabledAsync(nameof(FeatureFlags.FamilyScreenV2)),
FamilyScreenPageVersionSwitch: await featureManager.IsEnabledAsync(nameof(FeatureFlags.FamilyScreenPageVersionSwitch))
CurrentFeatureFlags? result =
new(
await _FeatureManager.IsEnabledAsync(nameof(FeatureFlags.InviteUser)),
await _FeatureManager.IsEnabledAsync(nameof(FeatureFlags.FamilyScreenV2)),
await _FeatureManager.IsEnabledAsync(nameof(FeatureFlags.FamilyScreenPageVersionSwitch))
);
return Ok(result);
}
Expand Down
81 changes: 59 additions & 22 deletions src/CareTogether.Api/Controllers/FilesController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using CareTogether.Managers.Records;
using System;
using System.Threading.Tasks;
using CareTogether.Managers.Records;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace CareTogether.Api.Controllers
{
Expand All @@ -12,48 +12,85 @@ namespace CareTogether.Api.Controllers
[Authorize(Policies.ForbidAnonymous, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class FilesController : ControllerBase //TODO: Merge this into RecordsController
{
private readonly IRecordsManager recordsManager;


public sealed record DocumentUploadInfo(Guid DocumentId, Uri ValetUrl);

readonly IRecordsManager _RecordsManager;

public FilesController(IRecordsManager recordsManager)
{
this.recordsManager = recordsManager;
_RecordsManager = recordsManager;
}


[HttpGet("family/{familyId:guid}/{documentId:guid}")]
public async Task<ActionResult<Uri>> GetFamilyDocumentReadValetUrl(Guid organizationId, Guid locationId, Guid familyId, Guid documentId)
public async Task<ActionResult<Uri>> GetFamilyDocumentReadValetUrl(
Guid organizationId,
Guid locationId,
Guid familyId,
Guid documentId
)
{
var valetUrl = await recordsManager.GetFamilyDocumentReadValetUrl(organizationId, locationId, User,
familyId, documentId);
Uri? valetUrl = await _RecordsManager.GetFamilyDocumentReadValetUrl(
organizationId,
locationId,
User,
familyId,
documentId
);
return Ok(valetUrl); //TODO: Don't return server errors (5xx) if there were client errors (should be 4xx)!
}

[HttpPost("upload/family/{familyId:guid}/{documentId:guid}")]
public async Task<ActionResult<DocumentUploadInfo>> GenerateFamilyDocumentUploadValetUrl(Guid organizationId, Guid locationId, Guid familyId, Guid documentId)
public async Task<ActionResult<DocumentUploadInfo>> GenerateFamilyDocumentUploadValetUrl(
Guid organizationId,
Guid locationId,
Guid familyId,
Guid documentId
)
{
var valetUrl = await recordsManager.GenerateFamilyDocumentUploadValetUrl(organizationId, locationId, User,
familyId, documentId);
Uri? valetUrl = await _RecordsManager.GenerateFamilyDocumentUploadValetUrl(
organizationId,
locationId,
User,
familyId,
documentId
);
return Ok(new DocumentUploadInfo(documentId, valetUrl));
}

[HttpGet("community/{communityId:guid}/{documentId:guid}")]
public async Task<ActionResult<Uri>> GetCommunityDocumentReadValetUrl(Guid organizationId, Guid locationId, Guid communityId, Guid documentId)
public async Task<ActionResult<Uri>> GetCommunityDocumentReadValetUrl(
Guid organizationId,
Guid locationId,
Guid communityId,
Guid documentId
)
{
var valetUrl = await recordsManager.GetCommunityDocumentReadValetUrl(organizationId, locationId, User,
communityId, documentId);
Uri? valetUrl = await _RecordsManager.GetCommunityDocumentReadValetUrl(
organizationId,
locationId,
User,
communityId,
documentId
);
return Ok(valetUrl);
}

[HttpPost("upload/community/{communityId:guid}/{documentId:guid}")]
public async Task<ActionResult<DocumentUploadInfo>> GenerateCommunityDocumentUploadValetUrl(Guid organizationId, Guid locationId, Guid communityId, Guid documentId)
public async Task<ActionResult<DocumentUploadInfo>> GenerateCommunityDocumentUploadValetUrl(
Guid organizationId,
Guid locationId,
Guid communityId,
Guid documentId
)
{
var valetUrl = await recordsManager.GenerateCommunityDocumentUploadValetUrl(organizationId, locationId, User,
communityId, documentId);
Uri? valetUrl = await _RecordsManager.GenerateCommunityDocumentUploadValetUrl(
organizationId,
locationId,
User,
communityId,
documentId
);
return Ok(new DocumentUploadInfo(documentId, valetUrl));
}

public sealed record DocumentUploadInfo(Guid DocumentId, Uri ValetUrl);
}
}
52 changes: 37 additions & 15 deletions src/CareTogether.Api/Controllers/RecordsController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using CareTogether.Managers;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using CareTogether.Managers.Records;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CareTogether.Api.Controllers
{
Expand All @@ -14,34 +14,56 @@ namespace CareTogether.Api.Controllers
[Authorize(Policies.ForbidAnonymous, AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class RecordsController : ControllerBase
{
private readonly IRecordsManager recordsManager;
readonly IRecordsManager _RecordsManager;

public RecordsController(IRecordsManager recordsManager)
{
this.recordsManager = recordsManager;
_RecordsManager = recordsManager;
}


[HttpGet]
public async Task<ActionResult<IEnumerable<RecordsAggregate>>> ListVisibleAggregatesAsync(Guid organizationId, Guid locationId)
public async Task<ActionResult<IEnumerable<RecordsAggregate>>> ListVisibleAggregatesAsync(
Guid organizationId,
Guid locationId
)
{
var results = await recordsManager.ListVisibleAggregatesAsync(User, organizationId, locationId);
ImmutableList<RecordsAggregate>? results = await _RecordsManager.ListVisibleAggregatesAsync(
User,
organizationId,
locationId
);
return Ok(results);
}

[HttpPost("atomicRecordsCommand")]
public async Task<ActionResult<RecordsAggregate?>> SubmitAtomicRecordsCommandAsync(Guid organizationId, Guid locationId,
[FromBody] AtomicRecordsCommand command)
public async Task<ActionResult<RecordsAggregate?>> SubmitAtomicRecordsCommandAsync(
Guid organizationId,
Guid locationId,
[FromBody] AtomicRecordsCommand command
)
{
var result = await recordsManager.ExecuteAtomicRecordsCommandAsync(organizationId, locationId, User, command);
RecordsAggregate? result = await _RecordsManager.ExecuteAtomicRecordsCommandAsync(
organizationId,
locationId,
User,
command
);
return Ok(result);
}

[HttpPost("compositeRecordsCommand")]
public async Task<ActionResult<RecordsAggregate?>> SubmitCompositeRecordsCommandAsync(Guid organizationId, Guid locationId,
[FromBody] CompositeRecordsCommand command)
public async Task<ActionResult<RecordsAggregate?>> SubmitCompositeRecordsCommandAsync(
Guid organizationId,
Guid locationId,
[FromBody] CompositeRecordsCommand command
)
{
var result = await recordsManager.ExecuteCompositeRecordsCommand(organizationId, locationId, User, command);
RecordsAggregate? result = await _RecordsManager.ExecuteCompositeRecordsCommand(
organizationId,
locationId,
User,
command
);
return Ok(result);
}
}
Expand Down
Loading
Loading