Skip to content

Commit

Permalink
Merge pull request #9 from davewalker5/DFL-11-Merge-DB-API-UIRepos
Browse files Browse the repository at this point in the history
DFL-11 Merge DB, API and UI Repos Into A Single Repo
  • Loading branch information
davewalker5 committed Dec 12, 2023
2 parents 416bb56 + b3cc33e commit 7778a59
Show file tree
Hide file tree
Showing 1,954 changed files with 245,917 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/DroneFlightLog.Mvc/wwwroot/* linguist-vendored=true
31 changes: 15 additions & 16 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.302'
include-prerelease: true
- name: Build
run: dotnet build --configuration Release src/DroneFlightLogDb.sln
- name: Run unit tests and generate code coverage
run: dotnet test src/DroneFlightLogDb.sln /p:CollectCoverage=true /p:CoverletOutput=coverage/ /p:CoverletOutputFormat=lcov
- name: Generage Coveralls code coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: src/DroneFlightLog.Data.Tests/coverage/coverage.info
- uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: "7.0.302"
include-prerelease: true
- name: Build
run: dotnet build --configuration Release src/DroneFlightLog.sln
- name: Run unit tests and generate code coverage
run: dotnet test src/DroneFlightLog.sln /p:CollectCoverage=true /p:CoverletOutput=coverage/ /p:CoverletOutputFormat=lcov
- name: Generage Coveralls code coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: src/DroneFlightLog.Data.Tests/coverage/coverage.info
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DroneFlightLogDb
# DroneFlightLog

[![Build Status](https://github.com/davewalker5/DroneFlightLogDb/workflows/.NET%20Core%20CI%20Build/badge.svg)](https://github.com/davewalker5/DroneFlightLogDb/actions)
[![GitHub issues](https://img.shields.io/github/issues/davewalker5/DroneFlightLogDb)](https://github.com/davewalker5/DroneFlightLogDb/issues)
Expand All @@ -13,23 +13,18 @@

DroneFlightLogDb implements the entities and business logic for a SQL-based drone flight logbook, providing facilities for recording and querying the following data:

* Operator details
* Drones, models and manufacturers
* Flights, flight locations and flight properties
- Operator details
- Drones, models and manufacturers
- Flights, flight locations and flight properties

## Getting Started

Please see the [Wiki](https://github.com/davewalker5/DroneFlightLogDb/wiki) for details on how to reference and use the Drone Flight Log business logic and how to get started with a database to hold the data.

## Authors

- **Dave Walker** - *Initial work* - [LinkedIn](https://www.linkedin.com/in/davewalker5/)
- **Dave Walker** - _Initial work_ - [LinkedIn](https://www.linkedin.com/in/davewalker5/)

## Feedback

To file issues or suggestions, please use the [Issues](https://github.com/davewalker5/DroneFlightLogDb/issues) page for this project on GitHub.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

# To file issues or suggestions, please use the [Issues](https://github.com/davewalker5/DroneFlightLogDb/issues) page for this project on GitHub.
4 changes: 4 additions & 0 deletions docker/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:latest
COPY droneflightlog.api-1.2.0.0 /opt/droneflightlog.api-1.2.0.0
WORKDIR /opt/droneflightlog.api-1.2.0.0/bin
ENTRYPOINT [ "./DroneFlightLog.Api" ]
97 changes: 97 additions & 0 deletions docker/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# droneflightlogapisqlite

The [DroneFlightLogDb](https://github.com/davewalker5/DroneFlightLogDb) and [DroneFlightLog.Api](https://github.com/davewalker5/DroneFlightLog.Api) GitHub projects implement the entities, business logic and a REST service for a SQL-based drone flight logbook, providing facilities for recording and querying the following data:

- Operator details
- Drones, models and manufacturers
- Flights, flight locations and flight properties

The droneflightlogapisqlite image contains a build of the logic and REST service for a SQLite database.

## Getting Started

### Prerequisities

In order to run this image you'll need docker installed.

- [Windows](https://docs.docker.com/windows/started)
- [OS X](https://docs.docker.com/mac/started/)
- [Linux](https://docs.docker.com/linux/started/)

### Usage

#### Container Parameters

The following "docker run" parameters are recommended when running the droneflightlogapisqlite image:

| Parameter | Value | Purpose |
| --------- | ------------------------------------------ | ------------------------------------------------------- |
| -d | - | Run as a background process |
| -v | /local:/var/opt/droneflightlog.api-1.0.0.4 | Mount the host folder containing the SQLite database |
| -p | 5001:80 | Expose the container's port 80 as port 5001 on the host |
| --rm | - | Remove the container automatically when it stops |

For example:

```shell
docker run -d -v /local:/var/opt/droneflightlog.api-1.0.0.4/ -p 5001:80 --rm davewalker5/droneflightlogapisqlite:latest
```

The "/local" path given to the -v argument is described, below, and should be replaced with a value appropriate for the host running the container. Similarly, the port number "5001" can be replaced with any available port on the host.

#### Volumes

The description of the container parameters, above, specifies that a folder containing the SQLite database file for the Drone Flight Log is mounted in the running container, using the "-v" parameter.

That folder should contain a SQLite database that has been created using the instructions in the [Drone Flight Log wiki](https://github.com/davewalker5/DroneFlightLogDb/wiki).

Specifically, the following should be done:

- [Create the SQLite database](https://github.com/davewalker5/DroneFlightLogDb/wiki/Using-a-SQLite-Database)
- [Add a user to the database](https://github.com/davewalker5/DroneFlightLogDb/wiki/REST-API)

The folder containing the "droneflightlog.db" file can then be passed to the "docker run" command using the "-v" parameter.

#### Running the Image

To run the image, enter the following command, substituting "/local" for the host folder containing the SQLite database, as described:

```shell
docker run -d -v /local:/var/opt/droneflightlog.api-1.0.0.4/ -p 5001:80 --rm davewalker5/droneflightlogapisqlite:latest
```

Once the container is running, browse to the following URL on the host:

http://localhost:5001

You should see the Swagger API documentation for the API.

## Built With

The droneflightlogapisqlite image was been built with the following:

| Aspect | Version |
| -------------- | ---------------------- |
| .NET Core CLI | 3.1.101 |
| Target Runtime | linux-x64 |
| Docker Desktop | 19.03.5, build 633a0ea |

## Find Us

- [DroneFlightLogDb on GitHub](https://github.com/davewalker5/DroneFlightLogDb)
- [DroneFlightLog.Api on GitHub](https://github.com/davewalker5/DroneFlightLog.Api)

## Versioning

For the versions available, see the [tags on this repository](https://github.com/davewalker5/DroneFlightLog.Api/tags).

## Authors

- **Dave Walker** - _Initial work_ - [LinkedIn](https://www.linkedin.com/in/davewalker5/)

See also the list of [contributors](https://github.com/davewalker5/DroneFlightLog.Api/contributors) who
participated in this project.

## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/davewalker5/DroneFlightLog.Api/blob/master/LICENSE) file for details.
4 changes: 4 additions & 0 deletions docker/ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:latest
COPY droneflightlog.mvc-1.1.0.0 /opt/droneflightlog.mvc-1.1.0.0
WORKDIR /opt/droneflightlog.mvc-1.1.0.0/bin
ENTRYPOINT [ "./DroneFlightLog.Mvc" ]
124 changes: 124 additions & 0 deletions docker/ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# droneflightlogmvc

The Drone Flight Log is a personal UAV flight logging application implemented using .NET Core. It has the following components:

| Name | GitHub | Comments |
| --- | --- | --- |
| DroneFlightLogDb | [DroneFlightLogDb](https://github.com/davewalker5/DroneFlightLogDb) | Business logic, entities and database implementation |
| DroneFlightLog.Api | [DroneFlightLog.Api](https://github.com/davewalker5/DroneFlightLog.Api) | REST API for reading and writing to the database |
| DroneFlightLog.Mvc | [DroneFlightLog.Mvc](https://github.com/davewalker5/DroneFlightLog.Mvc) | ASP.NET MVC UI for accessing the database via the service |

The application provides facilities for recording and querying the following data:

* Operator details
* Drones, models and manufacturers
* Flights, flight locations and flight properties

The droneflightlogmvc image contains a build of the web-based MVC user interface.

## Getting Started

### Prerequisities

In order to run this image you'll need docker installed.

* [Windows](https://docs.docker.com/windows/started)
* [OS X](https://docs.docker.com/mac/started/)
* [Linux](https://docs.docker.com/linux/started/)

### Usage

#### Service Container Parameters

An instance of the dronefilghtlogapisqlite image must be started first in order for the UI to work. The recommended parameters are:

| Parameter | Value | Purpose |
| --- | --- | --- |
| -d | - | Run as a background process
| -v | /local:/var/opt/droneflightlog.api-1.0.0.3 | Mount the host folder containing the SQLite database |
| --name | droneflightlogservice | Name the service so the UI can find it |
| --rm | - | Remove the container automatically when it stops |

The "/local" path given to the -v argument is described, below, and should be replaced with a value appropriate for the host running the container.

The "--name" parameter is mandatory as the service URL is held in the application settings for the UI image and is expected to be:

http://droneflightlogservice:80

#### UI Container Parameters

The following "docker run" parameters are recommended when running the droneflightlogmvc image:

| Parameter | Value | Purpose |
| --- | --- | --- |
| -d | - | Run as a background process
| -p | 5001:80 | Expose the container's port 80 as port 5001 on the host |
| --link | droneflightlogservice | Link to the drone flight log service container |
| --rm | - | Remove the container automatically when it stops |

For example:

```shell
docker run -d -p 5001:80 --rm --link droneflightlogservice davewalker5/droneflightlogmvc:latest
```

The port number "5001" can be replaced with any available port on the host.

#### Volumes

The description of the container parameters, above, specifies that a folder containing the SQLite database file for the Drone Flight Log is mounted in the running container, using the "-v" parameter.

That folder should contain a SQLite database that has been created using the instructions in the [Drone Flight Log wiki](https://github.com/davewalker5/DroneFlightLogDb/wiki).

Specifically, the following should be done:

- [Create the SQLite database](https://github.com/davewalker5/DroneFlightLogDb/wiki/Using-a-SQLite-Database)
- [Add a user to the database](https://github.com/davewalker5/DroneFlightLogDb/wiki/REST-API)

The folder containing the "droneflightlog.db" file can then be passed to the "docker run" command using the "-v" parameter.

#### Running the Image

To run the images for the service and UI, enter the following commands, substituting "/local" for the host folder containing the SQLite database, as described:

```shell
docker run -d -v /local:/var/opt/droneflightlog.api-1.0.0.3/ --name droneflightlogservice --rm davewalker5/droneflightlogapisqlite:latest
docker run -d -p 5001:80 --rm --link droneflightlogservice davewalker5/droneflightlogmvc:latest
```

Once the container is running, browse to the following URL on the host:

http://localhost:5001

You should see the login page for the UI.

## Built With

The droneflightlogmvc image was been built with the following:

| Aspect | Version |
| --- | --- |
| .NET Core CLI | 3.1.101 |
| Target Runtime | linux-x64 |
| Docker Desktop | 19.03.5, build 633a0ea |

## Find Us

* [DroneFlightLogDb on GitHub](https://github.com/davewalker5/DroneFlightLogDb)
* [DroneFlightLog.Api on GitHub](https://github.com/davewalker5/DroneFlightLog.Api)
* [DroneFlightLog.Mvc on GitHub](https://github.com/davewalker5/DroneFlightLog.Mvc)

## Versioning

For the versions available, see the [tags on this repository](https://github.com/davewalker5/DroneFlightLog.Mvc/tags).

## Authors

* **Dave Walker** - *Initial work* - [LinkedIn](https://www.linkedin.com/in/davewalker5/)

See also the list of [contributors](https://github.com/davewalker5/DroneFlightLog.Mvc/contributors) who
participated in this project.

## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/davewalker5/DroneFlightLog.Mvc/blob/master/LICENSE) file for details.
79 changes: 79 additions & 0 deletions src/DroneFlightLog.Api/Controllers/AddressesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Threading.Tasks;
using System.Web;
using DroneFlightLog.Data.Entities;
using DroneFlightLog.Data.Exceptions;
using DroneFlightLog.Data.Interfaces;
using DroneFlightLog.Data.Sqlite;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DroneFlightLog.Api.Controllers
{
[Authorize]
[ApiController]
[ApiConventionType(typeof(DefaultApiConventions))]
[Route("[controller]")]
public class AddressesController : Controller
{
private readonly IDroneFlightLogFactory<DroneFlightLogDbContext> _factory;

public AddressesController(IDroneFlightLogFactory<DroneFlightLogDbContext> factory)
{
_factory = factory;
}

[HttpGet]
[Route("{id}")]
public async Task<ActionResult<Address>> GetAddressAsync(int id)
{
Address address;

try
{
address = await _factory.Addresses.GetAddressAsync(id);
}
catch (AddressNotFoundException)
{
return NotFound();
}

return address;
}

[HttpGet]
[Route("{number}/{postcode}/{country}")]
public async Task<ActionResult<Address>> FindAddressAsync(string number, string postcode, string country)
{
string decodedNumber = HttpUtility.UrlDecode(number);
string decodedPostcode = HttpUtility.UrlDecode(postcode);
string decodedCountry = HttpUtility.UrlDecode(country);
Address address = await _factory.Addresses.FindAddressAsync(decodedNumber, decodedPostcode, decodedCountry);

if (address == null)
{
return NotFound();
}

return address;
}

[HttpPost]
[Route("")]
public async Task<ActionResult<Address>> CreateModelAsync([FromBody] Address template)
{
Address address;

try
{
address = await _factory.Addresses.AddAddressAsync(template.Number, template.Street, template.Town, template.County, template.Postcode, template.Country);
await _factory.Context.SaveChangesAsync();
}
catch (AddressExistsException)
{
return BadRequest();
}

return address;
}
}
}
Loading

0 comments on commit 7778a59

Please sign in to comment.