-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create task #8
Merged
Merged
create task #8
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
31eda58
feature: Creating theme
mikeoleynik bec1f14
feature: Updating theme
mikeoleynik 4085091
feature: Deleting theme
mikeoleynik e7926d0
feature: Creating task
mikeoleynik deb57a0
feature: Updating task
mikeoleynik fa932b5
feature: Deleting task
mikeoleynik 9cda7f9
feature: The student can be given a task.
mikeoleynik ede215f
feature: Adding users when create task
mikeoleynik 582da6a
feature: After creating task - student receive notification
mikeoleynik 57e6646
feature: Adding picture to task
mikeoleynik dddf917
chore: Adding user to task in user_tasks_attributes
mikeoleynik e1ba4d0
refactoring: methods that render correct json placed in ApplicationRe…
mikeoleynik 4749937
chore: Adding correct json for creating user
mikeoleynik f4179be
test: Common spec adding to the shared examples
mikeoleynik 2b733c4
refactoring: Moved shared logic serializers in base class
mikeoleynik 9a091d5
chore: Adding contrains to user_tasks and pictures tables
mikeoleynik d049c62
chore: Adding locale for task mailer
mikeoleynik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше использовать сервисы, чтобы избежать подобных коллбеков. коллбеки сложнее тестировать и они менее предсказуемы чем линейный код |
||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
эта конструкция повторяется во всех контроллерах, думаю можно вынести в метод и передавать в него блок