An open API service indexing awesome lists of open source software.

https://github.com/calesi19/task-tamer

A to do list api built with .NET and C#.
https://github.com/calesi19/task-tamer

csharp docker dotnet postgresql

Last synced: 3 months ago
JSON representation

A to do list api built with .NET and C#.

Awesome Lists containing this project

README

          

# Task Tamer

A simple to do list api to practice creating a .NET Web API. This Repo serves a reference guide for creating .NET APIs.

# How to run the project

## Setup the database.

1. Install Docker
2. Create a Docker account.
3. Run the following command to start a Postgres container.

```bash
docker run --name tasktamer -p 5432:5432 -e POSTGRES_PASSWORD=task123 -e POSTGRES_USER=tamer -e POSTGRES_DB=task_tamer -d postgres
```

## Setup the API
1. Clone the project
```bash
git clone https://github.com/Calesi19/FaveFinder.git
```

2. Install the dependencies
```bash
dotnet restore
```

3. Run the project
```bash
dotnet run
```

4. Open your browser and go to `http://localhost:5000`

# Create and Run a Docker Image

1. Create the image with the code by running the following command:
```bash
docker build -t tasktamer .
```
2. Run the docker image by running the command:
```bash
docker run -p 8080:8080 -p 8081:8081 tasktamer
```

# Packages

* Npgsql.EntityFrameworkCore.PostgreSQL
* Microsoft.EntityFrameworkCore
* Microsoft.EntityFrameworkCore.Design

# Managing Packages

You can install/remove a package by running the following commands:
```bash
# To install a package
dotnet add package

# To update a package
dotnet add package --version

# To remove a package
dotnet remove package
```

# Run Migrations

Make sure to have the dotnet-ef tool installed.

```bash
dotnet tool install --global dotnet-ef
```

Once a model has been created and added to the DataAccess class, run the following migration commands on the terminal to create the tables in the database.

```bash
dotnet ef migrations add
dotnet ef database update
```
Replace with a name you'd like to give your migration. Don't use spaces.

# Helpful Resources

* [Postgres Setup with .NET Entity Framework](https://www.youtube.com/watch?v=z7G6HV7WWz0)
* [.NET API Guide](https://www.youtube.com/playlist?list=PL82C6-O4XrHdiS10BLh23x71ve9mQCln0)

# Tutorial Guide

To create a .NET Web API, you need to have the .NET Core SDK installed on your machine.

You can run the following command to bootstrap a new .NET Web API project.
```bash
dotnet new webapi -n TaskTamer
```

To create a sln file, run the following command:
```bash
dotnet new sln -n something
```
To add a project to the solution, run the following command:
```bash
dotnet sln something.sln add something/something.csproj
```

# Testing
Swagger is a great tool to document your API and will come pre-installed with the project. To access the Swagger UI, run the project and go to `/swagger/index.html` page when you start your API.