Skip to content

Commit

Permalink
fix: rss folder change, rss deleted, change page folderid etc...
Browse files Browse the repository at this point in the history
  • Loading branch information
lcomplete committed Mar 27, 2023
1 parent 3c3f755 commit 16587c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ public interface PageRepository extends JpaRepository<Page, Long>, JpaSpecificat
@Transactional
@Query("UPDATE Page p SET p.markRead = :markRead WHERE p.markRead <> :markRead and p.connectorType = :connectorType")
int updateMarkReadByConnectorType(Integer connectorType, boolean markRead);

@Transactional
@Modifying(clearAutomatically = true)
@Query("UPDATE Page p SET p.folderId = :folderId WHERE p.connectorId = :connectorId")
void updateFolderIdByConnectorId(Integer connectorId, Integer folderId);

@Transactional
@Modifying(clearAutomatically = true)
@Query("UPDATE Page p SET p.folderId = null, p.connectorId = null, p.connectorType = null WHERE p.connectorId = :connectorId")
void deleteConnectorId(Integer connectorId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import com.huntly.server.domain.constant.AppConstants;
import com.huntly.server.domain.entity.Connector;
import com.huntly.server.repository.ConnectorRepository;
import com.huntly.server.repository.PageRepository;
import com.huntly.server.util.HttpUtils;
import com.huntly.server.util.SiteUtils;
import com.rometools.rome.feed.synd.SyndFeed;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.Objects;

/**
* @author lcomplete
Expand All @@ -29,11 +31,14 @@ public class FeedsService {

private final GlobalSettingService globalSettingService;

public FeedsService(ConnectorService connectorService, ConnectorFetchService connectorFetchService, ConnectorRepository connectorRepository, GlobalSettingService globalSettingService) {
private final PageRepository pageRepository;

public FeedsService(ConnectorService connectorService, ConnectorFetchService connectorFetchService, ConnectorRepository connectorRepository, GlobalSettingService globalSettingService, PageRepository pageRepository) {
this.connectorService = connectorService;
this.connectorFetchService = connectorFetchService;
this.connectorRepository = connectorRepository;
this.globalSettingService = globalSettingService;
this.pageRepository = pageRepository;
}

public Connector followFeed(String subscribeUrl) {
Expand Down Expand Up @@ -97,18 +102,24 @@ private Connector requireOneFeedConnector(Integer connectorId) {

public Connector updateFeedsSetting(FeedsSetting feedsSetting) {
Connector connector = requireOneFeedConnector(feedsSetting.getConnectorId());
Integer rawFolderId = connector.getFolderId();
connector.setCrawlFullContent(feedsSetting.getCrawlFullContent());
connector.setName(feedsSetting.getName());
connector.setEnabled(feedsSetting.getEnabled());
connector.setSubscribeUrl(feedsSetting.getSubscribeUrl());
connector.setFolderId(feedsSetting.getFolderId() == null || feedsSetting.getFolderId().equals(0) ? null : feedsSetting.getFolderId());
connector.setFetchIntervalSeconds(feedsSetting.getFetchIntervalMinutes() * 60);
return connectorRepository.save(connector);
var result = connectorRepository.save(connector);
if (!Objects.equals(rawFolderId, connector.getFolderId())) {
pageRepository.updateFolderIdByConnectorId(connector.getId(), connector.getFolderId());
}
return result;
}

public void delete(Integer connectorId) {
Connector connector = requireOneFeedConnector(connectorId);
connectorRepository.delete(connector);
pageRepository.deleteConnectorId(connectorId);
}

public FeedsSetting getFeedsSetting(Integer connectorId) {
Expand Down

0 comments on commit 16587c2

Please sign in to comment.