Skip to content

Commit

Permalink
osmApi: refactor – move to services/osm folder (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz authored Jan 10, 2025
1 parent 837e6fc commit 0dd09e9
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion pages/api/og-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ImageDefFromCenter,
ImageDefFromTag,
} from '../../src/services/types';
import { fetchWithMemberFeatures } from '../../src/services/osmApi';
import { fetchWithMemberFeatures } from '../../src/services/osm/osmApi';
import { getImageFromApi } from '../../src/services/images/getImageFromApi';
import { getLogo, ProjectLogo } from '../../src/server/images/logo';
import { ImageType } from '../../src/services/images/getImageDefs';
Expand Down
2 changes: 1 addition & 1 deletion pages/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { serverFetchOsmUser } from '../../src/server/osmApiAuthServer';
import { OSM_TOKEN_COOKIE } from '../../src/services/osmApiConsts';
import { OSM_TOKEN_COOKIE } from '../../src/services/osm/consts';

export default async (req: NextApiRequest, res: NextApiResponse) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/components/App/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Sentry from '@sentry/nextjs';
import nextCookies from 'next-cookies';
import Cookies from 'js-cookie';
import { clearFeatureCache, fetchFeature } from '../../services/osmApi';
import { clearFeatureCache, fetchFeature } from '../../services/osm/osmApi';
import { fetchJson } from '../../services/fetch';
import { isServer } from '../helpers';
import { getCoordsFeature } from '../../services/getCoordsFeature';
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeaturePanel/Climbing/useGetHandleSave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ClimbingRoute } from './types';
import { Feature, FeatureTags } from '../../../services/types';
import { useFeatureContext } from '../../utils/FeatureContext';
import { useClimbingContext } from './contexts/ClimbingContext';
import { CragChange, editCrag } from '../../../services/osmApiAuth';
import { CragChange, editCrag } from '../../../services/osm/osmApiAuth';
import { invertedBoltCodeMap } from './utils/boltCodes';
import { useSnackbar } from '../../utils/SnackbarContext';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EditDataItem, Members } from '../useEditItems';
import { getApiId, getShortId } from '../../../../services/helpers';
import { getOsmElement } from '../../../../services/osmApi';
import { getOsmElement } from '../../../../services/osm/osmApi';
import { useEditContext } from '../EditContext';
import { useFeatureEditData } from './FeatureEditSection/SingleFeatureEditContext';
import React from 'react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useTheme,
} from '@mui/material';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { fetchParentFeatures } from '../../../../services/osmApi';
import { fetchParentFeatures } from '../../../../services/osm/osmApi';
import { getApiId, getShortId } from '../../../../services/helpers';
import { FeatureRow } from './FeatureRow';
import { t } from '../../../../services/intl';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { EditDataItem } from '../useEditItems';
import { useEditContext } from '../EditContext';
import { getApiId, getShortId } from '../../../../services/helpers';
import { getFullFeatureWithMemberFeatures } from '../../../../services/osmApi';
import { getFullFeatureWithMemberFeatures } from '../../../../services/osm/osmApi';

const CharacterCountContainer = styled.div`
position: absolute;
Expand Down
4 changes: 2 additions & 2 deletions src/components/FeaturePanel/EditDialog/useGetHandleSave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useEditDialogFeature } from './utils';
import { useEditContext } from './EditContext';
import { createNoteText } from './createNoteText';
import { t } from '../../../services/intl';
import { saveChanges } from '../../../services/osmApiAuth';
import { insertOsmNote } from '../../../services/osmApi';
import { saveChanges } from '../../../services/osm/osmApiAuth';
import { insertOsmNote } from '../../../services/osm/osmApi';
import { useSnackbar } from '../../utils/SnackbarContext';
import { getShortId } from '../../../services/helpers';

Expand Down
2 changes: 1 addition & 1 deletion src/components/FeaturePanel/FeatureDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { t, Translation } from '../../services/intl';
import { useFeatureContext } from '../utils/FeatureContext';
import { TooltipButton } from '../utils/TooltipButton';
import { Feature } from '../../services/types';
import { OSM_WEBSITE } from '../../services/osmApiConsts';
import { OSM_WEBSITE } from '../../services/osm/consts';

const InfoTooltipWrapper = styled.span`
position: relative;
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeaturePanel/ObjectsAround.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Box, Typography } from '@mui/material';
import Router from 'next/router';
import { fetchAroundFeature } from '../../services/osmApi';
import { fetchAroundFeature } from '../../services/osm/osmApi';
import { useFeatureContext } from '../utils/FeatureContext';
import { Feature } from '../../services/types';
import { getOsmappLink, getUrlOsmId } from '../../services/helpers';
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeaturePanel/OsmError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box, Alert } from '@mui/material';
import { t } from '../../services/intl';
import { getUrlOsmId } from '../../services/helpers';
import { useFeatureContext } from '../utils/FeatureContext';
import { OSM_WEBSITE } from '../../services/osmApiConsts';
import { OSM_WEBSITE } from '../../services/osm/consts';

