Skip to content

Instantly share code, notes, and snippets.

@roharon
Last active July 24, 2020 08:27
Show Gist options
  • Save roharon/3361c2f463231456c6aa5b30c9980533 to your computer and use it in GitHub Desktop.
Save roharon/3361c2f463231456c6aa5b30c9980533 to your computer and use it in GitHub Desktop.
@Api(tags = {"1. Store"})
@Validated
@RestController
@AllArgsConstructor
@RequestMapping(value = "/api/v1/store")
public class StoreController {
private static final Logger LOGGER = LogManager.getLogger(StoreController.class);
private StoreRepository storeRepository;
private final int RADIUS = 1000;
private final int SIZE_PER_PAGE = 20;
@ApiOperation(value="근처 가맹점 조회", notes ="사용자 기준 근처 가맹점 조회")
@GetMapping("/near")
public @ResponseBody StoreListResponse getNearStore(
@ApiParam(value="페이지", defaultValue = "0") @RequestParam Integer page,
@ApiParam(value="시군", required = true) @RequestParam String sigoon,
@ApiParam(value="위도", required = true) @RequestParam float lat,
@ApiParam(value="경도", required = true) @RequestParam float lng) {
List<String> errors = new ArrayList<>();
Page<Store> storeList = null;
try{
PageRequest pageRequest = PageRequest.of(page, SIZE_PER_PAGE);
storeList = storeRepository.findBySigoonAndEarthDistance(pageRequest, sigoon, lat, lng, RADIUS);
} catch(Exception e){
errors.add(e.getMessage());
LOGGER.error(e.getMessage());
}
return StoreAdapter.storeListResponse(storeList, errors);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment