Code Monkey home page Code Monkey logo

subscription-app's Introduction

A Subscription Application

Table of Contents

The Question

Create a simple subscription platform (only RESTful APIs with MySQL) in which users can subscribe to a website (there can be multiple websites in the system). Whenever a new post is published on a particular website, all it's subscribers shall receive an email with the post title and description in it. (No authentication of any type is required).

Stepwise Implementation

  • Install laravel
  • Prerequisites
  • Configuring a database
  • Project Planning.
  • Links
  • Ending Thoughts.

Prerequisites

  • Assumed you have composer installed from https://getcomposer.org
  • Assumed you have node installed from https://nodejs.org (optional)
  • Assumed you are using a Visual Studios Code as your IDE. (optional)
  • Assumed you have PHP>=7.* installed in your system with the path of the executable in your $PATH variable.

Installing laravel

$ composer global require laravel/installer
$ laravel new your-app-name
$ cd your-app-name
$ composer update

If you use VS Code as your IDE, please continue with this command

$ code .

๐Ÿ’ก Please open an integrated terminal for your laravel artisan commands.

Configuring a database

By default, laravel & this project assumes you are using MySQL.

  • Driver: MySQL
  • Username: any_username
  • Password: any_password
  • Database: some_name

:alert: Please update the necessary credentials in the .env found in the project's root. If you do not find one, use the .env.local file to create one.

Project Documentation

Database Migrations

We have considered the following tables in the database:

  1. A table for multiple websites is websites.
  2. A table for posts on a website is posts.
  3. A table for list of subscriptions is mailing_list.
  4. A table for maintaining a email queue named jobs generated by php artisan queue:table.

API Routes

The following tables define routes to the different API's.

Please append /api to the routes

Websites Routes

Method Route Description
GET /websites Get all websites
POST /websites Add a new website
GET /websites/{id} Get details of a website
POST /websites/{id} Update all details of a website
PUT /websites/{id} Specific details of a website

Posts Routes

Method Route Description
GET /websites/{id}/posts Gets details of all posts of a website.
POST /websites/{id}/posts Add a new post to the website.
GET /websites/{id}/posts/{pid} Get details of a particular post of a website.
POST /websites/{id}/posts/{pid} Update all details of particular post of a website.
PUT /websites/{id}/posts/{pid} Update specific details of particular post of a website.

Mailing List (Subscription Route)

Method Route Description
POST /websites/{id}/subscribe Add a new subscriber to the website.
PUT /websites/{id}/subscribe Update name by email in query like [email protected]
DELETE /websites/{id}/subscriber Remove subscription from the specific website by email in query like [email protected]
GET /websites/{id}/subscriber Show the details of subscriber of a website by email in query like [email protected]

Implementing the models

Three models have been considered.

  1. A model for Website
  2. A model for Posts
  3. A model for Subscribers

Implementing the controllers...

The routes above, have their respective controllers bound by the Models.

  1. The WebsiteController, uses the Website Model to implement the routes defined for websites. The controller handles all functions of Create, Update, View/Read actions of a website.
  2. The PostController, uses the Posts Model to implement the routes defined for posts Create, Update, View/Read actions of a post.
  3. The MailingListController, uses the Subscriber Model to implement the routes defined for mailing-list/subscription. This controller is responsible for handling the mailing-list or subscription-table of a particular website.

Assigning an Observer & listing to the events.

A dedicated PostObserver is declared to observe for any new post created & dispatch a mailing job which is enqueued to the bottom of Queue.

The PostObserver is "booted" in the EventServiceProvider, defining that the Post Model is bound by this observer.

Notifying the User (Email)

Notifications are not perfectly handled. There was no attention given to the templating. Only a working implementation can be guaranteed.

  • To notify the subscriber about any new post (template by php artisan make:mail), NotifySubscriber is defined.
  • An asyncronous queue job (template generated by php artisan make:job) SendEmailJob handles the queue as well as finally invokes the "notifying" with the help of NotifySubscriber.

Links

Documentation:

The following links may be helpful:

  1. Laravel Docs - https://laravel.com/docs [At the time of writing the version of the docs was 9.x]
  2. PHP Docs - https://www.php.net/manual/
  3. Composer - https://getcomposer.org

API Implementation

If you want to run the api, you can use the button below:

Run in Postman

You can also use the JSON link to deploy on Postman.

Ending thoughts.

The front-end of this application will be a work-in progress. With this simple application, I have actually learnt a lot more than any other projects undertaken.

Thanks to Team Inisev....

Thank You & Regards,

@anrcry (Anweshan Roy Chowdury)

subscription-app's People

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.