GithubHelp home page GithubHelp logo

6fa16ef1cbb4ccbe1f9dfce6e1462429's Introduction

Email Sender Project

This service main functionality is to send email asynchronously using worker. The detail information about this service is listed below:

  • Language: PHP8.3
  • Dependency Management: composer
  • Database: PostgreSQL
  • Protocol: HTTP
  • Queue: Redis
  • Oauth2 Provider: Okta https://www.okta.com/

System Design

  1. Flow process flow design

  2. Docker design docker design

Database migration

Run Manual

Run .sql script manually one by one with ordering by prefix e.g 000001_, 000001_, etc

or

Using migrate CLI

  1. Installation source
    • WINDOWS:
      scoop install migrate
      
    • MAC:
      brew install golang-migrate
      
    • LINUX:
      $ curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey| apt-key add -
      $ echo "deb https://packagecloud.io/golang-migrate/migrate/ubuntu/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/migrate.list
      $ apt-get update
      $ apt-get install -y migrate
      
    please visit https://www.freecodecamp.org/news/database-migration-golang-migrate for detail instruction
  2. Add database config into .env file. Ensure following variables exist and don't forget to fill the value:
    DB_HOST=
    DB_PORT=
    DB_DATABASE=
    DB_USERNAME=
    DB_PASSWORD=
    
  3. Execute Migration
    • Up: make migrate-up
    • Down: make migrate-down

API Reference

Register

  POST /register
Parameter Type Description
email string Required. user email
password string Required. user password

Login

  POST /login
Parameter Type Description
email string Required. user email
password string Required. user password

Get token for testing

  GET /client

Get token for okta client

  GET /client-okta

Send email

  POST /email

header Authorization: Bearer {{access_token}}

Parameter Type Description
is_html boolean Optional. default value false
email_to string Required. Target email to whom the email will be sent
subject string Required. Email subject
body string Required. Email body that can be in HTML format by setting is_html to true

example

{
    "is_html": "true",
    "email_to": "[email protected]",
    "subject": "testing subject",
    "body": "<br>Hello World<br>"
}

How to run

Prerequisite

  1. Install docker alongside compose plugin https://docs.docker.com/compose/install/

Steps

  1. Create .env and fill it with correct value. Refer to .env.example
  2. Build image php:base-image
    docker build -t php:base-image .
  3. Run docker compose
    docker-compose up -d
  4. Execute database migration here
  5. Open client page in your browser to get bearer token 5.1 Visit http://localhost:8080/client for testing client, or 5.2 Visit http://localhost:8080/client-okta if using okta user
  6. Copy bearer token Bearer {{ token }}
  7. Execute this example curl in your Postman or terminal. Don't forget to change the token value with the one from step 6
    curl -L 'http://localhost:8080/email' \
    -H 'Authorization: Bearer {{ token }}' \
    -H 'Content-Type: application/json' \
    --data-raw '{
        "is_html": "true",
        "email_to": "[email protected]",
        "subject": "testing subject final",
        "body": "<br>Hello World! Nice to meet you<br>"
    }'

6fa16ef1cbb4ccbe1f9dfce6e1462429's People

Contributors

hafidzizzudin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.