-
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.
Browse files
Browse the repository at this point in the history
feature: AI코칭 기능 업데이트 및 몽고디비 연동
- Loading branch information
Showing
26 changed files
with
265 additions
and
192 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
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
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
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
50 changes: 50 additions & 0 deletions
50
...mongodb/src/main/java/com/smeem/output/persistence/mongodb/adapter/CorrectionAdapter.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,50 @@ | ||
package com.smeem.output.persistence.mongodb.adapter; | ||
|
||
import com.smeem.application.domain.diary.Correction; | ||
import com.smeem.application.domain.diary.Diary; | ||
import com.smeem.application.port.output.persistence.CorrectionPort; | ||
import com.smeem.output.persistence.mongodb.persistence.document.CorrectionDocument; | ||
import com.smeem.output.persistence.mongodb.persistence.repository.CorrectionRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CorrectionAdapter implements CorrectionPort { | ||
private final CorrectionRepository correctionRepository; | ||
|
||
@Override | ||
public List<Correction> save(List<Correction> corrections, Diary diary) { | ||
CorrectionDocument savedCorrection = correctionRepository.save(new CorrectionDocument(corrections, diary)); | ||
return savedCorrection.toDomain(); | ||
} | ||
|
||
@Override | ||
public int countDistinctByMemberAndDate(long memberId, LocalDate date) { | ||
LocalDateTime startOfDay = date.atStartOfDay(); | ||
LocalDateTime endOfDay = date.plusDays(1).atStartOfDay(); | ||
return correctionRepository.countByMemberIdAndCreatedAtBetween(memberId, startOfDay, endOfDay); | ||
} | ||
|
||
@Override | ||
public List<Correction> findByDiary(long diaryId) { | ||
return correctionRepository.findByDiaryId(diaryId) | ||
.map(CorrectionDocument::toDomain) | ||
.orElseGet(ArrayList::new); | ||
} | ||
|
||
@Override | ||
public void deleteByDiary(long diaryId) { | ||
correctionRepository.deleteByDiaryId(diaryId); | ||
} | ||
|
||
@Override | ||
public void deleteByMember(long memberId) { | ||
correctionRepository.deleteByMemberId(memberId); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...stence/mongodb/src/main/java/com/smeem/output/persistence/mongodb/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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.smeem.output.persistence.mongodb.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.mongodb.MongoDatabaseFactory; | ||
import org.springframework.data.mongodb.config.EnableMongoAuditing; | ||
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.mapping.MongoMappingContext; | ||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; | ||
|
||
@Configuration | ||
@EnableMongoAuditing | ||
@EnableMongoRepositories(basePackages = "com.smeem.output.persistence.mongodb") | ||
public class MongoConfig { | ||
|
||
@Bean | ||
public MappingMongoConverter mappingMongoConverter( | ||
MongoDatabaseFactory mongoDatabaseFactory, | ||
MongoMappingContext mongoMappingContext | ||
) { | ||
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDatabaseFactory); | ||
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext); | ||
converter.setTypeMapper(new DefaultMongoTypeMapper(null)); | ||
return converter; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...in/java/com/smeem/output/persistence/mongodb/persistence/document/CorrectionDocument.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,61 @@ | ||
package com.smeem.output.persistence.mongodb.persistence.document; | ||
|
||
import com.smeem.application.domain.diary.Correction; | ||
import com.smeem.application.domain.diary.Diary; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Document(collection = "smeem") | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class CorrectionDocument { | ||
@Id | ||
private String id; | ||
private List<CorrectionDetail> corrections; | ||
private long memberId; | ||
private long diaryId; | ||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
private static class CorrectionDetail { | ||
private String originContent; | ||
private String correctedContent; | ||
private String reason; | ||
private boolean corrected; | ||
|
||
public CorrectionDetail(Correction correction) { | ||
this.originContent = correction.originalSentence(); | ||
this.correctedContent = correction.correctedSentence(); | ||
this.corrected = correction.isCorrected(); | ||
this.reason = corrected ? correction.reason() : null; | ||
} | ||
|
||
public Correction toDomain() { | ||
return Correction.builder() | ||
.originalSentence(originContent) | ||
.correctedSentence(correctedContent) | ||
.reason(reason) | ||
.isCorrected(corrected) | ||
.build(); | ||
} | ||
} | ||
|
||
public CorrectionDocument(List<Correction> corrections, Diary diary) { | ||
this.corrections = corrections.stream().map(CorrectionDetail::new).toList(); | ||
this.memberId = diary.getMemberId(); | ||
this.diaryId = diary.getId(); | ||
} | ||
|
||
public List<Correction> toDomain() { | ||
return this.corrections.stream().map(CorrectionDetail::toDomain).toList(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ava/com/smeem/output/persistence/mongodb/persistence/repository/CorrectionRepository.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,19 @@ | ||
package com.smeem.output.persistence.mongodb.persistence.repository; | ||
|
||
import com.smeem.output.persistence.mongodb.persistence.document.CorrectionDocument; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface CorrectionRepository extends MongoRepository<CorrectionDocument, String> { | ||
int countByMemberIdAndCreatedAtBetween(long memberId, LocalDateTime startAt, LocalDateTime endAt); | ||
|
||
Optional<CorrectionDocument> findByDiaryId(long diaryId); | ||
|
||
void deleteByDiaryId(long diaryId); | ||
|
||
void deleteByMemberId(long memberId); | ||
} |
8 changes: 8 additions & 0 deletions
8
smeem-output-persistence/mongodb/src/main/resources/mongo-config/application-dev.yml
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,8 @@ | ||
spring: | ||
config: | ||
activate: | ||
on-profile: dev | ||
|
||
data: | ||
mongodb: | ||
uri: mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:27017/smeem?authSource=admin |
8 changes: 8 additions & 0 deletions
8
smeem-output-persistence/mongodb/src/main/resources/mongo-config/application-local.yml
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,8 @@ | ||
spring: | ||
config: | ||
activate: | ||
on-profile: local | ||
|
||
data: | ||
mongodb: | ||
uri: mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:27017/smeem?authSource=admin |
8 changes: 8 additions & 0 deletions
8
smeem-output-persistence/mongodb/src/main/resources/mongo-config/application-prod.yml
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,8 @@ | ||
spring: | ||
config: | ||
activate: | ||
on-profile: prod | ||
|
||
data: | ||
mongodb: | ||
uri: mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:27017/smeem?authSource=admin |
42 changes: 0 additions & 42 deletions
42
.../postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/CorrectionAdapter.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
Oops, something went wrong.