Add GET /api/v1/countries/borders endpoint to get countries for scratch map feature

This commit is contained in:
Eugene Burmakin 2024-11-01 20:49:59 +01:00
parent 02a5289024
commit 34c12a9536
7 changed files with 38 additions and 2 deletions

View file

@ -1 +1 @@
0.15.12
0.15.13

View file

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
# 0.15.13 - 2024-11-01
### Added
- `GET /api/v1/countries/borders` endpoint to get countries for scratch map feature
# 0.15.12 - 2024-11-01
### Added

View file

@ -0,0 +1,11 @@
# frozen_string_literal: true
class Api::V1::Countries::BordersController < ApplicationController
def index
countries = Rails.cache.fetch('dawarich/countries_codes', expires_in: 1.day) do
Oj.load(File.read(Rails.root.join('lib/assets/countries.json')))
end
render json: countries
end
end

View file

@ -157,7 +157,7 @@ export default class extends Controller {
try {
// Up-to-date version can be found on Github:
// https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson
const response = await fetch('/countries.geojson', {
const response = await fetch('/api/v1/countries/borders.json', {
headers: {
'Accept': 'application/geo+json,application/json'
}

View file

@ -72,6 +72,10 @@ Rails.application.routes.draw do
namespace :owntracks do
resources :points, only: :create
end
namespace :countries do
resources :borders, only: :index
end
end
end
end

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Api::V1::Countries::Borders', type: :request do
describe 'GET /index' do
it 'returns a list of countries with borders' do
get '/api/v1/countries/borders'
expect(response).to have_http_status(:success)
expect(response.body).to include('AF')
expect(response.body).to include('ZW')
end
end
end