This is a template project that utilizes a combination of tools and solutions such as ASP.NET Core, PostgreSQL & PgAdmin on the Docker. The idea of the project was to provide an easy to start base for a very basic project that can be expanded further. Here main components were meant to be a simple backend that has connection to a Database system that can be additionally managed. For simplicity, not requiring the user to install everything on their computer - the systems work on Docker containers.
Essentially this template has few of the following components created with it, to show how some operations can be utilized or modified for other purposes...
With this project, a database is initialized and stores 2 tables that depend one on another. One is a table with songs and the other with music genres. They are both generated through a seed.sql
file in the DBScripts folder that gets executed when a PostgreSQL Database is created with the docker-compose.yaml
file.
To allow for easier interactivity with the Database, a PgAdmin 4 tool is utilized. The tool gets initialized with the execution of the docker-compose.yaml
file and can be accessed by navigating through your browser as such: localhost:5432. To know what username, password and e-mail that you need to enter when starting the tool, please refer to the docker-compose.yaml
file, as it might be subject to change compare to what is written in this README.
A very basic web app has been created that has few endpoints with which you can interact, which themselves interact with the Database further. At the current stage in the Dockerfile file a line 6 has been added: ENV ASPNETCORE_ENVIRONMENT=Development
that also allows for the swagger UI to be present for an easier interactivity with the API end-points, while you experiment with it.
The idea naturally is that you could see how several queries with default and modifiable parameters are being sent by the application to the database and how information gets retrieved from it. This template should provide a good reference point if you would like to move further with creating of your own application or expanding it.
- GET METHODS:
- Available through: http://localhost:5000/Database
- Should return information on what kind of connection with PostgreSQL Database do you have. You should see the following with the current build:
PostgreSQL version: PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
- Should return information on what kind of connection with PostgreSQL Database do you have. You should see the following with the current build:
- Available through: http://localhost:5000/Music/random
- A request that will retrieve a random song from the database. The initialized database has initially only 4 songs in the music table. An example of a return you might get:
{"band": "Nirvana", "song": "Come as You Are", "style": "Grunge"}
- A request that will retrieve a random song from the database. The initialized database has initially only 4 songs in the music table. An example of a return you might get:
- Available through: http://localhost:5000/Database
- PUT METHOD:
- Available through: http://localhost:5000/Music/style/{bandname}/{songname}/{genretype}
- You can indicate a name of the band, name of a song and the genre that will be added to the database. There are not many user inputs sanitization steps that are implemented here for the simplicity sake. Only one that is present is one that checks whether the user's
genretype
entered value matches anything present in the database, or should the song provided by the user be categorizes asOther
, because of how the system is built so far. However, due to this, do not use this minimum examples in production as I'm pretty sure someone can literally drop your tables with a malicious SQL injection statement.
- You can indicate a name of the band, name of a song and the genre that will be added to the database. There are not many user inputs sanitization steps that are implemented here for the simplicity sake. Only one that is present is one that checks whether the user's
- Available through: http://localhost:5000/Music/style/{bandname}/{songname}/{genretype}
To see and try all the methods available yourself and via an easy interface, use the link at http://localhost:5000/swagger/index.html
- Make sure you have Git and Docker installed on your computer and Docker is running
- Clone the repository via
git clone https://github.com/Si-ja/.NET-Core-PostgreSQL-Docker-Template.git
- Navigate to the root of the repository
- Call
docker-compose.up
on one of the perfered methods. Deployment will get all the services started. Development will only start the database and the application itself will have to be ran manually through say an IDE. - For the Development version navigate to https://localhost:5000/. For the Deployment to http://localhost:5000/.
- Have fun
The links do only work on http
side. You can use the api as is on port 5000, and swagger uses the same one but has a different extension.
You will run into issues if you will want to run the backend service as a service with say dotnet watch run
. This is because the connection is created using an environmental variable and other type of connections are not implemented in the code.
- Add appsettings.json files for development and deployment environments
- Configurate docker-compose for development and deployment enviornments
- Fix the swagger interface and add ability to modify info on api routes
- Implement Interfaces to make the current system more decoupled