Skip to content

Commit

Permalink
chore: #548과 충돌해결을 위한 merge
Browse files Browse the repository at this point in the history
  • Loading branch information
yoondgu committed Oct 17, 2023
2 parents 2fc368c + 11320bb commit 3592ff0
Show file tree
Hide file tree
Showing 33 changed files with 133 additions and 156 deletions.
6 changes: 4 additions & 2 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation group: 'com.github.maricn', name: 'logback-slack-appender', version: '1.6.1'

implementation 'com.github.maricn:logback-slack-appender:1.6.1'
implementation 'org.hibernate:hibernate-spatial:6.2.5.Final'
implementation 'mysql:mysql-connector-java:8.0.32'

implementation 'io.jsonwebtoken:jjwt:0.9.1'
Expand All @@ -44,6 +44,8 @@ dependencies {
testImplementation 'io.rest-assured:rest-assured'
testImplementation 'io.rest-assured:spring-mock-mvc'
testImplementation 'org.assertj:assertj-core:3.19.0'
testImplementation 'org.testcontainers:mysql:1.17.2'
testImplementation 'org.testcontainers:junit-jupiter:1.17.2'

// S3
implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.1000')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public List<TopicResponse> findNearbyTopicsSortedByPinCount(
) {
Coordinate coordinate = Coordinate.of(latitude, longitude);
List<Location> nearLocation = locationRepository.findAllByCoordinateAndDistanceInMeters(
coordinate,
coordinate.getCoordinate(),
NEAR_DISTANCE_METERS
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.mapbefine.mapbefine.location.domain;

import static com.mapbefine.mapbefine.location.exception.LocationErrorCode.ILLEGAL_COORDINATE_RANGE;
import static java.lang.Math.acos;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.Math.toRadians;
import static lombok.AccessLevel.PROTECTED;

import com.mapbefine.mapbefine.location.exception.LocationException.LocationBadRequestException;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.PrecisionModel;

@Embeddable
@NoArgsConstructor(access = PROTECTED)
Expand All @@ -23,21 +22,25 @@ public class Coordinate {
private static final double LONGITUDE_LOWER_BOUND = 124;
private static final double LONGITUDE_UPPER_BOUND = 132;

@Column(columnDefinition = "Decimal(18,15)")
private double latitude;
/*
* 4326은 데이터베이스에서 사용하는 여러 SRID 값 중, 일반적인 GPS기반의 위/경도 좌표를 저장할 때 쓰이는 값입니다.
* */
private static final GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);

@Column(columnDefinition = "Decimal(18,15)")
private double longitude;
@Column(columnDefinition = "geometry SRID 4326", nullable = false)
private Point coordinate;

private Coordinate(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
private Coordinate(Point point) {
this.coordinate = point;
}


public static Coordinate of(double latitude, double longitude) {
validateRange(latitude, longitude);

return new Coordinate(latitude, longitude);
Point point = geometryFactory.createPoint(new org.locationtech.jts.geom.Coordinate(longitude, latitude));

return new Coordinate(point);
}

private static void validateRange(double latitude, double longitude) {
Expand All @@ -51,13 +54,12 @@ private static boolean isNotInRange(double latitude, double longitude) {
|| (longitude < LONGITUDE_LOWER_BOUND || LONGITUDE_UPPER_BOUND < longitude);
}

public double calculateDistanceInMeters(Coordinate otherCoordinate) {
double earthRadius = 6_371_000;
public double getLatitude() {
return coordinate.getY();
}

return acos(sin(toRadians(otherCoordinate.latitude)) * sin(toRadians(this.latitude)) + (
cos(toRadians(otherCoordinate.latitude)) * cos(toRadians(this.latitude))
* cos(toRadians(otherCoordinate.longitude - this.longitude))
)) * earthRadius;
public double getLongitude() {
return coordinate.getX();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbefine.mapbefine.location.domain;

import java.util.List;
import org.locationtech.jts.geom.Point;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -11,15 +12,12 @@ public interface LocationRepository extends JpaRepository<Location, Long> {

@Query(
"SELECT l FROM Location l "
+ "WHERE ( 6371000 * acos( cos( radians(:#{#current_coordinate.latitude}) ) "
+ " * cos( radians( l.coordinate.latitude ) ) "
+ " * cos( radians( l.coordinate.longitude ) - radians(:#{#current_coordinate.longitude}) ) "
+ " + sin( radians(:#{#current_coordinate.latitude}) ) "
+ " * sin( radians( l.coordinate.latitude ) ) ) ) <= :distance"
+ "WHERE ST_Contains(ST_Buffer(:coordinate, :distance), l.coordinate.coordinate)"
)
List<Location> findAllByCoordinateAndDistanceInMeters(
@Param("current_coordinate") Coordinate coordinate,
@Param("coordinate") Point coordinate,
@Param("distance") double distance
);


}
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ private Member findMember(Long memberId) {
private Location findDuplicateOrCreatePinLocation(PinCreateRequest request) {
Coordinate coordinate = Coordinate.of(request.latitude(), request.longitude());

return locationRepository.findAllByCoordinateAndDistanceInMeters(coordinate,
DUPLICATE_LOCATION_DISTANCE_METERS)
return locationRepository.findAllByCoordinateAndDistanceInMeters(
coordinate.getCoordinate(), DUPLICATE_LOCATION_DISTANCE_METERS
)
.stream()
.filter(location -> location.isSameAddress(request.address()))
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class DatabaseCleanup implements InitializingBean {

private static final String TRUNCATE_SQL_MESSAGE = "TRUNCATE TABLE %s";
private static final String SET_REFERENTIAL_INTEGRITY_SQL_MESSAGE = "SET REFERENTIAL_INTEGRITY %s";
private static final String SET_REFERENTIAL_INTEGRITY_SQL_MESSAGE = "SET FOREIGN_KEY_CHECKS = %s";
private static final String DISABLE_REFERENTIAL_QUERY = String.format(SET_REFERENTIAL_INTEGRITY_SQL_MESSAGE, false);
private static final String ENABLE_REFERENTIAL_QUERY = String.format(SET_REFERENTIAL_INTEGRITY_SQL_MESSAGE, true);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mapbefine.mapbefine;

import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.MySQLContainer;


public abstract class TestDatabaseContainer {

private static final MySQLContainer mySQLContainer = new MySQLContainer("mysql:8.0.32");

static {
mySQLContainer.start();
}

@DynamicPropertySource
public static void overrideProps(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", mySQLContainer::getJdbcUrl);
registry.add("spring.datasource.username", mySQLContainer::getUsername);
registry.add("spring.datasource.password", mySQLContainer::getPassword);
registry.add("spring.datasource.driver-class-name", mySQLContainer::getDriverClassName);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.SoftAssertions.assertSoftly;

import com.mapbefine.mapbefine.TestDatabaseContainer;
import com.mapbefine.mapbefine.atlas.domain.Atlas;
import com.mapbefine.mapbefine.atlas.domain.AtlasRepository;
import com.mapbefine.mapbefine.bookmark.domain.Bookmark;
Expand Down Expand Up @@ -34,7 +35,7 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;

@ServiceTest
class AdminCommandServiceTest {
class AdminCommandServiceTest extends TestDatabaseContainer {

@Autowired
private AdminCommandService adminCommandService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.mapbefine.mapbefine.TestDatabaseContainer;
import com.mapbefine.mapbefine.admin.dto.AdminMemberDetailResponse;
import com.mapbefine.mapbefine.admin.dto.AdminMemberResponse;
import com.mapbefine.mapbefine.common.annotation.ServiceTest;
Expand All @@ -26,7 +27,7 @@
import org.springframework.beans.factory.annotation.Autowired;

@ServiceTest
class AdminQueryServiceTest {
class AdminQueryServiceTest extends TestDatabaseContainer {

@Autowired
private AdminQueryService adminQueryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.mapbefine.mapbefine.TestDatabaseContainer;
import com.mapbefine.mapbefine.atlas.domain.Atlas;
import com.mapbefine.mapbefine.atlas.domain.AtlasRepository;
import com.mapbefine.mapbefine.atlas.exception.AtlasException.AtlasForbiddenException;
Expand All @@ -27,7 +28,7 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;

@ServiceTest
class AtlasCommandServiceTest {
class AtlasCommandServiceTest extends TestDatabaseContainer {

@Autowired
private TopicRepository topicRepository;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.mapbefine.mapbefine.TestDatabaseContainer;
import com.mapbefine.mapbefine.admin.application.AdminCommandService;
import com.mapbefine.mapbefine.auth.domain.AuthMember;
import com.mapbefine.mapbefine.common.annotation.ServiceTest;
Expand All @@ -24,7 +25,7 @@
import org.springframework.transaction.annotation.Transactional;

@ServiceTest
class AuthServiceTest {
class AuthServiceTest extends TestDatabaseContainer {

@Autowired
private AuthService authService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.mapbefine.mapbefine.TestDatabaseContainer;
import com.mapbefine.mapbefine.auth.domain.token.RefreshToken;
import com.mapbefine.mapbefine.auth.domain.token.RefreshTokenRepository;
import com.mapbefine.mapbefine.auth.dto.LoginTokens;
import com.mapbefine.mapbefine.common.annotation.ServiceTest;
import com.mapbefine.mapbefine.member.MemberFixture;
import com.mapbefine.mapbefine.member.domain.Member;
import com.mapbefine.mapbefine.member.domain.MemberRepository;
Expand All @@ -22,9 +24,9 @@
import java.util.Date;
import java.util.Optional;

@DataJpaTest
@ServiceTest
@TestPropertySource(locations = "classpath:application.yml")
class TokenServiceTest {
class TokenServiceTest extends TestDatabaseContainer {

@Autowired
private RefreshTokenRepository refreshTokenRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.mapbefine.mapbefine.TestDatabaseContainer;
import com.mapbefine.mapbefine.auth.domain.AuthMember;
import com.mapbefine.mapbefine.bookmark.domain.Bookmark;
import com.mapbefine.mapbefine.bookmark.domain.BookmarkRepository;
Expand All @@ -21,7 +22,7 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;

@ServiceTest
class BookmarkCommandServiceTest {
class BookmarkCommandServiceTest extends TestDatabaseContainer {

@Autowired
private BookmarkCommandService bookmarkCommandService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbefine.mapbefine.common;

import com.mapbefine.mapbefine.DatabaseCleanup;
import com.mapbefine.mapbefine.TestDatabaseContainer;
import io.restassured.RestAssured;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -9,7 +10,7 @@
import org.springframework.boot.test.web.server.LocalServerPort;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class IntegrationTest {
public class IntegrationTest extends TestDatabaseContainer {

@Autowired
protected TestAuthHeaderProvider testAuthHeaderProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mapbefine.mapbefine.TestDatabaseContainer;
import com.mapbefine.mapbefine.common.interceptor.AuthInterceptor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -26,7 +27,7 @@
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
@AutoConfigureRestDocs
public abstract class RestDocsIntegration {
public abstract class RestDocsIntegration extends TestDatabaseContainer {

@Autowired
protected ObjectMapper objectMapper;
Expand Down
Loading

0 comments on commit 3592ff0

Please sign in to comment.