mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Move point serializers to API namespace
This commit is contained in:
parent
df430851ce
commit
9d4cc7a4cf
7 changed files with 50 additions and 4 deletions
|
|
@ -31,6 +31,6 @@ class Api::V1::PointsController < ApiController
|
|||
private
|
||||
|
||||
def point_serializer
|
||||
params[:slim] == 'true' ? SlimPointSerializer : PointSerializer
|
||||
params[:slim] == 'true' ? Api::SlimPointSerializer : Api::PointSerializer
|
||||
end
|
||||
end
|
||||
|
|
|
|||
9
app/serializers/api/point_serializer.rb
Normal file
9
app/serializers/api/point_serializer.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Api::PointSerializer < PointSerializer
|
||||
EXCLUDED_ATTRIBUTES = %w[created_at updated_at visit_id import_id user_id raw_data].freeze
|
||||
|
||||
def call
|
||||
point.attributes.except(*EXCLUDED_ATTRIBUTES)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SlimPointSerializer
|
||||
class Api::SlimPointSerializer
|
||||
def initialize(point)
|
||||
@point = point
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class PointSerializer
|
||||
EXCLUDED_ATTRIBUTES = %w[created_at updated_at visit_id import_id user_id raw_data].freeze
|
||||
EXCLUDED_ATTRIBUTES = %w[created_at updated_at visit_id id import_id user_id raw_data].freeze
|
||||
|
||||
def initialize(point)
|
||||
@point = point
|
||||
|
|
|
|||
|
|
@ -72,8 +72,9 @@ class Exports::Create
|
|||
end
|
||||
|
||||
def create_export_file(data)
|
||||
dir_path = Rails.root.join('public', 'exports')
|
||||
dir_path = Rails.root.join('public/exports')
|
||||
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
|
||||
|
||||
file_path = dir_path.join("#{export.name}.#{file_format}")
|
||||
|
||||
File.open(file_path, 'w') { |file| file.write(data) }
|
||||
|
|
|
|||
20
spec/serializers/api/point_serializer_spec.rb
Normal file
20
spec/serializers/api/point_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::PointSerializer do
|
||||
describe '#call' do
|
||||
subject(:serializer) { described_class.new(point).call }
|
||||
|
||||
let(:point) { create(:point) }
|
||||
let(:expected_json) { point.attributes.except(*Api::PointSerializer::EXCLUDED_ATTRIBUTES) }
|
||||
|
||||
it 'returns JSON with correct attributes' do
|
||||
expect(serializer.to_json).to eq(expected_json.to_json)
|
||||
end
|
||||
|
||||
it 'does not include excluded attributes' do
|
||||
expect(serializer).not_to include(*Api::PointSerializer::EXCLUDED_ATTRIBUTES)
|
||||
end
|
||||
end
|
||||
end
|
||||
16
spec/serializers/api/slim_point_serializer_spec.rb
Normal file
16
spec/serializers/api/slim_point_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::SlimPointSerializer do
|
||||
describe '#call' do
|
||||
subject(:serializer) { described_class.new(point).call }
|
||||
|
||||
let(:point) { create(:point) }
|
||||
let(:expected_json) { point.attributes.slice('id', 'latitude', 'longitude', 'timestamp') }
|
||||
|
||||
it 'returns JSON with correct attributes' do
|
||||
expect(serializer.to_json).to eq(expected_json.to_json)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue