readme.md 2.8 KB
Newer Older
# Description of version 0.0.3

auto-generated ASP.NET server code

includes description and code for a fully functional server with MongoDB integration

Detlef Runde's avatar
Detlef Runde committed

# Prerequisites
1.	installed npm: https://phoenixnap.com/kb/install-node-js-npm-on-windows
2.	Installed openapi generator with npm: https://openapi-generator.tech/docs/installation/
3.	Installed docker (if you want to use it): https://www.docker.com/get-started 


# Generate or update the server

we provided the file `.openapi-generator-ignore` in `server`, which prevents openapi-generator to override some adapted files 

## auto-generate server code
open a command shell and execute
```
  openapi-generator-cli generate -i OpenAPI.yaml -g aspnetcore -o server
```

open the solution `Org.OpenAPITools.sln` (folder `server`) in Visual Studio

## In Visual Studio:
open `NuGet Package Manager` and add `MongoDB.Driver`

### File adaptations:
change version number in all files if a new version is provided

### - folder `Controllers`: 
change "`public class`" to "`public abstract class`"
compare files in "`ControllersImpl`" with the corresponding files in "`Controllers`" and adapt if necessary
methods should be the same with "`override`" instead of "`virtual`"

### - folder `Models`:
add: 
```
  using MongoDB.Bson;
  using MongoDB.Bson.Serialization.Attributes;
```

at the value that is to become the MongoDB ID, add:
```
  [BsonId]
  [BsonRepresentation(BsonType.String)]
```


# MongoDB
if you don't have a MongoDB, follow the instructions in `readme.txt` in `server/programs/MongoDB` 

and put MongoDB in folder `server/programs/MongoDB` (download MongoDB as zip-file from https://www.mongodb.com/try/download/community and unzip the file into this directory, so that the bin-directory is in this folder) 


# Use in Visual Studio
make sure, that an instance of MongoDB is running

start application with IIS Express


# Use in Docker
remove the substring `src/Org.OpenAPITools/` in Dockerfile (if not already done)

open a command shell and generate docker by executing in `server/src/Org.OpenAPITools`:
```
  docker build -t org.openapitools .
```

## to start:
Detlef Runde's avatar
Detlef Runde committed
the easiest way is to use docker-compose:

open a command shell and use docker-compose (if necessary adapt docker-compose.yml) by executing in `server/src/Org.OpenAPITools`:
```
  docker-compose up 
```

open http://localhost:8080/openapi/index.html in a web-browser, if you want to check the functionalities using SwaggerUI

## to stop:
open a command shell by executing in `server/src/Org.OpenAPITools`:
```
  docker-compose down
```

## to dump database 
execute the following command in docker:
``` 
  mongodump --db **insert database_name** --out /data-dump/`date +"%Y-%m-%d"`
```

## to import database:
execute the following command in docker:
```
  mongorestore --db **insert database_name** **insert path_to_bson_file**
```