Browse Source

Added duration field to Task migration, timestamps fields are now sent with def show in Task controller

Lou 3 years ago
parent
commit
37e7828183

+ 1
- 1
app/controllers/api/v1/tasks_controller.rb View File

@@ -41,7 +41,7 @@ class Api::V1::TasksController < ApplicationController
41 41
   private
42 42
 
43 43
   def task_params
44
-    params.require(:task).permit(:name, :description, :activity_id)
44
+    params.require(:task).permit(:name, :description, :duration, :activity_id, :created_at, :updated_at)
45 45
   end
46 46
 
47 47
   def set_task

+ 1
- 1
app/serializers/task_serializer.rb View File

@@ -1,6 +1,6 @@
1 1
 class TaskSerializer
2 2
   include JSONAPI::Serializer
3
-  attributes :name, :description, :user_id, :activity_id
3
+  attributes :name, :description, :duration, :user_id, :activity_id, :created_at, :updated_at
4 4
 
5 5
   cache_options store: Rails.cache, namespace: 'jsonapi-serializer', expires_in: 1.hour
6 6
 end

+ 1
- 0
db/migrate/20210510133939_create_tasks.rb View File

@@ -4,6 +4,7 @@ class CreateTasks < ActiveRecord::Migration[6.1]
4 4
       t.string :name, null: false
5 5
       t.index :name
6 6
       t.text :description
7
+      t.integer :duration
7 8
       t.references :activity, null: false
8 9
       t.references :user, null: false
9 10
 

+ 1
- 0
db/schema.rb View File

@@ -35,6 +35,7 @@ ActiveRecord::Schema.define(version: 2021_05_10_133939) do
35 35
   create_table "tasks", force: :cascade do |t|
36 36
     t.string "name", null: false
37 37
     t.text "description"
38
+    t.integer "duration"
38 39
     t.integer "activity_id", null: false
39 40
     t.integer "user_id", null: false
40 41
     t.datetime "created_at", precision: 6, null: false

+ 1
- 0
db/seeds.rb View File

@@ -33,6 +33,7 @@ end
33 33
   task = Task.create(
34 34
     name: Faker::Fantasy::Tolkien.character,
35 35
     description: Faker::Fantasy::Tolkien.poem,
36
+    duration: rand(1..120),
36 37
     user_id: User.all.sample.id,
37 38
     activity_id: Activity.all.sample.id
38 39
   )

BIN
erd.pdf View File


+ 1
- 0
test/fixtures/tasks.yml View File

@@ -3,5 +3,6 @@
3 3
 one:
4 4
   name: Do something
5 5
   description: Description of a task
6
+  duration: 60
6 7
   user: one
7 8
   activity: one

+ 1
- 1
test/test_helper.rb View File

@@ -10,4 +10,4 @@ class ActiveSupport::TestCase
10 10
   fixtures :all
11 11
 
12 12
   # Add more helper methods to be used by all tests here...
13
-end
13
+end

Loading…
Cancel
Save