-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 패키지 정리 * style: 사용되지 않는 코드 제거 * feat: 반복적인 개별 저장을 일괄 저장 방식으로 개선 * feat: @transactional 추가 * refactor: 코드 구조 개선
- Loading branch information
Showing
15 changed files
with
164 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
...contest/collectingbox/module/collectingbox/domain/repository/CollectingBoxRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
package contest.collectingbox.module.collectingbox.domain.repository; | ||
|
||
import contest.collectingbox.module.collectingbox.domain.CollectingBox; | ||
import contest.collectingbox.module.collectingbox.domain.Tag; | ||
import contest.collectingbox.module.location.domain.DongInfo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface CollectingBoxRepository extends JpaRepository<CollectingBox, Long>, CollectingBoxRepositoryCustom { | ||
|
||
@Query("select c from CollectingBox c join c.location l where l.dongInfo = :dongInfo and c.tag in :tags") | ||
List<CollectingBox> findAllByDongInfoAndTags(@Param("dongInfo") DongInfo dongInfo, | ||
@Param("tags") List<Tag> tags); | ||
} |
80 changes: 0 additions & 80 deletions
80
src/main/java/contest/collectingbox/module/publicdata/PublicDataApiController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
.../module/publicdata/AddressInfoMapper.java → .../publicdata/domain/AddressInfoMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ox/module/publicdata/KakaoApiManager.java → ...le/publicdata/domain/KakaoApiManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/contest/collectingbox/module/publicdata/domain/OpenDataApiManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package contest.collectingbox.module.publicdata.domain; | ||
|
||
import contest.collectingbox.global.exception.CollectingBoxException; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import static contest.collectingbox.global.exception.ErrorCode.UNEXPECTED_ERROR_EXTERNAL_API; | ||
|
||
@Component | ||
public class OpenDataApiManager { | ||
|
||
private static final String API_URL = "https://api.odcloud.kr/api%s?serviceKey=%s&perPage=%d"; | ||
|
||
@Value("${public-data.api.key}") | ||
private String apiKey; | ||
|
||
public int fetchTotalCount(String callAddress) { | ||
RestTemplate restTemplate = new RestTemplate(); | ||
ResponseEntity<String> response = restTemplate.getForEntity(getUrl(callAddress, 1), String.class); | ||
if (isError(response)) { | ||
throw new CollectingBoxException(UNEXPECTED_ERROR_EXTERNAL_API); | ||
} | ||
return new JSONObject(response.getBody()).getInt("totalCount"); | ||
} | ||
|
||
public JSONArray fetchOpenData(String callAddress, int perPage) { | ||
RestTemplate restTemplate = new RestTemplate(); | ||
ResponseEntity<String> response = restTemplate.getForEntity(getUrl(callAddress, perPage), String.class); | ||
if (isError(response)) { | ||
throw new CollectingBoxException(UNEXPECTED_ERROR_EXTERNAL_API); | ||
} | ||
return new JSONObject(response.getBody()).getJSONArray("data"); | ||
} | ||
|
||
private String getUrl(String callAddress, int perPage) { | ||
return String.format(API_URL, callAddress, apiKey, perPage); | ||
} | ||
|
||
private boolean isError(ResponseEntity<String> response) { | ||
return response.getStatusCode().isError(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../module/publicdata/PublicDataApiInfo.java → .../publicdata/domain/PublicDataApiInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...blicdata/PublicDataApiInfoRepository.java → ...a/domain/PublicDataApiInfoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.