diff --git a/proxy/noauthagent/agent_service.go b/proxy/noauthagent/agent_service.go index 1310ae8..e782101 100644 --- a/proxy/noauthagent/agent_service.go +++ b/proxy/noauthagent/agent_service.go @@ -5,6 +5,9 @@ import ( "git.loafle.net/overflow/commons_go/model/timestamp" "git.loafle.net/overflow/overflow_proxy_service/proxy" "encoding/json" + "git.loafle.net/overflow/overflow_proxy_service/proxy/member" + "git.loafle.net/overflow/overflow_proxy_service/proxy/agent" + "github.com/reactivex/rxgo/errors" ) type NoAuthAgentService struct { @@ -77,12 +80,12 @@ func(as *NoAuthAgentService)CheckAuth(tempKey string) (string,error) { } -func(as *NoAuthAgentService)GetNoAuthList(authStatus string) (string,error) { +func(as *NoAuthAgentService)GetNoAuthList(excludeStatus string) (string,error) { memMap := make(map[string]string) na := NewNoAuthAgent("", 0, "") - na.AuthStatus = authStatus + na.AuthStatus = excludeStatus bytes, err := json.Marshal(na) if err != nil { @@ -101,3 +104,35 @@ func(as *NoAuthAgentService)GetNoAuthList(authStatus string) (string,error) { func (as *NoAuthAgentService) GetModel() (interface{}) { return NewNoAuthAgent("", 0, "") } + +func (as *NoAuthAgentService)RequestAuth(noauthAgt NoAuthAgent, memberId, desc string) (string, error) { + paramMap := make(map[string]string) + noauthAgt.AuthStatus = "ACCEPT" + + bytes, err := json.Marshal(noauthAgt) + if err != nil { + return "", err; + } + paramMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes) + out := proxy.InvokeDB("noauthAgent", "update", paramMap) + if len(out) == 0 { + return "", errors.New("Cannot update Agent. ") + } + m := member.Member{} + m.Id = json.Number(memberId) + newAgent := agent.NewAgent(desc, m) + newone, err := agent.NewAgentService().SaveAgent(newAgent) + if err!= nil { + return "", err + } + + return newone, nil +} + +func (as *NoAuthAgentService)ReadNoAuthAgent(id string) (string, error){ + mm := make(map[string]string) + mm["id"] = id + out := proxy.InvokeDB("noauthAgent", "find", mm) + + return out, nil +} \ No newline at end of file diff --git a/proxy/noauthagent/agent_service_test.go b/proxy/noauthagent/agent_service_test.go index 006cc69..4490129 100644 --- a/proxy/noauthagent/agent_service_test.go +++ b/proxy/noauthagent/agent_service_test.go @@ -5,6 +5,7 @@ import ( "github.com/google/uuid" "testing" + "encoding/json" ) @@ -22,9 +23,9 @@ func TestCreateUUid(t *testing.T) { func TestCreateNoAuthAgent(t *testing.T) { - na := NewNoAuthAgent("2334278390283", 111, "Snoop") + na := NewNoAuthAgent("233421390283", 111, "Snoop") - na.TempKey = "22222222" + na.TempKey = "1111111" na.AuthStatus = "WAIT" nas := NewNoAuthAgentService() @@ -72,4 +73,18 @@ func TestNoAuthList(t *testing.T) { t.Log(out) -} \ No newline at end of file +} + +func TestRequestAuth(t *testing.T) { + nas := NewNoAuthAgentService() + res, err := nas.ReadNoAuthAgent("1") + + na := NoAuthAgent{} + json.Unmarshal([]byte(res), na) + + newone, err := nas.RequestAuth(na, "1", "test") + if err!= nil { + t.Fatal(err) + } + t.Log(newone) +}