Skip to content

(#333) events service udpate #371

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

Merged
merged 129 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
69da7d1
(#342) docs: update repo description
SaintAngeLs Aug 4, 2024
4dd3a18
(#342) organizations: core organizations repostiroy interface udpatre
SaintAngeLs Aug 4, 2024
a0e3f76
(#342) organizatrions: update organizations dto for suborganizations
SaintAngeLs Aug 4, 2024
5d92373
(#342) organizations: update api for udpated query dto
SaintAngeLs Aug 4, 2024
5ab930a
(#342) organizations: udpate repository organizations implementation,…
SaintAngeLs Aug 4, 2024
ee60ae5
(#342) web: add organizations tree views
SaintAngeLs Aug 4, 2024
4820560
(#342) web: add organisation back list navigation
SaintAngeLs Aug 4, 2024
d0ef806
(#342) organizations: udpate api to get paginated organisations
SaintAngeLs Aug 4, 2024
8b80bb6
(#342) organizatrions: garinated result implementation
SaintAngeLs Aug 4, 2024
013b176
(#342) organizations: add getPaginatedResults implemenation
SaintAngeLs Aug 4, 2024
94bd6ea
(#342) organizations: udpate api gateway
SaintAngeLs Aug 4, 2024
99d016c
(#342) organizations: update repository interface
SaintAngeLs Aug 4, 2024
3150750
(#342) organizations: implementing the filtering organizations/suborg…
SaintAngeLs Aug 4, 2024
63eaa7c
(#342) organizations: update core repository interface
SaintAngeLs Aug 4, 2024
5004376
(#342) web: add organizations search
SaintAngeLs Aug 4, 2024
4c2ea10
(#342) web: add organizations search
SaintAngeLs Aug 4, 2024
d70e2de
Merge pull request #352 from SaintAngeLs/organizations_service
SaintAngeLs Aug 4, 2024
8d8acac
(#365) organizations: update core organization class
SaintAngeLs Aug 5, 2024
e099308
(#342) organizations: update create and update organization
SaintAngeLs Aug 5, 2024
eeb5666
(#342) organizations: update organizations dtos
SaintAngeLs Aug 5, 2024
629df16
(#342) organizztions: update imfrastructure extensions
SaintAngeLs Aug 5, 2024
5132a28
(#342) organizations: update create organization handler to set defau…
SaintAngeLs Aug 5, 2024
d34d586
(#342) organizztions: update organization repository to find organiza…
SaintAngeLs Aug 5, 2024
d081820
(#342) web: add technikal fields to udpate organization
SaintAngeLs Aug 5, 2024
1bb3cd5
(#342) organization: add protobuf
SaintAngeLs Aug 5, 2024
5351d2d
(#342) organizations: add grpc tools required
SaintAngeLs Aug 5, 2024
79876da
(#333) events: udpate teh events address object
SaintAngeLs Aug 5, 2024
c0cddbe
(#333) events: core evnet class and core evnet settings
SaintAngeLs Aug 5, 2024
1d554c8
(#333) events: udpate core events settings
SaintAngeLs Aug 5, 2024
d77c86a
(#333) events: update create event comand and create command handler
SaintAngeLs Aug 6, 2024
711efd8
(#333) events: update command and command handlers
SaintAngeLs Aug 6, 2024
e95f8cb
(#333) mediafiles: remove reduns files, modify core for the events co…
SaintAngeLs Aug 6, 2024
30f3d34
(#333) mediafiles: remove external events from inftrastructure
SaintAngeLs Aug 6, 2024
0f83769
(#333) mediafiles: add outbox evnets
SaintAngeLs Aug 6, 2024
da9ed31
(#333) events: update external event handler
SaintAngeLs Aug 6, 2024
f52c69d
(#333) mediafiles: update context type
SaintAngeLs Aug 6, 2024
d73fc9b
(#333) events: update core evnet
SaintAngeLs Aug 6, 2024
8be628e
(#333) events: remove studnets repository
SaintAngeLs Aug 6, 2024
b7bb9a1
(#333) event: remove studnet repository
SaintAngeLs Aug 6, 2024
4492b5d
(#333) events: update core
SaintAngeLs Aug 6, 2024
281319a
(#333) event: update commands, dtos
SaintAngeLs Aug 6, 2024
046eac9
(#333) event: update applications dtos
SaintAngeLs Aug 6, 2024
330b8bd
(#333) event: update applications dtos
SaintAngeLs Aug 6, 2024
286a717
(#333) events: update infrastructure documents, mongo extenstion and…
SaintAngeLs Aug 6, 2024
8ae90ea
(#333) events: add ocelot service
SaintAngeLs Aug 7, 2024
18f2898
(#333) ocelot udpate program
SaintAngeLs Aug 7, 2024
40d6be2
(#333) event: update application create event command
SaintAngeLs Aug 7, 2024
5d61c70
(#333) event: add logging middleware
SaintAngeLs Aug 7, 2024
b030ebe
(#333) event: update infrastructure validators
SaintAngeLs Aug 7, 2024
2fc8d10
(#333) event: update web application to remove events radzen component
SaintAngeLs Aug 7, 2024
6aa023d
(#333) event: add time line component
SaintAngeLs Aug 8, 2024
ee4351b
(#368) mediafiles: new endpoint for any file upload, update mediafile…
SaintAngeLs Aug 8, 2024
f78d368
(#368) mediafiles: update corresponsing endpoint in apigateway
SaintAngeLs Aug 8, 2024
c627519
(#368) mediafiles: update the newly added method to uplad files to te…
SaintAngeLs Aug 8, 2024
d39aaf7
(#368) web: organize events update view
SaintAngeLs Aug 8, 2024
e4bc615
(#368) ocelot: udpate routes
SaintAngeLs Aug 8, 2024
24b3048
(#333) events: add get evetns paginateg qury
SaintAngeLs Aug 8, 2024
f30a784
(#368) evetns: add the GetPaginatedEvents Query handler
SaintAngeLs Aug 8, 2024
9781e0e
(#333) events: add getPaginatedEvents query
SaintAngeLs Aug 8, 2024
c9190a9
(#333) events: update api implementation
SaintAngeLs Aug 8, 2024
9972c62
(#333) events: update events ntrada configuration
SaintAngeLs Aug 8, 2024
ca1b706
(#368) evetns: update getPaginatedEventsHandler to operater of Reposi…
SaintAngeLs Aug 9, 2024
89e16d0
(#333) events: get events by organizer -- all the events user id orga…
SaintAngeLs Aug 9, 2024
fad2b55
(#333) events: update api
SaintAngeLs Aug 9, 2024
3c4668e
(#368) mediafiles: update apigateway endpoint
SaintAngeLs Aug 9, 2024
fd981c5
(#368) events:add search events razor component
SaintAngeLs Aug 9, 2024
54c5752
(#333) events: udpate api
SaintAngeLs Aug 9, 2024
51f9989
(#368) mediafiles: remove post search command endpoint
SaintAngeLs Aug 9, 2024
8e5120d
(#333) web: update events service search events method
SaintAngeLs Aug 10, 2024
8c0b81c
(#333) web: update events servive method payloads
SaintAngeLs Aug 10, 2024
94444b5
(#333) event core: update AddParticipant method ro rremove exception …
SaintAngeLs Aug 10, 2024
5fe1086
(#333) web: update search query, update all events razor page
SaintAngeLs Aug 10, 2024
2d66bd9
(#333) web: update events pages, add events details page
SaintAngeLs Aug 10, 2024
9e7f425
(#333) events: udpate apigeteway
SaintAngeLs Aug 10, 2024
01c78d6
(#333) events: udpate PagedResult total pages
SaintAngeLs Aug 10, 2024
9cb09be
(#333) events: update orgnization users numer dispaly, pagniation but…
SaintAngeLs Aug 11, 2024
3f63127
(#333) organization: update api
SaintAngeLs Aug 11, 2024
cf3777c
(#333) organizations: udpate organization queries organizationDto
SaintAngeLs Aug 11, 2024
73db4d1
(#333) organizations: update organizations query handlers
SaintAngeLs Aug 11, 2024
776d93d
(#369) organization: update core organiztions to add corea organizati…
SaintAngeLs Aug 11, 2024
7c1108b
(#369) organization: update core organiztions requests domain objects
SaintAngeLs Aug 11, 2024
d35430c
(#333) organizations: update infrastructure
SaintAngeLs Aug 11, 2024
2a233a8
(#369) organizations: update organization requests repozitory
SaintAngeLs Aug 11, 2024
e297998
(#369) organizations: add the commands and commands handlers for foll…
SaintAngeLs Aug 11, 2024
0c11e4e
(#369) organization: update core organization request and organizatio…
SaintAngeLs Aug 11, 2024
a5b9db0
(#333) organization: update api for the organization following
SaintAngeLs Aug 11, 2024
d2bf2e0
(#369) organizations: add the commands and commands handlers for requ…
SaintAngeLs Aug 11, 2024
8e11a47
(#369) organization: update api
SaintAngeLs Aug 11, 2024
7498827
(#369) organization: update follo organization command handler
SaintAngeLs Aug 11, 2024
d88517e
(#369) organization: update accept request hcommand handler
SaintAngeLs Aug 11, 2024
f6975a8
(#369) organization: update infrastructure extensions
SaintAngeLs Aug 11, 2024
8fda900
(#369) organization: command subscribe
SaintAngeLs Aug 11, 2024
1915be0
(#369) organization: add updated commands to api gateway
SaintAngeLs Aug 11, 2024
f2b388d
(#369) organization: update commands payloads
SaintAngeLs Aug 11, 2024
275c1c4
(#369) web: update organization service
SaintAngeLs Aug 11, 2024
6e94cda
(#369) organization: udpate inftrastructure to add the leave organiza…
SaintAngeLs Aug 11, 2024
daf1d85
(#369) organization: add leve organization command and command handlers
SaintAngeLs Aug 11, 2024
c1cd995
(#333) organization: update api
SaintAngeLs Aug 11, 2024
3548d42
(#333) organization: update api gateway to add the leve organization …
SaintAngeLs Aug 11, 2024
8aa8278
(#369) organization: add core user organizations objects
SaintAngeLs Aug 11, 2024
049926c
(#369) organization: add core user organizations objects
SaintAngeLs Aug 11, 2024
1e4097a
(#369) organization: add user organizations docuement and update mong…
SaintAngeLs Aug 11, 2024
7d11467
(#369) organization: add userOrganization repository implementation
SaintAngeLs Aug 11, 2024
284e506
(#369) organization: update extensions
SaintAngeLs Aug 11, 2024
b6ba6ad
(#369) organization: update organization application commands handler…
SaintAngeLs Aug 11, 2024
2ab3a23
(#369) organization: addd getUsersOrganizations query handler
SaintAngeLs Aug 11, 2024
83bc522
(#369) organization: udpate query handler
SaintAngeLs Aug 11, 2024
9ef6304
(#333) organization: update api, add new qquery
SaintAngeLs Aug 11, 2024
3f6e132
(#369) organization: add new qury interface to get organizations foll…
SaintAngeLs Aug 11, 2024
0732848
(#369) organization: udpate apigateway for the new qury
SaintAngeLs Aug 11, 2024
f3a9a71
(#369) web: add GetUserFollowedOrganizationsAsync to organiztion serv…
SaintAngeLs Aug 11, 2024
98c615e
(#369) events: update get user events qury api
SaintAngeLs Aug 12, 2024
c8e029e
(#369) events: update get user events
SaintAngeLs Aug 12, 2024
84c18ab
(#369) events: udpate get user events query handler
SaintAngeLs Aug 12, 2024
2a2df67
(#369) events: update get user events
SaintAngeLs Aug 12, 2024
54514b1
(#369) events: udpate getUserEvents handlet to regulate the numer of …
SaintAngeLs Aug 12, 2024
18d7e13
(#369) web: udpate followindw events page, interested in the evnes page
SaintAngeLs Aug 12, 2024
20e4541
(#369) web: main layout update link
SaintAngeLs Aug 12, 2024
49d2da1
(#369) reactions: update reactions mongo document
SaintAngeLs Aug 12, 2024
799b21c
(#369) reactions: update reactions mongo document
SaintAngeLs Aug 12, 2024
d2a15c1
(#369) reactions: update reactictions dtos
SaintAngeLs Aug 12, 2024
f5b07b3
(#369) web: udpate events following
SaintAngeLs Aug 12, 2024
c073db2
(#369) events: update studnets service available settings
SaintAngeLs Aug 12, 2024
d95cd1a
(#369) students: update dtos and commands
SaintAngeLs Aug 12, 2024
a2f5018
(#369) studnets: update infrastrucutre persistance
SaintAngeLs Aug 12, 2024
7a46dff
(#369) studnets: update user settings mongo repository
SaintAngeLs Aug 12, 2024
32c518a
(#369) events: update studnet update settings command handlers
SaintAngeLs Aug 12, 2024
9f9351a
(#369) web: update studnets settings update view
SaintAngeLs Aug 12, 2024
05fe5c8
(#369) fix: conflicts resolve
SaintAngeLs Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions MiniSpace.APIGateway.Ocelot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app

COPY . .

RUN dotnet publish src/MiniSpace.APIGateway.Ocelot -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app

COPY --from=build /app/out .

ENV ASPNETCORE_URLS=http://*:80
ENV ASPNETCORE_ENVIRONMENT=docker
ENV NTRADA_CONFIG=ntrada.docker

ENTRYPOINT ["dotnet", "MiniSpace.APIGateway.Ocelot.dll"]
89 changes: 89 additions & 0 deletions MiniSpace.APIGateway.Ocelot/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

## TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

### 1. Definitions.

"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.

"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or Object form, that is made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.

### 2. Grant of Copyright License.

Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.

### 3. Grant of Patent License.

Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.

### 4. Redistribution.

You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:

(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

You may add Your own copyright notices to Your version of this material, provided that such additional copyright notices are not considered to be modifications of the License.

### 5. Submission of Contributions.

Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.

### 6. Trademarks.

This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.

### 7. Disclaimer of Warranty.

Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.

### 8. Limitation of Liability.

In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.

### 9. Accepting Warranty or Additional Liability.

While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, protection, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

## END OF TERMS AND CONDITIONS

### Appendix: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be placed in the LICENSE file in the root directory of your source code (if not already present):

Copyright 2024 distributed_minispace_team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
1 change: 1 addition & 0 deletions MiniSpace.APIGateway.Ocelot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# MiniSpace ApiGateway for the microinfrastructure
2 changes: 2 additions & 0 deletions MiniSpace.APIGateway.Ocelot/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
dotnet build -c release
11 changes: 11 additions & 0 deletions MiniSpace.APIGateway.Ocelot/scripts/dockerize-tag-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

export ASPNETCORE_ENVIRONMENT=docker

cd ..

docker build -t minispace.apigateway:latest .

docker tag minispace.apigateway:latest adrianvsaint/minispace.apigateway:latest

docker push adrianvsaint/minispace.apigateway:latest
21 changes: 21 additions & 0 deletions MiniSpace.APIGateway.Ocelot/scripts/dockerize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
TAG=''
VERSION_TAG=

case "$TRAVIS_BRANCH" in
"master")
TAG=latest
VERSION_TAG=$TRAVIS_BUILD_NUMBER
;;
"develop")
TAG=dev
VERSION_TAG=$TAG-$TRAVIS_BUILD_NUMBER
;;
esac

REPOSITORY=$DOCKER_USERNAME/minispace.apigateway

docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker build -t $REPOSITORY:$TAG -t $REPOSITORY:$VERSION_TAG .
docker push $REPOSITORY:$TAG
docker push $REPOSITORY:$VERSION_TAG
5 changes: 5 additions & 0 deletions MiniSpace.APIGateway.Ocelot/scripts/start-async.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
export ASPNETCORE_ENVIRONMENT=local
export NTRADA_CONFIG=ntrada-async
cd src/MiniSpace.APIGateway
dotnet run
4 changes: 4 additions & 0 deletions MiniSpace.APIGateway.Ocelot/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
export ASPNETCORE_ENVIRONMENT=local
cd ../src/MiniSpace.APIGateway
dotnet run
2 changes: 2 additions & 0 deletions MiniSpace.APIGateway.Ocelot/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
dotnet test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appsettings.local.json
appsettings.docker.json
appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MiniSpace.APIGateway.Ocelot.Infrastructure
{
public class AnonymousRouteOptions
{
public IEnumerable<string> Routes { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Options;

namespace MiniSpace.APIGateway.Ocelot.Infrastructure
{
internal sealed class AnonymousRouteValidator : IAnonymousRouteValidator
{
private readonly HashSet<string> _routes;

public AnonymousRouteValidator(IOptions<AnonymousRouteOptions> options)
{
_routes = new HashSet<string>(options.Value.Routes ?? Enumerable.Empty<string>());
}

public bool HasAccess(string path) => _routes.Contains(path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;

namespace MiniSpace.APIGateway.Ocelot
{
internal static class ApplicationBuilderExtensions
{
private const string OperationHeader = "X-Operation";
private const string ResourceIdKey = "resource-id";
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};

public static void SetResourceId(this JObject jObject, string id)
{
var idProperty = jObject.Property("id", StringComparison.InvariantCultureIgnoreCase);
if (idProperty is null)
{
jObject.Add("id", id);
return;
}

idProperty.Value = id;
}

public static void SetResourceIdFoRequest(this HttpContext context, string id)
=> context.Items.TryAdd(ResourceIdKey, id);

public static string GetResourceIdFoRequest(this HttpContext context)
=> context.Items.TryGetValue(ResourceIdKey, out var id) ? id as string : string.Empty;

public static void SetOperationHeader(this HttpResponse response, string id)
=> response.Headers[OperationHeader] = $"operations/{id}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Convey.MessageBrokers.RabbitMQ;
using Convey.MessageBrokers.RabbitMQ.Conventions;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using OpenTracing;


namespace MiniSpace.APIGateway.Ocelot.Infrastructure
{
internal sealed class AsyncRoutesMiddleware : IMiddleware
{
private static readonly ConcurrentDictionary<string, IConventions> Conventions =
new ConcurrentDictionary<string, IConventions>();

private readonly IRabbitMqClient _rabbitMqClient;
private readonly IPayloadBuilder _payloadBuilder;
private readonly ITracer _tracer;
private readonly ICorrelationContextBuilder _correlationContextBuilder;
private readonly IAnonymousRouteValidator _anonymousRouteValidator;
private readonly IDictionary<string, RouteOptions> _routes;
private readonly bool _authenticate;

public AsyncRoutesMiddleware(IRabbitMqClient rabbitMqClient, IPayloadBuilder payloadBuilder, ITracer tracer,
ICorrelationContextBuilder correlationContextBuilder, IAnonymousRouteValidator anonymousRouteValidator,
IOptions<AsyncRoutesOptions> asyncRoutesOptions)
{
_rabbitMqClient = rabbitMqClient;
_payloadBuilder = payloadBuilder;
_tracer = tracer;
_correlationContextBuilder = correlationContextBuilder;
_anonymousRouteValidator = anonymousRouteValidator;
_routes = asyncRoutesOptions.Value.Routes;
_authenticate = asyncRoutesOptions.Value.Authenticate == true;
}

public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (_routes is null || !_routes.Any())
{
await next(context);
return;
}

var key = GetKey(context);
if (!_routes.TryGetValue(key, out var route))
{
await next(context);
return;
}

if ((_authenticate && route.Authenticate != false || route.Authenticate == true) &&
!_anonymousRouteValidator.HasAccess(context.Request.Path))
{
var authenticateResult = await context.AuthenticateAsync();
if (!authenticateResult.Succeeded)
{
context.Response.StatusCode = 401;
return;
}

context.User = authenticateResult.Principal;
}

if (!Conventions.TryGetValue(key, out var conventions))
{
conventions = new MessageConventions(typeof(object), route.RoutingKey, route.Exchange, null);
Conventions.TryAdd(key, conventions);
}

var spanContext = _tracer.ActiveSpan?.Context.ToString() ?? string.Empty;

var message = await _payloadBuilder.BuildFromJsonAsync<object>(context.Request);
var resourceId = Guid.NewGuid().ToString("N");
if (context.Request.Method == "POST" && message is JObject jObject)
{
jObject.SetResourceId(resourceId);
}

var messageId = Guid.NewGuid().ToString("N");
var correlationId = Guid.NewGuid().ToString("N");
var correlationContext = _correlationContextBuilder.Build(context, correlationId, spanContext,
route.RoutingKey, resourceId);
_rabbitMqClient.Send(message, conventions, messageId, correlationId, spanContext, correlationContext);
context.Response.StatusCode = 202;
context.Response.SetOperationHeader(correlationId);
}

private static string GetKey(HttpContext context) => $"{context.Request.Method} {context.Request.Path}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace MiniSpace.APIGateway.Ocelot.Infrastructure
{
internal sealed class AsyncRoutesOptions
{
public bool? Authenticate { get; set; }
public string Exchange { get; set; }
public string RoutingKey { get; set; }
public Dictionary<string, RouteOptions> Routes { get; set; }
}

public class RouteOptions
{
public string RoutingKey { get; set; }
public string Exchange { get; set; }
public bool? Authenticate { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;

namespace MiniSpace.APIGateway.Ocelot.Infrastructure
{
internal class CorrelationContext
{
public string CorrelationId { get; set; }
public string SpanContext { get; set; }
public UserContext User { get; set; }
public string ResourceId { get; set; }
public string TraceId { get; set; }
public string ConnectionId { get; set; }
public string Name { get; set; }
public DateTime CreatedAt { get; set; }

public class UserContext
{
public string Id { get; set; }
public bool IsAuthenticated { get; set; }
public string Role { get; set; }
public IDictionary<string, string> Claims { get; set; }
}
}
}
Loading
Loading