Skip to content
TechGluePublic

About

Personal minimal API to track consistent habits

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

CheckMeInService

Welcome to the CheckIn Service API 🎉

Hey there! Welcome to the CheckIn API! This personal project serves as a sandbox for sharpening my skills with ASP.NET Core and new language features and technologies while solving a personal problem: tracking and counting consistency in habit-building.

What's under the hood?

This app is built using:

  • C#
  • .NET 8 (latest LTS)
  • Test Containers
  • Azure SQL
  • Azure

Want to run the API locally?

Prerequisites 🛠️

Installation Steps 🔧

Now fire up your terminal and run:

$ git clone https://github.com/TechGlue/CheckIn.git
$ cd CheckIn
$ cd CheckMeInService

Setting up infrastructure

  • Launch Azure
  • Create a new app registration in EntraId
  • Expose an API and create the two scopes subscribers and checkins
  • Create a new Azure SQL DB instance
  • Run CheckMeIn_InitTables_SP_01.sql in the new DB instance
  • Execute the stored procedure "Exec dbo.InitTables"
  • Fill in the EntraId and AzureSQL login fields in the appsettings.json
  • Support with EntraId config files

Running the API

$ dotnet restore 
$ dotnet run

Query the database using an API testing tool. I prefer Postman, as it is the most straightforward for fetching the OAuth2 bearer token and authorizing access to the API. Here's a tutorial that I found helpful for getting started with Postman and EntraId

Routes

/api/checkins/

  • unenroll (Removes user given a phone number/email from the checkins table)
    Parameters:
    • phoneNumber
  • logdaily (Creates a new checkin entry given a phone number/email.)
    Parameters:
    • phoneNumber

/api/subscribers/

  • addsubscription (Creates a new user and registers user.)
    Parameters:
    • firstName
    • lastName
    • phoneNumber
    • subscriptionName

Creating and using a local AzureSQL database

AzureSQL, being a cloud-based service, it can be a hassle creating cloud environments for development and testing. Luckily, they have a docker image that can be used to create a local instance of AzureSQL.

The project during development makes use of a local database. To start the local database, run the following command:

make run 

What's going on under the hood?

  • The command starts a local Azure SQL Server leveraging the SQL Edge Image
  • The initialization script dbInit.sh is going to look for an active database connection. If found it will create the database and tables by restoring from a bacpac file. If for whatever reason the database connection is not found, it will simply time out.

Configure the local database connection string in the appsettings.json file for the service:

{
    "AzureSQL": {
        "DataSource": "127.0.0.1,1433",
        "UserId": "SA",
        "Password": "StrongPassword!123",
        "InitialCatalog": "CheckInDB"
    }
}

Add your EntraId configuration and you're ready to go!

Stop and delete all currently active containers

(Note: if you have other containers running, this command will stop and delete them.)

To clean up the local database, run the following command:

make drop 

Misc.

Design and architecture

About

Personal minimal API to track consistent habits

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages