-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MATE-153 : [!BUGFIX] 굿즈거래 채팅 저장 오류 및 MongoDB 시간 설정 오류 해결 (#137)
* MATE-153 : [!BUGFIX] 굿즈거래 시스템 메시지 저장 오류 해결 * MATE-153 : [FEAT] LocalDateTime 을 KST Date 타입으로 바꿔주는 컨버터 클래스 구현 * MATE-153 : [CHORE] validator 패키지 위치 변경 * MATE-153 : [FEAT] MongoConfig 클래스 컨버터 설정 추가
- Loading branch information
Showing
22 changed files
with
87 additions
and
21 deletions.
There are no files selected for viewing
19 changes: 17 additions & 2 deletions
19
src/main/java/com/example/mate/common/config/MongoConfig.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,24 +1,39 @@ | ||
package com.example.mate.common.config; | ||
|
||
import com.example.mate.common.util.converter.DateToLocalDateTimeKstConverter; | ||
import com.example.mate.common.util.converter.LocalDateTimeToDateKstConverter; | ||
import java.util.List; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.mongodb.MongoDatabaseFactory; | ||
import org.springframework.data.mongodb.core.convert.DbRefResolver; | ||
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver; | ||
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper; | ||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter; | ||
import org.springframework.data.mongodb.core.convert.MongoCustomConversions; | ||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext; | ||
|
||
@Configuration | ||
public class MongoConfig { | ||
|
||
@Bean | ||
public MappingMongoConverter mappingMongoConverter(MongoDatabaseFactory mongoDatabaseFactory, | ||
MongoMappingContext mongoMappingContext) { | ||
public MappingMongoConverter mappingMongoConverter( | ||
MongoDatabaseFactory mongoDatabaseFactory, | ||
MongoMappingContext mongoMappingContext, | ||
LocalDateTimeToDateKstConverter dateKstConverter, | ||
DateToLocalDateTimeKstConverter localDateTimeKstConverter | ||
) { | ||
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDatabaseFactory); | ||
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext); | ||
|
||
// "_class" 타입을 저장하지 않도록 설정 | ||
converter.setTypeMapper(new DefaultMongoTypeMapper(null)); | ||
|
||
// MongoDB KST 변환 컨버터 설정 | ||
converter.setCustomConversions(new MongoCustomConversions( | ||
List.of(localDateTimeKstConverter, dateKstConverter) | ||
)); | ||
|
||
return converter; | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/example/mate/common/util/converter/DateToLocalDateTimeKstConverter.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,26 @@ | ||
package com.example.mate.common.util.converter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.util.Date; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.data.convert.ReadingConverter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@ReadingConverter | ||
public class DateToLocalDateTimeKstConverter implements Converter<Date, LocalDateTime> { | ||
|
||
private static final int KST_OFFSET_HOURS = 9; | ||
|
||
@Override | ||
public LocalDateTime convert(Date source) { | ||
return convertToKst(source); | ||
} | ||
|
||
// KST 로 변환하기 위해 9시간을 빼줌 | ||
private LocalDateTime convertToKst(Date date) { | ||
LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); | ||
return localDateTime.minusHours(KST_OFFSET_HOURS); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/example/mate/common/util/converter/LocalDateTimeToDateKstConverter.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,25 @@ | ||
package com.example.mate.common.util.converter; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.data.convert.WritingConverter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@WritingConverter | ||
public class LocalDateTimeToDateKstConverter implements Converter<LocalDateTime, Date> { | ||
|
||
private static final int KST_OFFSET_HOURS = 9; | ||
|
||
@Override | ||
public Date convert(LocalDateTime source) { | ||
return convertToKst(source); | ||
} | ||
|
||
// KST 로 변환하기 위해 9시간을 더함 | ||
private Date convertToKst(LocalDateTime localDateTime) { | ||
return Timestamp.valueOf(localDateTime.plusHours(KST_OFFSET_HOURS)); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../mate/common/validator/EnumValidator.java → .../common/util/validator/EnumValidator.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
...mple/mate/common/validator/ValidEnum.java → ...mate/common/util/validator/ValidEnum.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
.../mate/common/validator/ValidPageable.java → .../common/util/validator/ValidPageable.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
...idator/ValidPageableArgumentResolver.java → ...idator/ValidPageableArgumentResolver.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
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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/example/mate/domain/goodsPost/dto/request/GoodsPostRequest.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
src/main/java/com/example/mate/domain/goodsReview/dto/request/GoodsReviewRequest.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
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
src/main/java/com/example/mate/domain/matePost/dto/request/MatePostCreateRequest.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
src/main/java/com/example/mate/domain/matePost/dto/request/MatePostSearchRequest.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
src/main/java/com/example/mate/domain/matePost/dto/request/MatePostStatusRequest.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
src/main/java/com/example/mate/domain/matePost/dto/request/MatePostUpdateRequest.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
src/main/java/com/example/mate/domain/mateReview/dto/request/MateReviewCreateRequest.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
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