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:
@@ -74,7 +74,27 @@ paths:
|
|||||||
"500":
|
"500":
|
||||||
description: Internal server error
|
description: Internal server error
|
||||||
$ref: "#/components/responses/BadResponse"
|
$ref: "#/components/responses/BadResponse"
|
||||||
|
/event/local_storage/{serial}:
|
||||||
|
delete:
|
||||||
|
summary: Delete an event
|
||||||
|
description: Delete an event
|
||||||
|
operationId: deleteEventBySerial
|
||||||
|
tags:
|
||||||
|
- event
|
||||||
|
parameters:
|
||||||
|
- $ref: "#/components/parameters/serial"
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Event deleted
|
||||||
|
$ref: "#/components/responses/OKResponse"
|
||||||
|
"401":
|
||||||
|
description: Event not found
|
||||||
|
"404":
|
||||||
|
description: Event not found
|
||||||
|
$ref: "#/components/responses/ResponseNotFound"
|
||||||
|
"500":
|
||||||
|
$ref: "#/components/responses/BadResponse"
|
||||||
|
description: Internal server error
|
||||||
components:
|
components:
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
access_token:
|
access_token:
|
||||||
@@ -82,6 +102,14 @@ components:
|
|||||||
in: header
|
in: header
|
||||||
name: Authorization
|
name: Authorization
|
||||||
parameters:
|
parameters:
|
||||||
|
serial:
|
||||||
|
name: serial
|
||||||
|
in: path
|
||||||
|
description: Serial of the local storage
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
example: "1234567890"
|
||||||
event_uuid:
|
event_uuid:
|
||||||
name: event_uuid
|
name: event_uuid
|
||||||
in: path
|
in: path
|
||||||
@@ -92,6 +120,13 @@ components:
|
|||||||
format: uuid
|
format: uuid
|
||||||
example: 123e4567-e89b-12d3-a456-426655440000
|
example: 123e4567-e89b-12d3-a456-426655440000
|
||||||
responses:
|
responses:
|
||||||
|
OKResponse:
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
$ref: "#/components/schemas/BaseResponse"
|
||||||
DeleteEventOK:
|
DeleteEventOK:
|
||||||
description: Event deleted
|
description: Event deleted
|
||||||
content:
|
content:
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
After=casaos-gateway.service
|
After=casaos-gateway.service
|
||||||
|
After=casaos-message-bus.service
|
||||||
|
After=casaos-local-storage.service
|
||||||
ConditionFileNotEmpty=/etc/casaos/user-service.conf
|
ConditionFileNotEmpty=/etc/casaos/user-service.conf
|
||||||
Description=CasaOS User Service
|
Description=CasaOS User Service
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/IceWhaleTech/CasaOS-Common/external"
|
"github.com/IceWhaleTech/CasaOS-Common/external"
|
||||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||||
@@ -17,6 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func EventListen() {
|
func EventListen() {
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
|
||||||
messageBusUrl, err := external.GetMessageBusAddress(config.CommonInfo.RuntimePath)
|
messageBusUrl, err := external.GetMessageBusAddress(config.CommonInfo.RuntimePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -28,6 +30,8 @@ func EventListen() {
|
|||||||
ws, err := websocket.Dial(wsURL, "", "http://localhost")
|
ws, err := websocket.Dial(wsURL, "", "http://localhost")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("connect websocket err", zap.Any("error", err))
|
logger.Error("connect websocket err", zap.Any("error", err))
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
defer ws.Close()
|
defer ws.Close()
|
||||||
|
|
||||||
@@ -62,4 +66,5 @@ func EventListen() {
|
|||||||
}
|
}
|
||||||
log.Println(string(output))
|
log.Println(string(output))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,3 +18,7 @@ func (s *UserService) GetEvents(ctx echo.Context, params codegen.GetEventsParams
|
|||||||
list := service.MyService.Event().GetEvents()
|
list := service.MyService.Event().GetEvents()
|
||||||
return ctx.JSON(http.StatusOK, list)
|
return ctx.JSON(http.StatusOK, list)
|
||||||
}
|
}
|
||||||
|
func (s *UserService) DeleteEventBySerial(ctx echo.Context, serial codegen.Serial) error {
|
||||||
|
service.MyService.Event().DeleteEventBySerial(serial)
|
||||||
|
return ctx.JSON(http.StatusOK, serial)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/IceWhaleTech/CasaOS-UserService/model"
|
"github.com/IceWhaleTech/CasaOS-UserService/model"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -10,6 +12,7 @@ type EventService interface {
|
|||||||
GetEvents() (list []model.EventModel)
|
GetEvents() (list []model.EventModel)
|
||||||
GetEventByUUID(uuid string) (m model.EventModel)
|
GetEventByUUID(uuid string) (m model.EventModel)
|
||||||
DeleteEvent(uuid string)
|
DeleteEvent(uuid string)
|
||||||
|
DeleteEventBySerial(serial string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type eventService struct {
|
type eventService struct {
|
||||||
@@ -31,7 +34,23 @@ func (e *eventService) GetEventByUUID(uuid string) (m model.EventModel) {
|
|||||||
func (e *eventService) DeleteEvent(uuid string) {
|
func (e *eventService) DeleteEvent(uuid string) {
|
||||||
e.db.Where("uuid = ?", uuid).Delete(&model.EventModel{})
|
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 {
|
func NewEventService(db *gorm.DB) EventService {
|
||||||
return &eventService{db: db}
|
return &eventService{db: db}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user