-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from mikeoleynik/2-create-task
create task
- Loading branch information
Showing
57 changed files
with
690 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
class TasksController < ApplicationController | ||
# POST /tasks | ||
def create | ||
task = Task.new(task_params) | ||
|
||
if task.save | ||
render_success(TaskSerializer.new(task)) | ||
else | ||
render_errors(task) | ||
end | ||
end | ||
|
||
# PATCH /tasks/:id | ||
def update | ||
task = Task.find(params[:id]) | ||
|
||
if task.update_attributes(task_params) | ||
render_success(TaskSerializer.new(task)) | ||
else | ||
render_errors(task) | ||
end | ||
end | ||
|
||
# DELETE /tasks/:id | ||
def destroy | ||
task = Task.find(params[:id]) | ||
task.destroy | ||
render json: {}, status: :no_content | ||
end | ||
|
||
private | ||
|
||
def task_params | ||
params.permit(:title, :body, :difficulty, :theme_id, picture_attributes: %i[image id _destroy], | ||
user_tasks_attributes: %i[id task_id user_id _destroy]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
class ThemesController < ApplicationController | ||
# POST /themes | ||
def create | ||
theme = Theme.new(theme_params) | ||
if theme.save | ||
render_success(ThemeSerializer.new(theme)) | ||
else | ||
render_errors(theme) | ||
end | ||
end | ||
|
||
# PATCH /themes/:id | ||
def update | ||
theme = Theme.find(params[:id]) | ||
if theme.update(theme_params) | ||
render_success(ThemeSerializer.new(theme)) | ||
else | ||
render_errors(theme) | ||
end | ||
end | ||
|
||
# DELETE /themes/:id | ||
def destroy | ||
theme = Theme.find(params[:id]) | ||
theme.destroy | ||
render json: {}, status: :no_content | ||
end | ||
|
||
private | ||
|
||
def theme_params | ||
params.permit(:title) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserTasksController < ApplicationController | ||
# POST /user_tasks | ||
def create | ||
user_task = UserTask.new(user_tasks_params) | ||
|
||
if user_task.save | ||
render_success(UserTaskSerializer.new(user_task)) | ||
else | ||
render_errors(user_task) | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_tasks_params | ||
params.permit(:user_id, :task_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
class UsersController < ApplicationController | ||
# POST /users | ||
def create | ||
User.invite!(email: '[email protected]', fullname: 'John Doe') | ||
render json: { success: 'invite sent' }, status: :ok | ||
user = User.invite!(email: '[email protected]', fullname: 'John Doe') | ||
render_success(UserSerializer.new(user)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class TaskMailer < ApplicationMailer | ||
def create_task | ||
email = User.find(params[:user]).email | ||
@task = Task.find(params[:task]).title | ||
|
||
mail(to: email, subject: t(:subject, scope: [:mailers, :task, :create_task])) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Picture < ApplicationRecord | ||
belongs_to :task | ||
|
||
mount_uploader :image, PictureUploader | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class Task < ApplicationRecord | ||
belongs_to :theme | ||
|
||
has_one :picture, dependent: :destroy | ||
has_many :user_tasks, dependent: :destroy | ||
has_many :users, through: :user_tasks | ||
|
||
validates :title, :body, :difficulty, presence: true | ||
validates :difficulty, numericality: { only_integer: true, less_than_or_equal_to: 10 } | ||
|
||
accepts_nested_attributes_for :picture | ||
accepts_nested_attributes_for :user_tasks | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Theme < ApplicationRecord | ||
has_many :tasks, dependent: :destroy | ||
|
||
validates :title, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserTask < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :task | ||
|
||
after_commit :create_task | ||
|
||
private | ||
|
||
def create_task | ||
TaskMailer.with(user: user_id, task: task_id).create_task.deliver_later | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class BaseSerializer | ||
include FastJsonapi::ObjectSerializer | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class TaskSerializer < BaseSerializer | ||
attributes :title, :body, :difficulty, :theme_id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class ThemeSerializer < BaseSerializer | ||
attributes :title | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserSerializer < BaseSerializer | ||
attributes :email, :fullname | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserTaskSerializer < BaseSerializer | ||
attributes :user_id, :task_id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class PictureUploader < CarrierWave::Uploader::Base | ||
include CarrierWave::MiniMagick | ||
|
||
storage :file | ||
|
||
def store_dir | ||
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | ||
end | ||
|
||
def extension_whitelist | ||
%w(jpg jpeg gif png) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
!!! | ||
%html | ||
%head | ||
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/ | ||
:css | ||
/* Email styles need to be inline */ | ||
%body | ||
= yield |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%p Task: #{@task} created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,5 @@ | ||
# Files in the config/locales directory are used for internationalization | ||
# and are automatically loaded by Rails. If you want to use locales other | ||
# than English, add the necessary files in this directory. | ||
# | ||
# To use the locales, use `I18n.t`: | ||
# | ||
# I18n.t 'hello' | ||
# | ||
# In views, this is aliased to just `t`: | ||
# | ||
# <%= t('hello') %> | ||
# | ||
# To use a different locale, set it with `I18n.locale`: | ||
# | ||
# I18n.locale = :es | ||
# | ||
# This would use the information in config/locales/es.yml. | ||
# | ||
# The following keys must be escaped otherwise they will not be retrieved by | ||
# the default I18n backend: | ||
# | ||
# true, false, on, off, yes, no | ||
# | ||
# Instead, surround them with single quotes. | ||
# | ||
# en: | ||
# 'true': 'foo' | ||
# | ||
# To learn more, please read the Rails Internationalization guide | ||
# available at http://guides.rubyonrails.org/i18n.html. | ||
|
||
en: | ||
hello: "Hello world" | ||
mailers: | ||
task: | ||
create_task: | ||
subject: 'Task created' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.