export const OsmError = () => {
const { feature } = useFeatureContext();
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeaturePanel/helpers/TestApiWarning.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API_SERVER, USE_PROD_API } from '../../../services/osmApiConsts';
import { API_SERVER, USE_PROD_API } from '../../../services/osm/consts';
import { Alert, Box } from '@mui/material';
import Link from 'next/link';
import React from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Map/behaviour/maptilerFix.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Feature, OsmId } from '../../../services/types';
import { getShortId } from '../../../services/helpers';
import { quickFetchFeature } from '../../../services/osmApi';
import { quickFetchFeature } from '../../../services/osm/osmApi';
import { MapGeoJSONFeature } from 'maplibre-gl';

const isFarAway = (feature: Feature, skeleton: Feature) =>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Map/behaviour/useOnMapClicked.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMapEventHook, isMobileDevice } from '../../helpers';
import pickBy from 'lodash/pickBy';
import { addFeatureCenterToCache } from '../../../services/osmApi';
import { addFeatureCenterToCache } from '../../../services/osm/osmApi';
import { getOsmappLink, getShortId } from '../../../services/helpers';
import {
getRoundedPosition,
Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchBox/onSelectedFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Router, { NextRouter } from 'next/router';
import { getApiId, getShortId, getUrlOsmId } from '../../services/helpers';
import { addFeatureCenterToCache } from '../../services/osmApi';
import { addFeatureCenterToCache } from '../../services/osm/osmApi';
import { getOverpassSource } from '../../services/mapStorage';
import { performOverpassSearch } from '../../services/overpassSearch';
import { t } from '../../services/intl';
Expand Down
4 changes: 2 additions & 2 deletions src/components/utils/OsmAuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
loginAndfetchOsmUser,
osmLogout,
OsmUser,
} from '../../services/osmApiAuth';
} from '../../services/osm/osmApiAuth';
import { useSnackbar } from './SnackbarContext';
import { OSM_USER_COOKIE } from '../../services/osmApiConsts';
import { OSM_USER_COOKIE } from '../../services/osm/consts';

type OsmAuthType = {
loggedIn: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { addFeatureCenterToCache, fetchFeature } from '../osmApi';
import * as helpers from '../../components/helpers';
import * as fetch from '../fetch';
import * as helpers from '../../../components/helpers';
import * as fetch from '../../fetch';
import {
NODE,
NODE_FEATURE,
RELATION,
RELATION_FEATURE,
WAY,
WAY_FEATURE,
} from './osmApi.fixture';
import { intl } from '../intl';
import * as tagging from '../tagging/translations';
import * as idTaggingScheme from '../tagging/idTaggingScheme';
} from '../../__tests__/osmApi.fixture';
import { intl } from '../../intl';
import * as tagging from '../../tagging/translations';
import * as idTaggingScheme from '../../tagging/idTaggingScheme';

