mirror of
https://github.com/iflytek/skillhub.git
synced 2026-08-28 11:25:00 +00:00
feat(subscription): add increment/decrement subscription count methods
This commit is contained in:
parent
79f1aa4db1
commit
9d4422cd6c
3 changed files with 22 additions and 0 deletions
|
|
@ -22,6 +22,8 @@ public interface SkillRepository {
|
|||
List<Skill> findByOwnerId(String ownerId);
|
||||
Page<Skill> findByOwnerId(String ownerId, Pageable pageable);
|
||||
void incrementDownloadCount(Long skillId);
|
||||
void incrementSubscriptionCount(Long skillId);
|
||||
void decrementSubscriptionCount(Long skillId);
|
||||
List<Skill> findBySlug(String slug);
|
||||
List<Skill> findByNamespaceSlugAndSlug(String namespaceSlug, String slug);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,16 @@ public class JpaSkillRepositoryAdapter implements SkillRepository {
|
|||
delegate.incrementDownloadCount(skillId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementSubscriptionCount(Long skillId) {
|
||||
delegate.incrementSubscriptionCount(skillId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementSubscriptionCount(Long skillId) {
|
||||
delegate.decrementSubscriptionCount(skillId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Skill> findBySlug(String slug) {
|
||||
return delegate.findBySlug(slug);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,16 @@ public interface SkillJpaRepository extends JpaRepository<Skill, Long>, SkillRep
|
|||
@Query("UPDATE Skill s SET s.downloadCount = s.downloadCount + 1 WHERE s.id = :skillId")
|
||||
void incrementDownloadCount(@Param("skillId") Long skillId);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("UPDATE Skill s SET s.subscriptionCount = s.subscriptionCount + 1 WHERE s.id = :skillId")
|
||||
void incrementSubscriptionCount(@Param("skillId") Long skillId);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("UPDATE Skill s SET s.subscriptionCount = CASE WHEN s.subscriptionCount > 0 THEN s.subscriptionCount - 1 ELSE 0 END WHERE s.id = :skillId")
|
||||
void decrementSubscriptionCount(@Param("skillId") Long skillId);
|
||||
|
||||
List<Skill> findBySlug(String slug);
|
||||
|
||||
@Query("SELECT s FROM Skill s JOIN Namespace n ON s.namespaceId = n.id WHERE n.slug = :namespaceSlug AND s.slug = :slug")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue