Setup - medhatelmasry/GoodBooks GitHub Wiki

Original GitHub repo which was forked from:

https://github.com/AccountGo/accountgo

Technology overview

.NET 9.0

Backend: ASP.NET WebAPI

Frontend: MVC(Only For UI) or React with TypeScript

Database: SQL Server

Note: Blazor has been injected into the MVC app in case there is a desire to migrate certain pages to SPA.

It seems the development on this app stopped about seven years ago in the original repo. When Medhat looked at it, he figured that it has most of what is needed and could be useful by upgrading the application to the latest state of .NET and React. Therefore, he forked it and updated it to the latest versions of .NET, React, and TypeScript.

Clone and run solution

  1. Clone the repo:
    git clone https://github.com/medhatelmasry/GoodBooks.git
    
    cd GoodBooks/
    
  2. List branches with:
    git branch -r
    
  3. Select the appropriate branch with:
    git checkout -b my-branch
    

    Replace my-branch with the branch you want to change to. Choose the development branch named main. The following command creates a new branch called main (-b) that tracks the remote branch origin/main:

    git checkout -b main origin/main
    
  4. This command will confirm to you the current branch:
    git branch
    
  5. Start SQL Server in a docker container with:
    docker run --cap-add SYS_PTRACE -e ACCEPT_EULA=1 -e MSSQL_SA_PASSWORD=SqlPassword! -p 1444:1433 --name azsql -d mcr.microsoft.com/mssql/server:2022-latest
    
  6. In root directory of the code, run the following commands:
    dotnet restore
    dotnet build
    
  7. Delete the src/Api/Data/Migrations folder
  8. In root directory of the code, run the following commands:
    dotnet ef migrations add M1 --project ./src/Api/ --startup-project ./src/Api/Api.csproj --msbuildprojectextensionspath .build/obj/Api/ --context ApplicationIdentityDbContext --output-dir Data/Migrations/IdentityDb
    
    dotnet ef migrations add M2 --project ./src/Api/ --startup-project ./src/Api/Api.csproj --msbuildprojectextensionspath .build/obj/Api/ --context ApiDbContext --output-dir Data/Migrations/ApiDb
    
    dotnet ef database update --project ./src/Api/ --msbuildprojectextensionspath .build/obj/Api/ --context ApplicationIdentityDbContext
    
    dotnet ef database update --project ./src/Api/ --msbuildprojectextensionspath .build/obj/Api/ --context ApiDbContext
    
  9. Add the following to the appsettings.Development.json in the Api project:
    "JwtSettings": {
      "validIssuer": "Good Deed Books API",
      "validAudience": "http://localhost:8001",
      "expires": 60
    },
    "SECRET": {
      "key": "GoodDeedBooks1234GoodDeedBooks1234"
    }
    
  10. Go to the src/Api folder and start the WebAPI app with:
      dotnet watch
    
  11. Hit this endpoint in order to populate the database with some sample data: http://localhost:8001/api/administration/setup Project was updated to auto seed the database upon startup of the API project. It is no longer required to visit the /setup endpoint. Simply running dotnet watch will work. Thereafter, test endpoint http://localhost:8001/api/Financials/Accounts

    Expected Result when testing endpoint /api/Financials/Accounts

  12. Ensure the API app is running. In a separate terminal window, go to the src/AccountGoWeb and run the backend ASP.NET Core MVC app with the following command:

      dotnet watch
    

The use of React as a replacement for MVC.

  1. Update to the latest versions of

    node

    npm

  2. In a separate terminal window, go to the `src/GoodBooksReact` folder run these commands:
    npm install
    npm run dev
    

    The React app will run. It is a rudimentary frontend menu system and is a work in progress. As at September 2024, it was decided to postpone development of this react app in favor of using Blazor instead.

Production

Set the following database environment variables in production on API Azure site:

  • DBSERVER
  • DBUSERID
  • DBPASSWORD
  • DBNAME

The above values are replaced in Startup.cs in the Api project. The connection string is first read from appsettings.json and the appropriate values are then replaced with environment variables.

"ConnectionStrings": {
  "DefaultConnection": "Data Source={0};User ID={1};Password={2};Initial Catalog={3};TrustServerCertificate=yes;MultipleActiveResultSets=true;"
}
⚠️ **GitHub.com Fallback** ⚠️