tramway-api 0.4.1 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c2f3fdcc95c2f0dd8a014123d5e090bef95931953cf943bd152a4c80c80d810
4
- data.tar.gz: 9fb3a7d8e4a28296eccbf9f1eef2534b7754aae3f1d62cd6dcc91d39403a1c80
3
+ metadata.gz: 9d30f1034ddf1ce117031c4938dd22976165f3e14aedbe7dc88b8e4e17101db0
4
+ data.tar.gz: 136d87b0dc8ac562d8e77615b8fa25a633ec8413efbfd6e641338ade3c9195df
5
5
  SHA512:
6
- metadata.gz: 8a2a4adaee087ac770e142a945e4d01f1328c03cef7a19aef7c5473f8818eae9d6d10cf19f8cf04ab93e736bc1c7319b715d5840def3b34035820fd026122025
7
- data.tar.gz: d221ec2853428480eccb1fe7a31d7def12fb5ea1853c6ba8b8803e056da28b64ca977ecb47c4f449114dc80285c5835e37d6ec9624bc7326a00ed3183e193938
6
+ metadata.gz: 8525c1cbae56ac1b2825fdaae66952557f671eb741837c7c9e2d17fd3c6e97e3e7f24a49a5aaba893a90845e623685f041d79a9a22d7a27c8a58cef2b95375bf
7
+ data.tar.gz: 720f689c3538cdc4c0aed15ff8d22b42ba28ca75c4219fef8922ae90cc719abaa473812864f111e19f3eb5c289ed6d9325965e9fc6a91328b6ecf29a514f91d5
@@ -2,8 +2,6 @@ module Tramway
2
2
  module Api
3
3
  module V1
4
4
  class ApplicationController < ::Tramway::Api::ApplicationController
5
- private
6
-
7
5
  def render_errors_for(model)
8
6
  render json: model, status: :unprocessable_entity, serializer: ::Tramway::Api::V1::ErrorSerializer
9
7
  end
@@ -7,5 +7,34 @@ module Tramway::Api::V1
7
7
  each_serializer: serializer,
8
8
  status: :ok
9
9
  end
10
+
11
+ def create
12
+ record_form = form_class.new model_class.new
13
+ if record_form.submit params[:data][:attributes]
14
+ render json: record_form.model,
15
+ serializer: serializer_class,
16
+ status: :created
17
+ else
18
+ render_errors_for record_form
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def model_class
25
+ params[:model].constantize
26
+ end
27
+
28
+ def decorator_class(model_name = nil)
29
+ "#{model_name || model_class}Decorator".constantize
30
+ end
31
+
32
+ def form_class(model_name = nil)
33
+ "#{model_name || model_class}Form".constantize
34
+ end
35
+
36
+ def serializer_class(model_name = nil)
37
+ "#{model_name || model_class}Serializer".constantize
38
+ end
10
39
  end
11
40
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Tramway::Api::V1::ApplicationSerializer < ActiveModel::Serializer
4
+ def created_at
5
+ object.created_at.iso8601
6
+ end
7
+
8
+ def updated_at
9
+ object.updated_at.iso8601
10
+ end
11
+ end
@@ -2,5 +2,6 @@ Tramway::Api::Engine.routes.draw do
2
2
  namespace :v1 do
3
3
  resource :user_token, only: [ :create ]
4
4
  resource :user, only: [ :create, :show ]
5
+ resources :records
5
6
  end
6
7
  end
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Api
3
- VERSION = '0.4.1'
3
+ VERSION = '0.5'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-28 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: knock
@@ -72,6 +72,7 @@ files:
72
72
  - app/jobs/tramway/api/application_job.rb
73
73
  - app/mailers/tramway/api/application_mailer.rb
74
74
  - app/models/tramway/api/application_record.rb
75
+ - app/serializers/tramway/api/v1/application_serializer.rb
75
76
  - app/serializers/tramway/api/v1/error_serializer.rb
76
77
  - app/views/layouts/tramway/api/application.html.erb
77
78
  - config/initializers/active_model_serializers.rb