@@ -7,21 +7,17 @@ import (
77 "io"
88 "net/http"
99
10+ "github.com/ut-code/Raxcel/server/types"
1011 "github.com/zalando/go-keyring"
1112)
1213
13- type RegisterRequest struct {
14- Email string `json:"email"`
15- Password string `json:"password"`
16- }
17-
1814type SignupResult struct {
1915 UserId string `json:"userId"`
2016 Error string `json:"error"`
2117}
2218
2319func (a * App ) Signup (email , password string ) SignupResult {
24- postData := RegisterRequest {
20+ postData := types. SignupRequest {
2521 Email : email ,
2622 Password : password ,
2723 }
@@ -49,7 +45,7 @@ func (a *App) Signup(email, password string) SignupResult {
4945 Error : fmt .Sprintf ("Failed to read response: %v" , err ),
5046 }
5147 }
52- var serverResponse map [ string ] string
48+ var serverResponse types. SignupResponse
5349 err = json .Unmarshal (body , & serverResponse )
5450 if err != nil {
5551 return SignupResult {
@@ -60,27 +56,22 @@ func (a *App) Signup(email, password string) SignupResult {
6056 if resp .StatusCode != http .StatusCreated {
6157 return SignupResult {
6258 UserId : "" ,
63- Error : serverResponse [ "error" ] ,
59+ Error : serverResponse . Error ,
6460 }
6561 }
6662 return SignupResult {
67- UserId : serverResponse [ "userId" ] ,
63+ UserId : serverResponse . UserId ,
6864 Error : "" ,
6965 }
7066}
7167
72- type LoginRequest struct {
73- Email string `json:"email"`
74- Password string `json:"password"`
75- }
76-
7768type SigninResult struct {
7869 Token string `json:"token"`
7970 Error string `json:"error"`
8071}
8172
8273func (a * App ) Signin (email , password string ) SigninResult {
83- postData := LoginRequest {
74+ postData := types. SigninRequest {
8475 Email : email ,
8576 Password : password ,
8677 }
@@ -110,7 +101,7 @@ func (a *App) Signin(email, password string) SigninResult {
110101 }
111102 }
112103
113- var serverResponse map [ string ] string
104+ var serverResponse types. SigninResponse
114105 err = json .Unmarshal (body , & serverResponse )
115106 if err != nil {
116107 return SigninResult {
@@ -121,10 +112,10 @@ func (a *App) Signin(email, password string) SigninResult {
121112 if resp .StatusCode != http .StatusOK {
122113 return SigninResult {
123114 Token : "" ,
124- Error : serverResponse [ "error" ] ,
115+ Error : serverResponse . Error ,
125116 }
126117 }
127- token := serverResponse [ "token" ]
118+ token := serverResponse . Token
128119 err = keyring .Set ("Raxcel" , "raxcel-user" , token )
129120 if err != nil {
130121 return SigninResult {
@@ -164,21 +155,28 @@ func (a *App) GetCurrentUser() GetCurrentUserResult {
164155 Error : fmt .Sprint (err ),
165156 }
166157 }
167- var serverResponse map [ string ] string
158+ var serverResponse types. GetCurrentUserResponse
168159 if err := json .Unmarshal (body , & serverResponse ); err != nil {
169160 return GetCurrentUserResult {
170161 UserId : "" ,
171162 Error : fmt .Sprint (err ),
172163 }
173164 }
174- if serverResponse ["error" ] != "" {
165+ if serverResponse .AuthMiddlewareReturn != nil {
166+ return GetCurrentUserResult {
167+ UserId : "" ,
168+ // Error: serverResponse.AuthMiddlewareReturn.MiddlewareError, でも同じこと
169+ Error : serverResponse .MiddlewareError ,
170+ }
171+ }
172+ if serverResponse .GetCurrentUserResponse .Error != "" {
175173 return GetCurrentUserResult {
176174 UserId : "" ,
177- Error : serverResponse [ "error" ] ,
175+ Error : serverResponse . Error ,
178176 }
179177 }
180178 return GetCurrentUserResult {
181- UserId : serverResponse [ "userId" ] ,
179+ UserId : serverResponse . UserId ,
182180 Error : "" ,
183181 }
184182}
0 commit comments