Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/item/controllers/itemController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { RequestHandler } from 'express';
import httpStatus from 'http-status-codes';
import { injectable, inject } from 'tsyringe';
import { SERVICES } from '../../common/constants';

import { ItemManager } from '../models/itemManager';
import { Item } from '../models/item';
import { GeoContext } from '../../common/interfaces';
Expand Down Expand Up @@ -39,18 +38,23 @@ export class ItemController {
this.createdResourceCounter = meter.createCounter('created_resource');
}

public getItems: GetResourceHandler = async (req, res) => {
const { command_name: commandName, tile, sub_tile, geo_context, reduce_fuzzy_match, size } = req.query;
const response = await this.manager.getItems(
{
commandName,
tile,
subTile: sub_tile ? parseInt(sub_tile) : undefined,
geo: geo_context ? (JSON.parse(geo_context) as GeoContext) : undefined,
},
reduce_fuzzy_match == 'true',
size ? parseInt(size) : undefined
);
return res.status(httpStatus.OK).json(response);
public getItems: GetResourceHandler = async (req, res, next) => {
try {
const { command_name: commandName, tile, sub_tile, geo_context, reduce_fuzzy_match, size } = req.query;
const response = await this.manager.getItems(
{
commandName,
tile,
subTile: sub_tile ? parseInt(sub_tile) : undefined,
geo: geo_context ? (JSON.parse(geo_context) as GeoContext) : undefined,
},
reduce_fuzzy_match == 'true',
size ? parseInt(size) : undefined
);
return res.status(httpStatus.OK).json(response);
} catch (error: unknown) {
this.logger.warn('itemController.getItems Error:', error);
next(error);
}
};
}
62 changes: 41 additions & 21 deletions src/latLon/controllers/latLonController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,56 @@ export class LatLonController {
this.createdResourceCounter = meter.createCounter('created_resource');
}

public latlonToTile: GetLatLonToTileHandler = async (req, res) => {
const { lat, lon } = req.query;

const response = await this.manager.latLonToTile({ lat, lon });
return res.status(httpStatus.OK).json(response);
public latlonToTile: GetLatLonToTileHandler = async (req, res, next) => {
try {
const { lat, lon } = req.query;

const response = await this.manager.latLonToTile({ lat, lon });
return res.status(httpStatus.OK).json(response);
} catch (error: unknown) {
this.logger.warn('latLonController.latlonToTile Error:', error);
next(error);
}
};

public tileToLatLon: GetTileToLatLonHandler = async (req, res) => {
const { tile: tileName, sub_tile_number } = req.query;

const response = await this.manager.tileToLatLon({
tileName,
subTileNumber: sub_tile_number,
});
return res.status(httpStatus.OK).json(response);
public tileToLatLon: GetTileToLatLonHandler = async (req, res, next) => {
try {
const { tile: tileName, sub_tile_number } = req.query;

const response = await this.manager.tileToLatLon({
tileName,
subTileNumber: sub_tile_number,
});
return res.status(httpStatus.OK).json(response);
} catch (error: unknown) {
this.logger.warn('latLonController.tileToLatLon Error:', error);
next(error);
}
};

public latlonToMgrs: GetLatLonToMgrsHandler = (req, res) => {
const { lat, lon, accuracy } = req.query;
public latlonToMgrs: GetLatLonToMgrsHandler = (req, res, next) => {
try {
const { lat, lon, accuracy } = req.query;

const response = this.manager.latLonToMGRS({ lat, lon, accuracy });
const response = this.manager.latLonToMGRS({ lat, lon, accuracy });

return res.status(httpStatus.OK).json(response);
return res.status(httpStatus.OK).json(response);
} catch (error: unknown) {
this.logger.warn('latLonController.latlonToMgrs Error:', error);
next(error);
}
};

public mgrsToLatlon: getMgrsToLatLonHandler = (req, res) => {
const { mgrs } = req.query;
public mgrsToLatlon: getMgrsToLatLonHandler = (req, res, next) => {
try {
const { mgrs } = req.query;

const response = this.manager.mgrsToLatLon(mgrs);
const response = this.manager.mgrsToLatLon(mgrs);

return res.status(httpStatus.OK).json(response);
return res.status(httpStatus.OK).json(response);
} catch (error: unknown) {
this.logger.warn('latLonController.mgrsToLatlon Error:', error);
next(error);
}
};
}
29 changes: 17 additions & 12 deletions src/route/controllers/routeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,22 @@ export class RouteController {
this.createdResourceCounter = meter.createCounter('created_resource');
}

public getRoutes: GetResourceHandler = async (req, res) => {
const { command_name: commandName, control_point, geo_context, reduce_fuzzy_match, size } = req.query;
const response = await this.manager.getRoutes(
{
commandName,
controlPoint: control_point ? parseInt(control_point) : undefined,
geo: geo_context ? (JSON.parse(geo_context) as GeoContext) : undefined,
},
reduce_fuzzy_match == 'true',
size ? parseInt(size) : undefined
);
return res.status(httpStatus.OK).json(response);
public getRoutes: GetResourceHandler = async (req, res, next) => {
try {
const { command_name: commandName, control_point, geo_context, reduce_fuzzy_match, size } = req.query;
const response = await this.manager.getRoutes(
{
commandName,
controlPoint: control_point ? parseInt(control_point) : undefined,
geo: geo_context ? (JSON.parse(geo_context) as GeoContext) : undefined,
},
reduce_fuzzy_match == 'true',
size ? parseInt(size) : undefined
);
return res.status(httpStatus.OK).json(response);
} catch (error: unknown) {
this.logger.warn('routeController.getRoutes Error:', error);
next(error);
}
};
}
21 changes: 13 additions & 8 deletions src/tile/controllers/tileController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ export class TileController {
this.createdResourceCounter = meter.createCounter('created_resource');
}

public getTiles: GetResourceHandler = async (req, res) => {
const { tile, sub_tile, reduce_fuzzy_match, size } = req.query;
const response = await this.manager.getTiles(
{ tile, subTile: sub_tile ? parseInt(sub_tile) : undefined },
reduce_fuzzy_match == 'true',
size ? parseInt(size) : undefined
);
return res.status(httpStatus.OK).json(response);
public getTiles: GetResourceHandler = async (req, res, next) => {
try {
const { tile, sub_tile, reduce_fuzzy_match, size } = req.query;
const response = await this.manager.getTiles(
{ tile, subTile: sub_tile ? parseInt(sub_tile) : undefined },
reduce_fuzzy_match == 'true',
size ? parseInt(size) : undefined
);
return res.status(httpStatus.OK).json(response);
} catch (error: unknown) {
this.logger.warn('tileController.getTiles Error:', error);
next(error);
}
};
}