mif-az / Ultra-Saver

0 stars 1 forks source link

Database


Setup

Requirements

How to launch

  1. Clone repo
  2. Go to the ClientApp folder
  3. Run
    npm install
  4. Come back to the main folder
  5. Run
    dotnet run

How to deal with secrets

To add a secret run where <SECRET> is the name of the secret and <VALUE> is the actual value

dotnet user-secrets set "<SECRET>" "<VALUE>"

If you want to check the secrets you've already set you can run

dotnet user-secrets list

CRUD and Auth API

There is a high chance you will need info from a backend API route that requires authorization - for that you will need to use Auth API.

  1. Import UserContext and Auth API from UserProvider: import { UserContext, authApi } from '../contexts/UserProvider';
  2. Get the global user state: const [user, setUser] = useContext(UserContext);
  3. Call any CRUD method you need:
    1. GET method: authApi(user).get(<url>)
    2. POST method (default behavior is upsert*) authApi(user).post(<url>, <body>) It is important that <body> matches the database model
    3. DELETE method authApi(user).post(<url>, <body>, "DELETE") only the unique identifier fields are enough to provide in <body>. These fields can vary but the usual one is "id"

*upsert: check if an entry with the unique identifier exists in the database -> if so, update with provided data; otherwise create a new entry in the database using provided data