jest.mock('../../components/helpers', () => ({
jest.mock('../../../components/helpers', () => ({
isServer: jest.fn(),
isBrowser: jest.fn(),
}));

jest.mock('../fetch', () => ({
jest.mock('../../fetch', () => ({
fetchJson: jest.fn(),
}));

jest.mock('../tagging/translations', () => ({
jest.mock('../../tagging/translations', () => ({
fetchSchemaTranslations: jest.fn(),
}));

jest.mock('../tagging/idTaggingScheme', () => ({
jest.mock('../../tagging/idTaggingScheme', () => ({
addSchemaToFeature: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { osmToFeature } from '../osmToFeature';

import { ImageDef } from '../types';
import { ImageDef } from '../../types';

const nodeResponse = {
type: 'node',
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Feature } from './types';
import { addSchemaToFeature } from './tagging/idTaggingScheme';
import { Feature } from '../types';
import { addSchemaToFeature } from '../tagging/idTaggingScheme';
import { osmToFeature } from './osmToFeature';

// this is raw response from openstreetmap api
Expand Down
30 changes: 15 additions & 15 deletions src/services/osmApi.ts → src/services/osm/osmApi.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { resolveCountryCode } from 'next-codegrid';
import { FetchError, getShortId, getUrlOsmId } from './helpers';
import { fetchJson } from './fetch';
import { FetchError, getShortId, getUrlOsmId } from '../helpers';
import { fetchJson } from '../fetch';
import {
Feature,
LonLat,
OsmId,
Position,
RelationMember,
SuccessInfo,
} from './types';
import { removeFetchCache } from './fetchCache';
import { overpassAroundToSkeletons } from './overpassAroundToSkeletons';
import { isBrowser } from '../components/helpers';
import { addSchemaToFeature } from './tagging/idTaggingScheme';
import { fetchSchemaTranslations } from './tagging/translations';
} from '../types';
import { removeFetchCache } from '../fetchCache';
import { overpassAroundToSkeletons } from '../overpassAroundToSkeletons';
import { isBrowser } from '../../components/helpers';
import { addSchemaToFeature } from '../tagging/idTaggingScheme';
import { fetchSchemaTranslations } from '../tagging/translations';
import { osmToFeature } from './osmToFeature';
import { getImageDefs, mergeMemberImageDefs } from './images/getImageDefs';
import { getImageDefs, mergeMemberImageDefs } from '../images/getImageDefs';
import * as Sentry from '@sentry/nextjs';
import { fetchOverpassCenter } from './overpass/fetchOverpassCenter';
import { fetchOverpassCenter } from '../overpass/fetchOverpassCenter';
import {
isClimbingRelation,
isClimbingRoute,
isPublictransportRoute,
isRouteMaster,
publishDbgObject,
} from '../utils';
import { getOverpassUrl } from './overpassSearch';
import { API_SERVER, OSM_WEBSITE } from './osmApiConsts';
} from '../../utils';
import { getOverpassUrl } from '../overpassSearch';
import { API_SERVER, OSM_WEBSITE } from './consts';

const getOsmUrl = ({ type, id }: OsmId) =>
`${API_SERVER}/api/0.6/${type}/${id}.json`;
Expand Down Expand Up @@ -352,12 +352,12 @@ export const fetchFeature = async (apiId: OsmId): Promise<Feature> => {
// offline features for testing
if (apiId.type === 'relation' && apiId.id === 6) {
await fetchSchemaTranslations();
const osmApiTestItems = await import('./osmApiTestItems');
const osmApiTestItems = await import('./offlineItems');
return osmApiTestItems.TEST_CRAG;
}
if (apiId.type === 'node' && apiId.id === 6) {
await fetchSchemaTranslations();
const osmApiTestItems = await import('./osmApiTestItems');
const osmApiTestItems = await import('./offlineItems');
return osmApiTestItems.TEST_NODE;
}

Expand Down
14 changes: 7 additions & 7 deletions src/services/osmApiAuth.ts → src/services/osm/osmApiAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
OsmId,
Position,
SuccessInfo,
} from './types';
} from '../types';
import {
buildXmlString,
getApiId,
Expand All @@ -21,15 +21,15 @@ import {
stringifyDomXml,
Xml2JsMultiDoc,
Xml2JsSingleDoc,
} from './helpers';
import { join } from '../utils';
} from '../helpers';
import { join } from '../../utils';
import { clearFeatureCache } from './osmApi';
import { isBrowser } from '../components/helpers';
import { getLabel } from '../helpers/featureLabel';
import { isBrowser } from '../../components/helpers';
import { getLabel } from '../../helpers/featureLabel';
import {
EditDataItem,
Members,
} from '../components/FeaturePanel/EditDialog/useEditItems';
} from '../../components/FeaturePanel/EditDialog/useEditItems';
import {
OSM_WEBSITE,
PROD_CLIENT_ID,
Expand All @@ -38,7 +38,7 @@ import {
TEST_SERVER,
USE_PROD_API,
OSM_TOKEN_COOKIE,
} from './osmApiConsts';
} from './consts';

// TS file in osm-auth is probably broken (new is required)
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Feature } from './types';
import { getPoiClass } from './getPoiClass';
import { getImageDefs } from './images/getImageDefs';
import { Feature } from '../types';
import { getPoiClass } from '../getPoiClass';
import { getImageDefs } from '../images/getImageDefs';

export const osmToFeature = (element): Feature => {
const {
Expand Down

0 comments on commit 0dd09e9

Please sign in to comment.