mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Add GET /api/v1/countries/borders endpoint to get countries for scratch map feature
This commit is contained in:
parent
02a5289024
commit
34c12a9536
7 changed files with 38 additions and 2 deletions
|
|
@ -1 +1 @@
|
|||
0.15.12
|
||||
0.15.13
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
11
app/controllers/api/v1/countries/borders_controller.rb
Normal file
11
app/controllers/api/v1/countries/borders_controller.rb
Normal 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
|
||||
|
|
@ -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'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
15
spec/requests/api/v1/countries/borders_spec.rb
Normal file
15
spec/requests/api/v1/countries/borders_spec.rb
Normal 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
|
||||
Loading…
Reference in a new issue