Web client for this project is here: https://github.com/zorrokid/movies-collection-web-client
Build image with tag "movie-api":
$ docker build -f MovieAPI/Dockerfile -t movie-api .
To run in interactive terminal, run container with name "movie-api-container":
$ docker run -it -p 5001:80 --name movie-api-container movie-api
- .net 5
- Entity Framework Core 5
- Automapper
- MediatR: https://github.com/jbogard/MediatR
This is the main entry point of this backend project providing REST API for this application.
To set environment specific appsettings.json export environment variable first, e.g. to use appsettings.Development.json:
$ export ASPNETCORE_ENVIRONMENT=Development
Currently the database is PostgreSQL database.
Connection string is defined in MovieAPI-project's appsettings.json file.
Log in as postgres user:
$ sudo su postgres
Create db user:
$ createuser --interactive --pwprompt
Enter name of role to add: movies
Enter password for new role: xxxxxxx
Enter it again: xxxxxxx
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
Create db with previously created user as owner:
$ createdb --owner=movies moviedb
To login to db:
$ psql -Umovies -dmoviedb
To build the project run in the root folder
dotnet build
From the project root-folder run:
dotnet ef database update --startup-project ./MovieAPI/ --project ./Infrastructure/ --context IdentityContext
dotnet ef database update --startup-project ./MovieAPI/ --project ./Infrastructure/ --context ApplicationContext
Or use helper script
$ bash migate-db.sh
From the project root-folder run:
dotnet ef migrations add <migration name> --startup-project ./MovieAPI/ --project ./Infrastructure/ --context IdentityContext --output-dir=Migrations/Identity
From the repository root folder run:
dotnet ef migrations add <migration name> --startup-project ./MovieAPI/ --project ./Infrastructure/ --context ApplicationContext --output-dir=Migrations/Application
To remove last migration (from repository root folder)
dotnet ef migrations remove --context ApplicationContext --project ./Infrastructure --startup-project ./MovieAPI/
Reverting to certain migration (from the repository root folder):
dotnet ef database update 20210531183555_Initial --startup-project ./MovieAPI/ --project ./Infrastructure/ --context ApplicationContext
Reverting all migrations (from the repository root folder)
dotnet ef database update 0 --startup-project ./MovieAPI/ --project ./Infrastructure/ --context ApplicationContext
Or use helper script
bash clear-db.sh
Currently only a custom CSV-format is supported. Use CsvImport-project to import collection from CSV.
Run build
dotnet build
Run CsvImport to get help about command line options.
Example:
$ bin/Debug/net5.0/CsvImport -p data/Collections.csv -c /home/mikko/dev/dotnet/movies/MovieAPI/
To use development appsettings, set environment before running CsvImport:
$ export ASPNETCORE_ENVIRONMENT=Development
To launch API go to MoviesAPI-project folder and run
dotnet run
Swagger is started in following address: https://localhost:5001/swagger/index.html
Create project folder inside root folder of repository.
In project folder run
dotnet new <project template name>
e.g. to create a test project
dotnet new mstest
To add project to solution in root folder run:
dotnet sln add <Project name>/<Project name>.csproj
$ dotnet add CsvImport/CsvImport.csproj reference Application/Application.csproj
To run tests, in root folder run
dotnet test
Links:
- https://github.com/FiloSottile/mkcert
- https://blog.bitsrc.io/using-https-for-local-development-for-react-angular-and-node-fdfaf69693cd
$ mkcert -install
Created a new local CA 💥
Sudo password:
The local CA is now installed in the system trust store! ⚡️
The local CA is now installed in the Firefox and/or Chrome/Chromium trust store (requires browser restart)! 🦊
$ mkcert -CAROOT
/home/mikko/.local/share/mkcert
~/.local/share/mkcert$ mkcert localhost
Created a new certificate valid for the following names 📜
- "localhost"
The certificate is at "./localhost.pem" and the key at "./localhost-key.pem" ✅
It will expire on 12 September 2023 🗓
devServer: {
contentBase: './dist',
hot: true,
https: {
key: fs.readFileSync('/home/mikko/.local/share/mkcert/localhost-key.pem'),
cert: fs.readFileSync('/home/mikko/.local/share/mkcert/localhost.pem'),
ca: fs.readFileSync('/home/mikko/.local/share/mkcert/rootCA.pem'),
},
},
~/.local/share/mkcert$ mkcert -uninstall
Sudo password:
The local CA is now uninstalled from the system trust store(s)! 👋
mikko@mikko-Strix-15-GL503GE:~/dev/dotnet/movies/MovieAPI$ dotnet dev-certs https -t Trusting the HTTPS development certificate was requested. Trusting the certificate on Linux distributions automatically is not supported. For instructions on how to manually trust the certificate on your Linux distribution, go to https://aka.ms/dev-certs-trust A valid HTTPS certificate is already present.