diff --git a/app/server/huntly-server/src/main/java/com/huntly/server/repository/PageRepository.java b/app/server/huntly-server/src/main/java/com/huntly/server/repository/PageRepository.java index f45108a..b6f1ea9 100644 --- a/app/server/huntly-server/src/main/java/com/huntly/server/repository/PageRepository.java +++ b/app/server/huntly-server/src/main/java/com/huntly/server/repository/PageRepository.java @@ -51,4 +51,14 @@ public interface PageRepository extends JpaRepository, 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); } \ No newline at end of file diff --git a/app/server/huntly-server/src/main/java/com/huntly/server/service/FeedsService.java b/app/server/huntly-server/src/main/java/com/huntly/server/service/FeedsService.java index c04f486..6dd8c1c 100644 --- a/app/server/huntly-server/src/main/java/com/huntly/server/service/FeedsService.java +++ b/app/server/huntly-server/src/main/java/com/huntly/server/service/FeedsService.java @@ -8,6 +8,7 @@ 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; @@ -15,6 +16,7 @@ import org.springframework.stereotype.Service; import java.time.Instant; +import java.util.Objects; /** * @author lcomplete @@ -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) { @@ -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) {