Skip to content

Repository files navigation

Email Newsletter Rust

NOTE: Run the init_db.sh before building/running the project else there will be sqlx expand error

Command to install sqls-cli using cargo

cargo install --version=0.5.7 sqlx-cli --no-default-features --features postgres

Command to create a new script under migrations folder:

sqlx migrate add create_subscriptions_table

When you want to see all logs coming out of a certain test case to debug it you can run

# We are using the `bunyan` CLI to prettify the outputted logs
# The original `bunyan` requires NPM, but you can install a Rust-port with
# `cargo install bunyan`
TEST_LOG=true cargo test health_check_works | bunyan

It must be invoked as a cargo subcommand All options after -- are passed to cargo itself

We need to point it at our library since it contains all our SQL queries.

cargo sqlx prepare -- --lib

Build a docker image tagged as "email-newsletter-rust" according to the recipe specified in Dockerfile

docker build --tag email-newsletter-rust --file Dockerfile .

Run the docker image

docker run -p 9001:9001 email-newsletter-rust

Remove unused Docker objects (containers, images, volumes, etc.):

docker system prune -a --volumes

Get the size of our docker image:

docker image inspect email-newsletter-rust --format='{{.Size}}'

Combined command to build and run the docker image:

docker build --tag email-newsletter-rust --file Dockerfile . && docker run -p 9001:9001 email-newsletter-rust

Testing Commands

Health check:

curl http://localhost:9001/health_check

Subscribe to a newsletter:

curl --request POST \
--data 'name=le%20guin&email=ursula_le_guin%40gmail.com' \
http://localhost:9001/subscriptions --verbose

MailTrap API Demo Request:

{
  "from": {
    "email": "donotreply@ayush-tickoo.in",
    "name": "Mailtrap Test Mark 3"
  },
  "to": [
    {
      "email": "ronit.tickoo@gmail.com"
    }
  ],
  "subject": "Yo Meow Negga",
  "text": "This is a Testing Mail [Test Mail Mark 3]",
  "category": "Integration Test"
}

MailTrap API Demo Response:

{"success":true,"message_ids":["8b627ff0-52b2-11f0-0000-f1e8ba0efc25"]}

Migrations Script for subscriptions table:

sqlx migrate add add_status_to_subscriptions

Created Script for Non-nullable status column:

sqlx migrate add make_status_not_null_in_subscriptions

Script for creating subscription_tokens table:

sqlx migrate add create_subscription_tokens_table

Script for creating users table:

sqlx migrate add create_users_table

Create Script file for renaming password column generated using command:

sqlx migrate add rename_password_column

Create Script file for adding salt column

sqlx migrate add add_salt_to_users

Create script file for removing salt column

sqlx migrate add remove_salt_from_users

Mark the redis script as executable before running it:

chmod +x ./scripts/init_redis.sh

Script to initialize add seed user sql file:

sqlx migrate add seed_user

About

An email newsletter implemented using Rust using Actix web server

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages