Skip to content

Commit

Permalink
Feat: maps api (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
pingowl authored May 27, 2024
1 parent 0daa893 commit 0fa9bc5
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ out/
### classpath ###
application.properties
drugbox_firebase.json
gha-creds-*.json
gha-creds-*.json
seoul.geojson
drugbin.CSV
google-cloud-api.json
5 changes: 4 additions & 1 deletion src/main/java/com/drugbox/common/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public enum ErrorCode {

// 이미지 예외
IMAGE_SIZE_EXCEEDED(HttpStatus.BAD_REQUEST, "이미지 파일은 10MB이하여야 합니다."),
IMAGE_TYPE_INVALID(HttpStatus.BAD_REQUEST, "이미지 파일 타입이 유효하지 않습니다.");
IMAGE_TYPE_INVALID(HttpStatus.BAD_REQUEST, "이미지 파일 타입이 유효하지 않습니다."),

// Map 예외
NOT_FOUND_MAP_RESULT(HttpStatus.NOT_FOUND, "장소 검색 결과가 없습니다."),;

private final HttpStatus httpStatus;
private final String detail;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/drugbox/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public ResponseEntity<TokenDto> googleLogin(@RequestBody GoogleLoginParams param
}

@GetMapping("/redirect/google") // 백엔드 자체 테스트용
public ResponseEntity<TokenDto> googleRedirect(@RequestParam("code") String authCode){
public void googleRedirect(@RequestParam("code") String authCode){
log.info("\n AuthCode:" + authCode);
return ResponseEntity.ok(authService.getGoogleAccessToken(authCode));
//return ResponseEntity.ok(authService.getGoogleAccessToken(authCode));
}

@PostMapping("/signup/pw")
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/com/drugbox/controller/MapController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.drugbox.controller;

import com.drugbox.dto.request.CoordRequest;
import com.drugbox.dto.response.BinLocationResponse;
import com.drugbox.dto.response.MapDetailResponse;
import com.drugbox.dto.response.MapResponse;
import com.drugbox.service.MapService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.json.simple.parser.ParseException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;


@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("maps")
public class MapController {
private final MapService mapService;

@PostMapping("/seoul/save")
public ResponseEntity<Void> saveSeoulDrugBinLocations() {
mapService.saveSeoulDrugBinLocations();
return new ResponseEntity(HttpStatus.OK);
}

@PostMapping("/division/save")
public ResponseEntity<Void> saveDrugBinLocations() {
mapService.saveDrugBinLocations();
return new ResponseEntity(HttpStatus.OK);
}

@GetMapping("/seoul")
public ResponseEntity<List<BinLocationResponse>> getSeoulDrugBinLocations(){
List<BinLocationResponse> response = mapService.getSeoulDrugBinLocations();
return ResponseEntity.status(HttpStatus.OK).body(response);
}

@GetMapping("/division")
public ResponseEntity<List<BinLocationResponse>> getDivisionDrugBinLocations(
@RequestParam(value="addrLvl1") String addrLvl1,
@RequestParam(value="addrLvl2", required = false) String addrLvl2){
List<BinLocationResponse> response = mapService.getDivisionDrugBinLocations(addrLvl1, addrLvl2);
return ResponseEntity.status(HttpStatus.OK).body(response);
}

@GetMapping("/nearby")
public ResponseEntity<List<MapResponse>> getNearbyPharmacyAndConvenienceLocations(
@ModelAttribute CoordRequest coordRequest) throws IOException, ParseException {
List<MapResponse> response = mapService.getNearbyPharmacyAndConvenienceLocations(coordRequest);
return ResponseEntity.status(HttpStatus.OK).body(response);
}

@GetMapping("/search")
public ResponseEntity<List<MapResponse>> searchLocations(@RequestParam String name) throws IOException, ParseException {
List<MapResponse> responses = mapService.searchLocations(name);
return ResponseEntity.status(HttpStatus.OK).body(responses);
}

@GetMapping("/detail")
public ResponseEntity<MapDetailResponse> getLocationDetail(@RequestParam String id) throws IOException, ParseException {
MapDetailResponse response = mapService.searchLocationDetail(id);
return ResponseEntity.status(HttpStatus.OK).body(response);
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/drugbox/domain/BinId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.drugbox.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.io.Serializable;

@Embeddable
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@Data
public class BinId implements Serializable {
@Column(name = "bin_id")
private Long binId;
@Column(name = "division_key")
private Integer divisionKey;
}
32 changes: 32 additions & 0 deletions src/main/java/com/drugbox/domain/BinLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.drugbox.domain;

import com.drugbox.common.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Entity
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class BinLocation extends BaseEntity {

@EmbeddedId
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "binlocation_id")
private BinId id;

@Column(nullable = false)
private String lat;
@Column(nullable = false)
private String lng;
@Column(nullable = false)
private String address;
private String addrLvl1; // 시,도
private String addrLvl2; // 시,군,구
private String detail;
}
14 changes: 14 additions & 0 deletions src/main/java/com/drugbox/dto/request/CoordRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.drugbox.dto.request;

import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CoordRequest {
private String latitude;
private String longitude;
}

17 changes: 17 additions & 0 deletions src/main/java/com/drugbox/dto/response/BinLocationResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.drugbox.dto.response;

import lombok.Builder;
import lombok.Getter;


@Getter
@Builder
public class BinLocationResponse {
private Long id;
private String lat;
private String lng;
private String address;
private String addrLvl1; // 시,도
private String addrLvl2; // 시,군,구
private String detail;
}
14 changes: 14 additions & 0 deletions src/main/java/com/drugbox/dto/response/MapDetailResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.drugbox.dto.response;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class MapDetailResponse {
private String locationName;
private String locationId;
private String locationPhotos;
private String formattedAddress;
private String currentOpeningHours;
}
14 changes: 14 additions & 0 deletions src/main/java/com/drugbox/dto/response/MapResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.drugbox.dto.response;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class MapResponse {
private String locationName;
private String locationAddress;
private String locationId;
private String latitude;
private String longitude;
}
11 changes: 11 additions & 0 deletions src/main/java/com/drugbox/repository/BinLocationRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.drugbox.repository;

import com.drugbox.domain.BinLocation;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface BinLocationRepository extends JpaRepository<BinLocation, Long> {
List<BinLocation> findAllByAddrLvl1AndAddrLvl2(String addrLvl1, String addrLvl2);
List<BinLocation> findAllByAddrLvl1(String addrLvl1);
}
Loading

0 comments on commit 0fa9bc5

Please sign in to comment.