2026-04-28 17:29:17 +08:00
|
|
|
package com.xuqm.im.service;
|
|
|
|
|
|
|
|
|
|
import com.xuqm.common.exception.BusinessException;
|
|
|
|
|
import com.xuqm.im.entity.WebhookConfigEntity;
|
|
|
|
|
import com.xuqm.im.repository.WebhookConfigRepository;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class WebhookConfigService {
|
|
|
|
|
|
|
|
|
|
private final WebhookConfigRepository repository;
|
|
|
|
|
|
|
|
|
|
public WebhookConfigService(WebhookConfigRepository repository) {
|
|
|
|
|
this.repository = repository;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 19:39:42 +08:00
|
|
|
public List<WebhookConfigEntity> list(String appKey) {
|
|
|
|
|
return repository.findByAppId(appKey);
|
2026-04-28 17:29:17 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-07 19:39:42 +08:00
|
|
|
public WebhookConfigEntity get(String appKey, String id) {
|
|
|
|
|
return repository.findByIdAndAppId(id, appKey)
|
2026-05-02 22:57:55 +08:00
|
|
|
.orElseThrow(() -> new BusinessException(404, "回调配置不存在"));
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 19:39:42 +08:00
|
|
|
public WebhookConfigEntity create(String appKey, String url, String secret, Boolean enabled) {
|
2026-04-28 17:29:17 +08:00
|
|
|
WebhookConfigEntity entity = new WebhookConfigEntity();
|
|
|
|
|
entity.setId(UUID.randomUUID().toString());
|
2026-05-07 19:39:42 +08:00
|
|
|
entity.setAppId(appKey);
|
2026-04-28 17:29:17 +08:00
|
|
|
entity.setUrl(url);
|
|
|
|
|
entity.setSecret(secret);
|
|
|
|
|
entity.setEnabled(enabled == null || enabled);
|
|
|
|
|
entity.setCreatedAt(LocalDateTime.now());
|
|
|
|
|
return repository.save(entity);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 19:39:42 +08:00
|
|
|
public WebhookConfigEntity update(String appKey, String id, String url, String secret, Boolean enabled) {
|
|
|
|
|
WebhookConfigEntity entity = repository.findByIdAndAppId(id, appKey)
|
2026-04-28 17:29:17 +08:00
|
|
|
.orElseThrow(() -> new BusinessException(404, "回调配置不存在"));
|
|
|
|
|
if (url != null) {
|
|
|
|
|
entity.setUrl(url);
|
|
|
|
|
}
|
|
|
|
|
if (secret != null) {
|
|
|
|
|
entity.setSecret(secret);
|
|
|
|
|
}
|
|
|
|
|
if (enabled != null) {
|
|
|
|
|
entity.setEnabled(enabled);
|
|
|
|
|
}
|
|
|
|
|
return repository.save(entity);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 19:39:42 +08:00
|
|
|
public void delete(String appKey, String id) {
|
|
|
|
|
WebhookConfigEntity entity = repository.findByIdAndAppId(id, appKey)
|
2026-04-28 17:29:17 +08:00
|
|
|
.orElseThrow(() -> new BusinessException(404, "回调配置不存在"));
|
|
|
|
|
repository.delete(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|