member model added
member unmashal test code
This commit is contained in:
parent
cd7f0cbc0a
commit
d45b1a5dcc
|
@ -2,14 +2,14 @@ package member
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.loafle.net/overflow/encryption_go"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy"
|
||||
"log"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/apikey"
|
||||
"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"`
|
||||
Email string `json:"email"`
|
||||
PwSalt string `json:"pwSalt"`
|
||||
|
@ -17,20 +17,28 @@ type MemberService struct {
|
|||
Name string `json:"name"`
|
||||
Company string `json:"company"`
|
||||
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"
|
||||
|
||||
func NewMember() *MemberService {
|
||||
m := MemberService{}
|
||||
func NewMember() *Member {
|
||||
m := Member{}
|
||||
return &m
|
||||
}
|
||||
func NewMemberService() *MemberService {
|
||||
ms := &MemberService{}
|
||||
ms.Param = NewMember()
|
||||
return ms
|
||||
}
|
||||
|
||||
func (m *MemberService) getMemberMap() map[string]string {
|
||||
memMap := make(map[string]string)
|
||||
|
||||
str, err := json.Marshal(m)
|
||||
str, err := json.Marshal(m.Param)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Json Marshal Error: ", err)
|
||||
|
@ -47,7 +55,7 @@ func (m *MemberService) Login() string {
|
|||
if result == "" {
|
||||
return "login reject"
|
||||
}
|
||||
temp := MemberService{}
|
||||
temp := Member{}
|
||||
err := json.Unmarshal([]byte(result), &temp)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
|
@ -56,7 +64,7 @@ func (m *MemberService) Login() string {
|
|||
return "Not authenticated."
|
||||
}
|
||||
|
||||
b := encryption.Check(m.PwSalt, temp.PwSalt, temp.Digest)
|
||||
b := encryption.Check(m.Param.PwSalt, temp.PwSalt, temp.Digest)
|
||||
if !b {
|
||||
return "login reject"
|
||||
}
|
||||
|
@ -65,15 +73,15 @@ func (m *MemberService) Login() 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 {
|
||||
log.Fatal("encryption Encrypt Error: ", err)
|
||||
}
|
||||
|
||||
m.PwSalt = pwSalt
|
||||
m.Digest = digest
|
||||
m.Param.PwSalt = pwSalt
|
||||
m.Param.Digest = digest
|
||||
memMap := m.getMemberMap()
|
||||
|
||||
re := proxy.InvokeDB(TARGET_DAO, "create", memMap)
|
||||
|
@ -82,19 +90,19 @@ func (m *MemberService) Regist() string {
|
|||
}
|
||||
|
||||
func (m *MemberService) ReadByEmail() string {
|
||||
log.Println("Call ReadByEmail", m.Email)
|
||||
log.Println("Call ReadByEmail", m.Param.Email)
|
||||
memMap := m.getMemberMap()
|
||||
re := proxy.InvokeDB(TARGET_DAO, "findByEmail", memMap)
|
||||
return re
|
||||
}
|
||||
|
||||
func (m *MemberService) Read() string {
|
||||
log.Println("Call Read", m.Email)
|
||||
log.Println("Call Read", m.Param.Email)
|
||||
// Todo Call DB Gateway
|
||||
m.Digest = "qwer5795"
|
||||
m.Param.Digest = "qwer5795"
|
||||
//memMap := m.getMemberMap()
|
||||
mm := make(map[string]string)
|
||||
mm["id"] = string(m.Id)
|
||||
mm["id"] = string(m.Param.Id)
|
||||
log.Println("Read Member", m)
|
||||
re := proxy.InvokeDB(TARGET_DAO, "find", mm)
|
||||
|
||||
|
@ -102,9 +110,9 @@ func (m *MemberService) Read() 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
|
||||
m.Digest = "read"
|
||||
m.Param.Digest = "read"
|
||||
memMap := m.getMemberMap()
|
||||
|
||||
re := proxy.InvokeDB(TARGET_DAO, "update", memMap)
|
||||
|
@ -113,9 +121,9 @@ func (m *MemberService) Modify() string {
|
|||
}
|
||||
|
||||
func (m *MemberService) Remove() string {
|
||||
log.Println("Call Remove", m.Email)
|
||||
log.Println("Call Remove", m.Param.Email)
|
||||
// Todo Call DB Gateway
|
||||
m.Digest = "read"
|
||||
//m.Digest = "read"
|
||||
memMap := m.getMemberMap()
|
||||
|
||||
re := proxy.InvokeDB(TARGET_DAO, "delete", memMap)
|
||||
|
|
|
@ -2,6 +2,9 @@ package member
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"encoding/json"
|
||||
"github.com/golang/glog"
|
||||
"fmt"
|
||||
"log"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy"
|
||||
)
|
||||
|
@ -12,11 +15,13 @@ func TestMemberService_Login(t *testing.T) {
|
|||
|
||||
func TestMemberService_Regist(t *testing.T) {
|
||||
m := &MemberService{
|
||||
Email:"geek2@loafle.com",
|
||||
PwSalt:"qwer5795",
|
||||
Company:"Loafle",
|
||||
Name:"Geek",
|
||||
Phone:"010-4055-6699",
|
||||
Param: &Member{
|
||||
Email:"geek2@loafle.com",
|
||||
PwSalt:"qwer5795",
|
||||
Company:"Loafle",
|
||||
Name:"Geek",
|
||||
Phone:"010-4055-6699",
|
||||
},
|
||||
}
|
||||
|
||||
retMem := m.Regist()
|
||||
|
@ -25,8 +30,10 @@ func TestMemberService_Regist(t *testing.T) {
|
|||
|
||||
func TestMemberLogin(t *testing.T) {
|
||||
m := &MemberService{
|
||||
Email:"geek@loafle.com",
|
||||
PwSalt:"qwer5795",
|
||||
Param:&Member{
|
||||
Email:"geek@loafle.com",
|
||||
PwSalt:"qwer5795",
|
||||
},
|
||||
}
|
||||
b := m.Login()
|
||||
t.Log("LOGIN RESULT : ", b)
|
||||
|
@ -42,7 +49,9 @@ func TestMemberService_Read(t *testing.T) {
|
|||
|
||||
func TestMemberService_ReadByEmail(t *testing.T) {
|
||||
m := &MemberService{
|
||||
Email:"geek@loafle.com",
|
||||
Param:&Member{
|
||||
Email:"geek@loafle.com",
|
||||
},
|
||||
}
|
||||
|
||||
mm := m.getMemberMap()
|
||||
|
@ -52,11 +61,32 @@ func TestMemberService_ReadByEmail(t *testing.T) {
|
|||
|
||||
func TestMemberUpdate(t *testing.T) {
|
||||
m := &MemberService{
|
||||
Id: "11",
|
||||
Email:"keeg@loafle.com",
|
||||
Param:&Member{
|
||||
Id: "11",
|
||||
Email:"keeg@loafle.com",
|
||||
},
|
||||
}
|
||||
|
||||
mm := m.getMemberMap()
|
||||
rr := proxy.InvokeDB(TARGET_DAO, "update", mm)
|
||||
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)
|
||||
}
|
|
@ -8,11 +8,11 @@ import (
|
|||
)
|
||||
|
||||
type NoAuthAgentService struct {
|
||||
|
||||
Param *NoAuthAgent `json:"param"`
|
||||
}
|
||||
|
||||
func NewNoAuthAgentService() *NoAuthAgentService {
|
||||
return &NoAuthAgentService{}
|
||||
return &NoAuthAgentService{Param:&NoAuthAgent{}}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
||||
func InvokeDB(targetDb, methodName string, param map[string]string) (string) {
|
||||
|
||||
in := &pb.DBInput{}
|
||||
|
|
Loading…
Reference in New Issue
Block a user