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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<WebhookConfigEntity> list(String appId) {
|
|
|
|
|
return repository.findByAppId(appId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-02 22:57:55 +08:00
|
|
|
public WebhookConfigEntity get(String appId, String id) {
|
|
|
|
|
return repository.findByIdAndAppId(id, appId)
|
|
|
|
|
.orElseThrow(() -> new BusinessException(404, "回调配置不存在"));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 17:29:17 +08:00
|
|
|
public WebhookConfigEntity create(String appId, String url, String secret, Boolean enabled) {
|
|
|
|
|
WebhookConfigEntity entity = new WebhookConfigEntity();
|
|
|
|
|
entity.setId(UUID.randomUUID().toString());
|
|
|
|
|
entity.setAppId(appId);
|
|
|
|
|
entity.setUrl(url);
|
|
|
|
|
entity.setSecret(secret);
|
|
|
|
|
entity.setEnabled(enabled == null || enabled);
|
|
|
|
|
entity.setCreatedAt(LocalDateTime.now());
|
|
|
|
|
return repository.save(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WebhookConfigEntity update(String appId, String id, String url, String secret, Boolean enabled) {
|
|
|
|
|
WebhookConfigEntity entity = repository.findByIdAndAppId(id, appId)
|
|
|
|
|
.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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void delete(String appId, String id) {
|
|
|
|
|
WebhookConfigEntity entity = repository.findByIdAndAppId(id, appId)
|
|
|
|
|
.orElseThrow(() -> new BusinessException(404, "回调配置不存在"));
|
|
|
|
|
repository.delete(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|