Przeglądaj źródła

Added README file and seeding functionality

feature/fixing_load_messages_bug
Ermin Bronja 3 lat temu
rodzic
commit
6dd08446e2

+ 82
- 0
Backend/Diligent.WebAPI.Host/Program.cs Wyświetl plik

@@ -1,4 +1,8 @@
using Diligent.WebAPI.Business.Services;
using Diligent.WebAPI.Data.Entities;
using Diligent.WebAPI.Data.HelperModels;
using Diligent.WebAPI.Host.Hubs;
using Microsoft.AspNetCore.Identity;
using Serilog;
using Serilog.Formatting.Json;

@@ -10,6 +14,84 @@ Diligent.WebAPI.Host.Extensions.ApiConfiguration.ConfigureServices(collection);
builder.ConfigureValidationMiddleware();
var app = builder.Build();

using (var serviceScope = app.Services.CreateScope())
{
var roleManager = serviceScope.ServiceProvider.GetRequiredService<RoleManager<Roles>>();
var requestService = serviceScope.ServiceProvider.GetRequiredService<RequestService>();
var roomService = serviceScope.ServiceProvider.GetRequiredService<RoomService>();
var customerManager = serviceScope.ServiceProvider.GetRequiredService<UserManager<Customer>>();

if (!await roleManager.RoleExistsAsync("Support"))
{
await roleManager.CreateAsync(new Roles() { Name = "Support" });
}

if (!await roleManager.RoleExistsAsync("Customer"))
{
await roleManager.CreateAsync(new Roles() { Name = "Customer" });
}

if ((await roomService.GetRoomsAsync()).Count() == 0)
{
await roomService.CreateRoomAsync(new Room { Id = "61da70bbde07582b720e056d", Name = "Room1", Customers = new List<CustomerDTO>(), Messages = new List<Message>(), CreatedBy = "8a781b04-8d3a-4d65-98ab-77b832a6dd06" });
await roomService.CreateRoomAsync(new Room { Id = "61da61cbde07582b720e056d", Name = "Room2", Customers = new List<CustomerDTO>(), Messages = new List<Message>(), CreatedBy = "8a781b04-8d3a-4d65-98ab-77b832a6dd06" });
}

if ((await requestService.GetRequestsAsync()).Count() == 0)
{
await requestService.CreateRequestAsync(new Request { Id = "62fb60badc07582b720e056d", RoomId = "61da70bbde07582b720e056d", SenderId = "8a781b04-3d3a-4d65-98ab-77b532a6ad06", SenderUsername = "User2", RoomName = "Room1" });
await requestService.CreateRequestAsync(new Request { Id = "62fb31bbde12482b720e156f", RoomId = "61da70bbde07582b720e056d", SenderId = "8e781b04-8d4a-4d65-98ab-37b832a6da06", SenderUsername = "User3", RoomName = "Room2" });
}

if (await customerManager.FindByEmailAsync("user1@gmail.com") == null)
{
Customer customer = new()
{
Id = new Guid("8a781b04-8d3a-4d65-98ab-77b832a6dd06"),
FirstName = "User1",
LastName = "User1",
Email = "user1@gmail.com",
UserName = "user1"
};

await customerManager.CreateAsync(customer, "Nekasifra123!");

await customerManager.AddToRoleAsync(customer, "Support");
}

if (await customerManager.FindByEmailAsync("user2@gmail.com") == null)
{
Customer customer = new()
{
Id = new Guid("8a781b04-3d3a-4d65-98ab-77b532a6ad06"),
FirstName = "User2",
LastName = "User2",
Email = "user2@gmail.com",
UserName = "user2"
};

await customerManager.CreateAsync(customer, "Nekasifra123!");

await customerManager.AddToRoleAsync(customer, "Customer");
}

if (await customerManager.FindByEmailAsync("user3@gmail.com") == null)
{
Customer customer = new()
{
Id = new Guid("8e781b04-8d4a-4d65-98ab-37b832a6da06"),
FirstName = "User3",
LastName = "User3",
Email = "user3@gmail.com",
UserName = "user3"
};

await customerManager.CreateAsync(customer, "Nekasifra123!");

await customerManager.AddToRoleAsync(customer, "Customer");
}
}

app.UseCors("ClientPermission");

app.MapControllers();

+ 4
- 2
Backend/Diligent.WebAPI.Host/appsettings.json Wyświetl plik

@@ -1,7 +1,9 @@
{
"WebApiDB": {
"ConnectionString": "mongodb+srv://dzenis12:Nekasifra123@chat.hvh4y.mongodb.net/?retryWrites=true&w=majority",
"DatabaseName": "WebApiDB"
//"ConnectionString": "mongodb+srv://dzenis12:Nekasifra123@chat.hvh4y.mongodb.net/?retryWrites=true&w=majority",
//"DatabaseName": "WebApiDB"
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "SignalRAndReactChat"
},
"Logging": {
"LogLevel": {

+ 131
- 0
README.md Wyświetl plik

@@ -0,0 +1,131 @@
SignalR and React chat
======================

* * *

Welcome to our SignalR and React chat app. In next sections we will walk you through our project, setting it up on your computer, running tests and last but not the least walk you through tools that we used:

* Description
* Setup
* Testing

Description
-----------

* * *

This is an internal Chat app project that was done by Diligent. Our project is hosted on our local [git](https://git.dilig.net/stefan.stamenovic/WebAPISignalRChat)

#### Tech stack

* * *

Backend was done using ASP.NET Core 6. For database we used MongoDb, which is a NoSql database. Frontend was done using React with Redux Toolkit for state management

#### Development environment

* * *

* Visual Studio 2022 - Used as the primary code editor for backend development
* Visual Studio Code - Used as the primary code editor for frontend development
* Compass - GUI for MongoDb
* Postman
* Swagger
* git

Setup
-----

* * *

Here we will show you how to set up project and run it in localhost.

* Database setup
* Project setup
* Backend setup
* Frontend setup
* Database initialization

#### Database setup

* * *

Please follow the official tutorial on installing and running the latest Mongo database which can be found on this link:

>[https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/)

#### Project setup

* * *

In order to run our project, you need to clone it from git first. Open terminal (cmd and powershell work as well) in folder that you want this project to be and run command

```sh
git clone http://git.dilig.net/stefan.stamenovic/WebAPISignalRChat.git
```

#### Backend setup

* * *

To run backend run command:

```sh
dotnet run
```

**Congratulations!** You now ran backend api for chat app. You can see swagger documentation in the browser with the url

>[https://localhost:5116](http://localhost:5116)

#### Frontend setup

* * *

To run frontend first you have to install required packages, run command:

```sh
npm install
```

Then you have to start frontend locally, run command:

```sh
npm start
```

**Congratulations!** You now ran frontend for chat app. App url

>[https://localhost:3000](https://localhost:3000)

#### Database initialization

* * *

When you run backend first time, it will add some records in database which is required to test app. Database should be initialized with

* Users
* Roles
* Rooms
* Requests

Testing
-------

* * *

Here we will show you how to run tests and see code coverage

#### Run tests

* * *

To run tests, you have to select dropdown Test > Run All Test, or press shortcut Ctrl + R, A

#### Code Coverlet Setup

* * *

Please follow tutorial to setup and run code coverlet library which can be found on this link:

>[https://www.code4it.dev/blog/code-coverage-vs-2019-coverlet](https://www.code4it.dev/blog/code-coverage-vs-2019-coverlet)

Ładowanie…
Anuluj
Zapisz