Skip to content
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 17 commits into from
Sep 12, 2019
Merged

create task #8

merged 17 commits into from
Sep 12, 2019

Conversation

mikeoleynik
Copy link
Owner

  • Adding #create, #update, #delete for Theme, Task.
  • Adding join table user_tasks. (The student can be given a task.). It is possible to add a link between a user and a task:
    • when creating a task;
    • in a separate UserTaskController
  • After creating a task - student receives a notification (callback is triggered when a user is created);
  • Adding a picture to the task;

Issue: #2 Create task

@mikeoleynik mikeoleynik added the enhancement New feature or request label Sep 11, 2019
task = Task.new(task_params)

if task.save
render_success(TaskSerializer.new(task))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

эта конструкция повторяется во всех контроллерах, думаю можно вынести в метод и передавать в него блок

email = User.find(params[:user]).email
@task = Task.find(params[:task]).title

mail(to: email, subject: 'Task created')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

юзай I18n сразу

belongs_to :user
belongs_to :task

after_commit :create_task

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше использовать сервисы, чтобы избежать подобных коллбеков. коллбеки сложнее тестировать и они менее предсказуемы чем линейный код

# frozen_string_literal: true

class TaskSerializer
include FastJsonapi::ObjectSerializer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сделай базовый класс и вынеси include в него

"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

# process scale: [200, 300]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

удаляй этот закомментированный код

db/schema.rb Outdated
end

create_table "user_tasks", force: :cascade do |t|
t.bigint "user_id"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null: false


# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "pictures", force: :cascade do |t|
t.string "image"
t.integer "task_id"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null: false ?

# PATCH /themes/:id
def update
theme = Theme.find(params[:id])
if theme.update_attributes(theme_params)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update

@mikeoleynik mikeoleynik merged commit ca991d8 into master Sep 12, 2019
@mikeoleynik mikeoleynik deleted the 2-create-task branch September 12, 2019 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants