mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-10-06 19:59:42 +07:00
add message_bus service dependency (#25)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-UserService/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -10,6 +12,7 @@ type EventService interface {
|
||||
GetEvents() (list []model.EventModel)
|
||||
GetEventByUUID(uuid string) (m model.EventModel)
|
||||
DeleteEvent(uuid string)
|
||||
DeleteEventBySerial(serial string)
|
||||
}
|
||||
|
||||
type eventService struct {
|
||||
@@ -31,7 +34,23 @@ func (e *eventService) GetEventByUUID(uuid string) (m model.EventModel) {
|
||||
func (e *eventService) DeleteEvent(uuid string) {
|
||||
e.db.Where("uuid = ?", uuid).Delete(&model.EventModel{})
|
||||
}
|
||||
func (e *eventService) DeleteEventBySerial(serial string) {
|
||||
list := []model.EventModel{}
|
||||
e.db.Find(&list)
|
||||
for _, v := range list {
|
||||
|
||||
if v.SourceID == "local-storage" {
|
||||
properties := make(map[string]string)
|
||||
err := json.Unmarshal([]byte(v.Properties), &properties)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if properties["serial"] == serial {
|
||||
e.db.Delete(&v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func NewEventService(db *gorm.DB) EventService {
|
||||
return &eventService{db: db}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user