Skip to content

Commit

Permalink
feat : 사진 다운로드 시, photos_es에 download 태그 추가하는 로직 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
redblackblossom committed Aug 13, 2024
1 parent 4606e16 commit 8277cd4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import co.elastic.clients.elasticsearch.core.BulkResponse;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import co.elastic.clients.json.JsonData;
import com.umc.naoman.domain.photo.elasticsearch.document.PhotoEs;
import com.umc.naoman.domain.photo.entity.Photo;
import com.umc.naoman.global.error.BusinessException;
Expand All @@ -21,7 +22,9 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Repository
Expand Down Expand Up @@ -268,6 +271,39 @@ public List<Long> deletePhotoEsByShareGroupIdList(List<Long> shareGroupIdList) {
return rdsIdList;
}

//특정 사진에 특정 맴버 다운로드 태그 추가
public void addDownloadTag(List<PhotoEs> photoEs, Long memberId){
List<FieldValue> fieldValueList = photoEs.stream()
.map(photo -> FieldValue.of(photo.getName()))
.toList();
String routing = photoEs.get(0).getShareGroupId().toString();
Map<String, JsonData> params = new HashMap<>();
params.put("memberId", JsonData.of(memberId));
try {
elasticsearchClient.updateByQuery(u -> u
.index("photos_es")
.routing(routing)
.query(q -> q
.terms(t -> t
.field("name")
.terms(te -> te.value(fieldValueList))
)
)
.script(s -> s
.inline(i->i
.source("if (!ctx._source.downloadTag.contains(params.memberId)) { " +
"ctx._source.downloadTag.add(params.memberId); }")
.lang("painless")
.params(params)
)

)
);
} catch (IOException e) {
throw new BusinessException(ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION, e);
}
}

String esTimeFormat(LocalDateTime localDateTime) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return localDateTime.format(dateTimeFormatter);
Expand Down

This file was deleted.

0 comments on commit 8277cd4

Please sign in to comment.