member model added

member unmashal test code
This commit is contained in:
geek 2017-06-05 15:37:46 +09:00
parent cd7f0cbc0a
commit d45b1a5dcc
4 changed files with 71 additions and 32 deletions

View File

@ -2,14 +2,14 @@ package member
import ( import (
"encoding/json" "encoding/json"
"git.loafle.net/overflow/encryption_go"
"git.loafle.net/overflow/overflow_proxy_service/proxy" "git.loafle.net/overflow/overflow_proxy_service/proxy"
"log" "log"
"git.loafle.net/overflow/overflow_proxy_service/proxy/apikey" "git.loafle.net/overflow/overflow_proxy_service/proxy/apikey"
"git.loafle.net/overflow/overflow_proxy_service/proxy/keystore" "git.loafle.net/overflow/overflow_proxy_service/proxy/keystore"
"git.loafle.net/overflow/encryption_go"
) )
type MemberService struct { type Member struct {
Id json.Number `json:"id,Number,omitempty"` Id json.Number `json:"id,Number,omitempty"`
Email string `json:"email"` Email string `json:"email"`
PwSalt string `json:"pwSalt"` PwSalt string `json:"pwSalt"`
@ -17,20 +17,28 @@ type MemberService struct {
Name string `json:"name"` Name string `json:"name"`
Company string `json:"company"` Company string `json:"company"`
Phone string `json:"phone"` Phone string `json:"phone"`
AuthorizedDate json.Number `json:"id,Number"` AuthorizedDate json.Number `json:"authorizedDate,Number"`
}
type MemberService struct {
Param *Member `json:"param"`
} }
var TARGET_DAO = "member" var TARGET_DAO = "member"
func NewMember() *MemberService { func NewMember() *Member {
m := MemberService{} m := Member{}
return &m return &m
} }
func NewMemberService() *MemberService {
ms := &MemberService{}
ms.Param = NewMember()
return ms
}
func (m *MemberService) getMemberMap() map[string]string { func (m *MemberService) getMemberMap() map[string]string {
memMap := make(map[string]string) memMap := make(map[string]string)
str, err := json.Marshal(m) str, err := json.Marshal(m.Param)
if err != nil { if err != nil {
log.Fatal("Json Marshal Error: ", err) log.Fatal("Json Marshal Error: ", err)
@ -47,7 +55,7 @@ func (m *MemberService) Login() string {
if result == "" { if result == "" {
return "login reject" return "login reject"
} }
temp := MemberService{} temp := Member{}
err := json.Unmarshal([]byte(result), &temp) err := json.Unmarshal([]byte(result), &temp)
if err != nil { if err != nil {
return err.Error() return err.Error()
@ -56,7 +64,7 @@ func (m *MemberService) Login() string {
return "Not authenticated." return "Not authenticated."
} }
b := encryption.Check(m.PwSalt, temp.PwSalt, temp.Digest) b := encryption.Check(m.Param.PwSalt, temp.PwSalt, temp.Digest)
if !b { if !b {
return "login reject" return "login reject"
} }
@ -65,15 +73,15 @@ func (m *MemberService) Login() string {
} }
func (m *MemberService) Regist() string { func (m *MemberService) Regist() string {
log.Println("Call Regist", m.Email, m.PwSalt) log.Println("Call Regist", m.Param.Email, m.Param.PwSalt)
pwSalt, digest, err := encryption.Encrypt(m.PwSalt) pwSalt, digest, err := encryption.Encrypt(m.Param.PwSalt)
if err != nil { if err != nil {
log.Fatal("encryption Encrypt Error: ", err) log.Fatal("encryption Encrypt Error: ", err)
} }
m.PwSalt = pwSalt m.Param.PwSalt = pwSalt
m.Digest = digest m.Param.Digest = digest
memMap := m.getMemberMap() memMap := m.getMemberMap()
re := proxy.InvokeDB(TARGET_DAO, "create", memMap) re := proxy.InvokeDB(TARGET_DAO, "create", memMap)
@ -82,19 +90,19 @@ func (m *MemberService) Regist() string {
} }
func (m *MemberService) ReadByEmail() string { func (m *MemberService) ReadByEmail() string {
log.Println("Call ReadByEmail", m.Email) log.Println("Call ReadByEmail", m.Param.Email)
memMap := m.getMemberMap() memMap := m.getMemberMap()
re := proxy.InvokeDB(TARGET_DAO, "findByEmail", memMap) re := proxy.InvokeDB(TARGET_DAO, "findByEmail", memMap)
return re return re
} }
func (m *MemberService) Read() string { func (m *MemberService) Read() string {
log.Println("Call Read", m.Email) log.Println("Call Read", m.Param.Email)
// Todo Call DB Gateway // Todo Call DB Gateway
m.Digest = "qwer5795" m.Param.Digest = "qwer5795"
//memMap := m.getMemberMap() //memMap := m.getMemberMap()
mm := make(map[string]string) mm := make(map[string]string)
mm["id"] = string(m.Id) mm["id"] = string(m.Param.Id)
log.Println("Read Member", m) log.Println("Read Member", m)
re := proxy.InvokeDB(TARGET_DAO, "find", mm) re := proxy.InvokeDB(TARGET_DAO, "find", mm)
@ -102,9 +110,9 @@ func (m *MemberService) Read() string {
} }
func (m *MemberService) Modify() string { func (m *MemberService) Modify() string {
log.Println("Call Modify", m.Email, "::", m.PwSalt) log.Println("Call Modify", m.Param.Email, "::", m.Param.PwSalt)
// Todo Call DB Gateway // Todo Call DB Gateway
m.Digest = "read" m.Param.Digest = "read"
memMap := m.getMemberMap() memMap := m.getMemberMap()
re := proxy.InvokeDB(TARGET_DAO, "update", memMap) re := proxy.InvokeDB(TARGET_DAO, "update", memMap)
@ -113,9 +121,9 @@ func (m *MemberService) Modify() string {
} }
func (m *MemberService) Remove() string { func (m *MemberService) Remove() string {
log.Println("Call Remove", m.Email) log.Println("Call Remove", m.Param.Email)
// Todo Call DB Gateway // Todo Call DB Gateway
m.Digest = "read" //m.Digest = "read"
memMap := m.getMemberMap() memMap := m.getMemberMap()
re := proxy.InvokeDB(TARGET_DAO, "delete", memMap) re := proxy.InvokeDB(TARGET_DAO, "delete", memMap)

View File

@ -2,6 +2,9 @@ package member
import ( import (
"testing" "testing"
"encoding/json"
"github.com/golang/glog"
"fmt"
"log" "log"
"git.loafle.net/overflow/overflow_proxy_service/proxy" "git.loafle.net/overflow/overflow_proxy_service/proxy"
) )
@ -12,11 +15,13 @@ func TestMemberService_Login(t *testing.T) {
func TestMemberService_Regist(t *testing.T) { func TestMemberService_Regist(t *testing.T) {
m := &MemberService{ m := &MemberService{
Email:"geek2@loafle.com", Param: &Member{
PwSalt:"qwer5795", Email:"geek2@loafle.com",
Company:"Loafle", PwSalt:"qwer5795",
Name:"Geek", Company:"Loafle",
Phone:"010-4055-6699", Name:"Geek",
Phone:"010-4055-6699",
},
} }
retMem := m.Regist() retMem := m.Regist()
@ -25,8 +30,10 @@ func TestMemberService_Regist(t *testing.T) {
func TestMemberLogin(t *testing.T) { func TestMemberLogin(t *testing.T) {
m := &MemberService{ m := &MemberService{
Email:"geek@loafle.com", Param:&Member{
PwSalt:"qwer5795", Email:"geek@loafle.com",
PwSalt:"qwer5795",
},
} }
b := m.Login() b := m.Login()
t.Log("LOGIN RESULT : ", b) t.Log("LOGIN RESULT : ", b)
@ -42,7 +49,9 @@ func TestMemberService_Read(t *testing.T) {
func TestMemberService_ReadByEmail(t *testing.T) { func TestMemberService_ReadByEmail(t *testing.T) {
m := &MemberService{ m := &MemberService{
Email:"geek@loafle.com", Param:&Member{
Email:"geek@loafle.com",
},
} }
mm := m.getMemberMap() mm := m.getMemberMap()
@ -52,11 +61,32 @@ func TestMemberService_ReadByEmail(t *testing.T) {
func TestMemberUpdate(t *testing.T) { func TestMemberUpdate(t *testing.T) {
m := &MemberService{ m := &MemberService{
Id: "11", Param:&Member{
Email:"keeg@loafle.com", Id: "11",
Email:"keeg@loafle.com",
},
} }
mm := m.getMemberMap() mm := m.getMemberMap()
rr := proxy.InvokeDB(TARGET_DAO, "update", mm) rr := proxy.InvokeDB(TARGET_DAO, "update", mm)
log.Println(rr) log.Println(rr)
}
func TestComvertJson(t *testing.T) {
m := make(map[string]string)
m["email"] = "geek@loafle.com"
m["password"] = "qwer5795"
ss := NewMemberService()
paramStr, err := json.Marshal(m)
if err != nil {
glog.Fatal("Json Marshal Failed : ", err.Error())
}
// service converting
err = json.Unmarshal(paramStr, ss.Param)
if err != nil {
glog.Fatal("Json Unmarshal Failed : ", err.Error())
}
fmt.Println(ss.Param.Email)
} }

View File

@ -8,11 +8,11 @@ import (
) )
type NoAuthAgentService struct { type NoAuthAgentService struct {
Param *NoAuthAgent `json:"param"`
} }
func NewNoAuthAgentService() *NoAuthAgentService { func NewNoAuthAgentService() *NoAuthAgentService {
return &NoAuthAgentService{} return &NoAuthAgentService{Param:&NoAuthAgent{}}
} }

View File

@ -7,6 +7,7 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
) )
func InvokeDB(targetDb, methodName string, param map[string]string) (string) { func InvokeDB(targetDb, methodName string, param map[string]string) (string) {
in := &pb.DBInput{} in := &pb.DBInput{}