From d5949c063f2b709d64624e2021a1a76f1c2ca1d0 Mon Sep 17 00:00:00 2001 From: rt00492 <rt00492@surrey.ac.uk> Date: Mon, 25 Apr 2022 23:29:13 +0100 Subject: [PATCH] Adding email microservice docker image, and implementing reminder helper method --- README.md | 12 ++++++++++++ app/controllers/application_controller.rb | 11 +++++++++++ app/controllers/home_controller.rb | 7 +++++++ app/views/home/home.html.erb | 1 + config/routes.rb | 1 + docker-compose.yaml | 6 ++++-- 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b2816d..33090e9 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,18 @@ log_out is a method that sends a delete http request containing the JWT token of session[:logged_in] is set to false by this method +## Mailer Microservice + +The Mailer Microservice is run inside a docker container that is booted up by using [this](#creating-the-image) command. + +### Helper Methods + +There are a few Helper Methods that in the ApplicationController.rb file, which means the methods are available to any controller that inherits from ApplicationController (i.e most controllers). + +#### reminder_email + +reminder_email(emails, reminder) is a method that takes two inputs, emails and reminder, emails is a list of emails that the reminder needs to be sent to, and the reminder input is a reminder object (currently no model exists, need to implement when reminders are added to the database). + ## Adding to the readme When editing use this as a guide: https://guides.github.com/features/mastering-markdown/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3481e2b..1fefd03 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -65,4 +65,15 @@ class ApplicationController < ActionController::Base redirect_to root_path end + def reminder_email(emails, reminder) + email = HTTParty.post('http://172.17.0.1:3002/reminder', :body => { + :emails => emails, + :event => { + :title => reminder["title"], + :description => reminder["description"] + } + }) + redirect_to root_path + end + end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index bed6ba7..17d45a6 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -28,6 +28,13 @@ class HomeController < ApplicationController def test_auth auth end + + def reminder_email_test + email = ["rtreadwaynest@gmail.com", "ross@alantreadway.net"] + reminder = {"title" => "this is a test", "description" => "this is a test description"} + reminder_email(email, reminder) + end + end \ No newline at end of file diff --git a/app/views/home/home.html.erb b/app/views/home/home.html.erb index ddc973b..7472d19 100644 --- a/app/views/home/home.html.erb +++ b/app/views/home/home.html.erb @@ -12,6 +12,7 @@ <body> <%= yield %> + <%= link_to "Reminder", home_reminder_email_test_path, class: 'btn btn-warning btn-md' %> <% if session[:logged_in] %> <%= link_to "Logout", home_test_log_out_path, class: 'btn btn-warning btn-md' %> <% else %> diff --git a/config/routes.rb b/config/routes.rb index 42f6302..bf204c3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,5 +16,6 @@ Rails.application.routes.draw do post 'sign_up/send', to: 'registrations#sign_up' get 'login', to: 'sessions#new' post 'login/send', to: 'sessions#login' + get 'home/reminder_email_test', to: 'home#reminder_email_test' end diff --git a/docker-compose.yaml b/docker-compose.yaml index 2383271..7a1c188 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,8 +3,6 @@ version: "3.7" services: db_primary: image: mysql:5.7 - # volumes: - # - db_data:/var/lib/mysql restart: always environment: MYSQL_DATABASE: docker_dev @@ -46,3 +44,7 @@ services: - db_auth links: - db_auth + mailer: + image: driftydirt/group24mailer:0.0.3 + ports: + - "3002:3000" -- GitLab