Skip to content

Commit

Permalink
Merge pull request #111 from Na-o-man/feature/#104/add_dowload_tag_es…
Browse files Browse the repository at this point in the history
…_logic

[Feat] 사진 다운로드 시, photos_es에 다운로드 멤버 아이디 추가
  • Loading branch information
bflykky authored Aug 13, 2024
2 parents 2051ba4 + 8ba9242 commit 9585288
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 @@ -265,6 +268,39 @@ public List<Long> deletePhotoEsByShareGroupId(Long shareGroupId) {
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 9585288

Please sign in to comment.