Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 条目收藏和条目更新相关问题. #678

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

更新日志文档,版本顺序从新到旧,最新版本在最前(上)面。

# 0.15.10

## 问题修复

- 修复条目收藏的异常问题 674
- 修复条目移除后未移除对应收藏的问题 674
- 条目更新封面字段时异常移除相关条目封面字段 #675

# 0.15.9

- 支持Prometheus的指标聚合API #676
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.15.9
version=0.15.10
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ public Mono<Void> onSubjectCoverUpdate(SubjectUpdateEvent event) {

return attachmentRepository.findByUrl(oldCover)
.map(AttachmentEntity::getId)
.flatMapMany(attachmentReferenceRepository::deleteAllByAttachmentId)
.flatMap(oldCoverAttId -> attachmentReferenceRepository
.deleteByTypeAndAttachmentIdAndReferenceId(
AttachmentReferenceType.SUBJECT,
oldEntity.getId(),
oldCoverAttId
).doOnSuccess(unused ->
log.debug("Delete attachment Reference by type and att id and sub id.")))
// update new attachment that move to cover dir
.then(attachmentRepository.findByTypeAndParentIdAndName(AttachmentType.Directory,
AttachmentConst.ROOT_DIRECTORY_ID, AttachmentConst.COVER_DIR_NAME))
Expand All @@ -91,12 +97,20 @@ public Mono<Void> onSubjectCoverUpdate(SubjectUpdateEvent event) {
.map(entity -> entity.setParentId(coverDirAttId)))
.flatMap(attachmentRepository::save)
.map(AttachmentEntity::getId)
.map(attId -> AttachmentReferenceEntity.builder()
.type(AttachmentReferenceType.SUBJECT)
.attachmentId(attId)
.referenceId(newEntity.getId())
.build())
.flatMap(attachmentReferenceRepository::save)
.flatMap(attId -> attachmentReferenceRepository
.findByTypeAndAttachmentIdAndReferenceId(AttachmentReferenceType.SUBJECT,
attId, newEntity.getId())
.switchIfEmpty(attachmentReferenceRepository.save(
AttachmentReferenceEntity.builder()
.type(AttachmentReferenceType.SUBJECT)
.attachmentId(attId)
.referenceId(newEntity.getId())
.build()
).doOnSuccess(entity ->
log.debug("Create attachment Reference by type and att id and sub id: [{}].",
entity)))
)

.then();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package run.ikaros.server.core.collection;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import run.ikaros.server.core.subject.event.SubjectRemoveEvent;
import run.ikaros.server.store.entity.SubjectEntity;
import run.ikaros.server.store.repository.SubjectCollectionRepository;

@Slf4j
@Component
public class CollectionSubjectRemoveEventListener {
private final SubjectCollectionRepository subjectCollectionRepository;

public CollectionSubjectRemoveEventListener(
SubjectCollectionRepository subjectCollectionRepository) {
this.subjectCollectionRepository = subjectCollectionRepository;
}

/**
* Listen subject remove event.
*/
@EventListener(SubjectRemoveEvent.class)
public Mono<Void> onSubjectAdd(SubjectRemoveEvent event) {
SubjectEntity entity = event.getEntity();
if (entity == null) {
return Mono.empty();
}
return subjectCollectionRepository.removeAllBySubjectId(entity.getId())
.doOnSuccess(unused -> log.debug("Subject collections removed by subject id: {}",
entity.getId()))
.then();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ public Mono<SubjectCollection> findCollection(Long userId, Long subjectId) {
Assert.isTrue(subjectId >= 0, "'subjectId' must >= 0");
return checkUserIdExists(userId)
.then(subjectRepository.findById(subjectId))
.switchIfEmpty(Mono.error(
new SubjectNotFoundException("Subject not found for id: " + subjectId)))
.flatMap(subjectEntity -> copyProperties(subjectEntity, new SubjectCollection()))
.flatMap(subjectCollection ->
subjectCollectionRepository.findByUserIdAndSubjectId(userId, subjectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Mono<Void> collect(Long userId, Long subjectId,
@Transactional
Mono<Void> unCollect(Long userId, Long subjectId);

/**
* Find subject collection with userId and subjectId.
*
* @param userId user id
* @param subjectId subject id
* @return subject collection or null
*/
Mono<SubjectCollection> findCollection(Long userId, Long subjectId);

Mono<PagingWrap<SubjectCollection>> findCollections(Long userId, Integer page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface SubjectCollectionRepository
Mono<Long> countAllByUserId(Long userId);

Mono<Long> countByType(CollectionType type);

Mono<Void> removeAllBySubjectId(Long subjectId);
}
Loading