-
Notifications
You must be signed in to change notification settings - Fork 2
[TMO-62] 상대방 프로필 및 여행 로그 구현 #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b572ff1
feat: 마이페이지 프로필 조회 시 가입일자 추가
yuuuja 70c52f6
feat: 상대방 프로필 조회 로직 추가
yuuuja 6556624
feat: 여행 목록 관련 controller 통일 및 여행 개수 반환 로직 추가
yuuuja 0dec882
[TMO-62] 상대방의 만든 여행, 참가한 여행 목록 구현
yuuuja 28358cb
[TMO-62] countries csv파일 DB 적재
yuuuja 4e33595
[TMO-62] locations 테이블 데이터 적재 로직수정
yuuuja 55f5aaf
[TMO-62] 방문한 국가 로그 API 구현
yuuuja 5c077c8
[TMO-62] 여행 로그 API 조회 시 여행 날짜 추가
yuuuja 9ddc491
[TMO-62] 총 여행 거리 계산 로직 추가
yuuuja de5f271
[TMO-62] 여행로그 response시 국내/해외 분리 로직 추가
yuuuja 14a2a48
[TMO-62] 최근 신고 여부 및 횟수 추가
yuuuja 62d91b3
[TMO-62] 테스트코드 수정
yuuuja cc9e539
[TMO-62] 테스트코드 수정
yuuuja ae60184
[TMO-62] 여행 거리 DB 누적 방식으로 변경
yuuuja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/swyp/swyp6_team7/location/dao/CountryDao.java
This file contains hidden or 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,67 @@ | ||
| package swyp.swyp6_team7.location.dao; | ||
|
|
||
| import org.springframework.dao.DuplicateKeyException; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.springframework.stereotype.Repository; | ||
| import swyp.swyp6_team7.location.domain.Country; | ||
| import swyp.swyp6_team7.location.domain.Continent; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @Repository | ||
| public class CountryDao { | ||
| private final JdbcTemplate jdbcTemplate; | ||
|
|
||
| public CountryDao(JdbcTemplate jdbcTemplate) { | ||
| this.jdbcTemplate = jdbcTemplate; | ||
| } | ||
|
|
||
| public void addCountry(Country country) { | ||
| if (isCountryExists(country.getCountryName())) { | ||
| System.out.println("Duplicate country: " + country.getCountryName()); | ||
| return; | ||
| } | ||
|
|
||
| String sql = "INSERT INTO countries (country_name, latitude, longitude, continent) VALUES (?, ?, ?, ?)"; | ||
| try { | ||
| jdbcTemplate.update(sql, | ||
| country.getCountryName(), | ||
| country.getLatitude(), | ||
| country.getLongitude(), | ||
| country.getContinent().name()); | ||
| } catch (DuplicateKeyException e) { | ||
| System.out.println("Already exists: " + country.getCountryName()); | ||
| } | ||
| } | ||
|
|
||
| public boolean isCountryExists(String countryName) { | ||
| String sql = "SELECT COUNT(*) FROM countries WHERE country_name = ?"; | ||
| Integer count = jdbcTemplate.queryForObject(sql, new Object[]{countryName}, Integer.class); | ||
| return count != null && count > 0; | ||
| } | ||
|
|
||
| public Optional<Country> findByCountryName(String countryName) { | ||
| String sql = "SELECT * FROM countries WHERE country_name = ?"; | ||
| return jdbcTemplate.query(sql, new Object[]{countryName}, rs -> { | ||
| if (rs.next()) { | ||
| Country country = new Country(); | ||
| country.setId(rs.getInt("country_id")); | ||
| country.setCountryName(rs.getString("country_name")); | ||
| country.setLatitude(rs.getDouble("latitude")); | ||
| country.setLongitude(rs.getDouble("longitude")); | ||
| country.setContinent(Continent.valueOf(rs.getString("continent"))); | ||
| return Optional.of(country); | ||
| } | ||
| return Optional.empty(); | ||
| }); | ||
| } | ||
|
|
||
| public Country insertCountry(String countryName, Continent continent) { | ||
| String sql = "INSERT INTO countries (country_name, continent) VALUES (?, ?)"; | ||
| jdbcTemplate.update(sql, countryName, continent.name()); | ||
|
|
||
| return findByCountryName(countryName).orElseThrow(() -> | ||
| new IllegalStateException("Country insert failed: " + countryName)); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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
32 changes: 32 additions & 0 deletions
32
src/main/java/swyp/swyp6_team7/location/domain/Continent.java
This file contains hidden or 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,32 @@ | ||
| package swyp.swyp6_team7.location.domain; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum Continent { | ||
| ASIA("아시아"), | ||
| EUROPE("유럽"), | ||
| NORTH_AMERICA("북아메리카"), | ||
| SOUTH_AMERICA("남아메리카"), | ||
| AFRICA("아프리카"), | ||
| OCEANIA("오세아니아"), | ||
| ANTARCTICA("남극"); | ||
|
|
||
| private final String description; | ||
|
|
||
| public static Continent fromString(String value) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거 호출 빈도가 높으면 메모리 사용량이 꽤 될거같아서, String - Continent 쌍으로 Map 저장해도 좋을거같아요! |
||
| return Arrays.stream(values()) | ||
| .filter(e -> e.description.equals(value)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalArgumentException("지원되지 않는 Continent입니다: " + value)); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return description; | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
src/main/java/swyp/swyp6_team7/location/domain/Country.java
This file contains hidden or 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,32 @@ | ||
| package swyp.swyp6_team7.location.domain; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @Entity | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Table(name ="countries") | ||
| public class Country { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "country_id") | ||
| private Integer id; | ||
|
|
||
| @Column(name = "country_name",nullable = false, unique = true) | ||
| private String countryName; | ||
|
|
||
| private Double latitude; | ||
| private Double longitude; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| private Continent continent; | ||
|
|
||
| @Builder | ||
| public Country(String countryName, Continent continent) { | ||
| this.countryName = countryName; | ||
| this.continent = continent; | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -21,9 +21,16 @@ public class Location { | |
| @Column(name = "location_type") | ||
| private LocationType locationType; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "country_id", nullable = false) | ||
| private Country country; | ||
|
Comment on lines
+24
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요건 개인적인 선호도인데... Join 을 명시적으로 안하고 코드 레벨에서 관리하면 어떨까 싶습니다. 회의할때 의견 나눠보시죵 |
||
|
|
||
|
|
||
|
|
||
| @Builder | ||
| public Location(String locationName,LocationType locationType) { | ||
| public Location(String locationName,LocationType locationType, Country country) { | ||
| this.locationName = locationName; | ||
| this.locationType = locationType; | ||
| this.country = country; | ||
| } | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
src/main/java/swyp/swyp6_team7/location/init/CountryInitializer.java
This file contains hidden or 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,37 @@ | ||
| package swyp.swyp6_team7.location.init; | ||
|
|
||
| import jakarta.annotation.PostConstruct; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.core.io.ClassPathResource; | ||
| import org.springframework.stereotype.Component; | ||
| import swyp.swyp6_team7.location.dao.CountryDao; | ||
| import swyp.swyp6_team7.location.domain.Country; | ||
| import swyp.swyp6_team7.location.parser.CountryParser; | ||
| import swyp.swyp6_team7.location.reader.CsvReader; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.util.List; | ||
|
|
||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class CountryInitializer { | ||
| private final CsvReader<Country> csvReader; | ||
| private final CountryParser countryParser; | ||
| private final CountryDao countryDao; | ||
|
|
||
| @PostConstruct | ||
| public void initCountries() { | ||
| try { | ||
| InputStream input = new ClassPathResource("cities/countries.csv").getInputStream(); | ||
| List<Country> countries = csvReader.readByLine(input, countryParser, null); | ||
| countries.stream() | ||
| .filter(country -> country != null) | ||
| .forEach(countryDao::addCountry); | ||
| System.out.println("countries.csv 적재 완료 (" + countries.size() + "건)"); | ||
| } catch (Exception e) { | ||
| System.err.println("countries.csv 적재 실패: " + e.getMessage()); | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/swyp/swyp6_team7/location/init/LocationInitializer.java
This file contains hidden or 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,22 @@ | ||
| package swyp.swyp6_team7.location.init; | ||
|
|
||
| import jakarta.annotation.PostConstruct; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
| import swyp.swyp6_team7.location.service.LocationService; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class LocationInitializer { | ||
| private final LocationService locationService; | ||
|
|
||
| @PostConstruct | ||
| public void initLocations() { | ||
| try { | ||
| locationService.loadAllLocations(); | ||
| } catch (Exception e) { | ||
| System.err.println("Location 초기 데이터 적재 실패: " + e.getMessage()); | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요거는 JPA 안쓰시고 JDBC 쓰신 이유가 있으실까요?