omv intergration

This commit is contained in:
2024-07-03 17:58:27 +07:00
parent f0d6780c12
commit dd3a9ebea4
8 changed files with 281 additions and 9 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ package model
import "time"
//Soon to be removed
// Soon to be removed
type UserDBModel struct {
Id int `gorm:"column:id;primary_key" json:"id"`
Username string `json:"username"`
+87
View File
@@ -0,0 +1,87 @@
package service
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/IceWhaleTech/CasaOS-UserService/service/model"
)
type OMVService interface {
LoginSession(userName string, password string) string
Logout()
GetUser(username string) string
SetUser(m model.UserDBModel) model.UserDBModel
ApplyChange()
}
type omvService struct {
}
// LoginSession implements OMVService.
func (o *omvService) LoginSession(userName string, password string) string {
panic("unimplemented")
}
func LoginSession(username string, password string) string {
postBody, _ := json.Marshal(map[string]interface{}{
"service": "session",
"method": "login",
"params": map[string]string{
"username": username,
"password": password,
},
})
responseBody := bytes.NewBuffer(postBody)
response, err := http.Post("http://10.0.0.4:1081/rpc.php", "application/json", responseBody)
if err != nil {
fmt.Print(err.Error())
os.Exit(1)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
return string(responseData)
}
func (o *omvService) Logout() {
// Implement logout logic here
}
func (o *omvService) GetUser(username string) string {
postBody, _ := json.Marshal(map[string]interface{}{
"service": "UserMgmt",
"method": "getUser",
"params": map[string]string{
"name": username,
},
})
responseBody := bytes.NewBuffer(postBody)
response, err := http.Post("http://10.0.0.4:1081/rpc.php", "application/json", responseBody)
if err != nil {
fmt.Print(err.Error())
os.Exit(1)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
return string(responseData)
}
func (o *omvService) SetUser(m model.UserDBModel) model.UserDBModel {
// Implement SetUser logic here
return m // Assuming m is the modified user
}
func (o *omvService) ApplyChange() {
// Implement ApplyChange logic here
}
func NewOMVService() OMVService {
return &omvService{}
}
+6
View File
@@ -14,6 +14,7 @@ type Repository interface {
User() UserService
MessageBus() *message_bus.ClientWithResponses
Event() EventService
OMV() OMVService
}
func NewService(db *gorm.DB, RuntimePath string) Repository {
@@ -27,6 +28,7 @@ func NewService(db *gorm.DB, RuntimePath string) Repository {
gateway: gatewayManagement,
user: NewUserService(db),
event: NewEventService(db),
omv: NewOMVService(),
}
}
@@ -34,8 +36,12 @@ type store struct {
gateway external.ManagementService
user UserService
event EventService
omv OMVService
}
func (c *store) OMV() OMVService {
return c.omv
}
func (c *store) Event() EventService {
return c.event
}