adding new routes to the api client
This commit is contained in:
parent
5a950af7a1
commit
d5fffa1d66
@ -62,3 +62,31 @@ func (a userClient) SignUp(username, password string) (domain.BaseResponse, erro
|
||||
|
||||
return bind, nil
|
||||
}
|
||||
|
||||
func (a userClient) RefreshJwtToken(username, refreshToken string) (domain.LoginResponse, error) {
|
||||
endpoint := fmt.Sprintf("%s/%s/refresh/token", a.serverAddress, UserBaseRoute)
|
||||
body := domain.RefreshTokenRequest{
|
||||
Username: username,
|
||||
RefreshToken: refreshToken,
|
||||
}
|
||||
|
||||
var bind = domain.LoginResponse{}
|
||||
err := PostBodyUrl(a.client, endpoint, body, &bind)
|
||||
if err != nil {
|
||||
return domain.LoginResponse{}, err
|
||||
}
|
||||
|
||||
return bind, nil
|
||||
}
|
||||
|
||||
func (a userClient) refreshSessionToken() (domain.BaseResponse, error) {
|
||||
endpoint := fmt.Sprintf("%s/%s/refresh/sessionToken", a.serverAddress, UserBaseRoute)
|
||||
|
||||
var bind = domain.BaseResponse{}
|
||||
err := PostUrl(a.client, endpoint, &bind)
|
||||
if err != nil {
|
||||
return domain.BaseResponse{}, err
|
||||
}
|
||||
|
||||
return bind, nil
|
||||
}
|
||||
|
@ -29,3 +29,40 @@ func PostUrlForm(client http.Client, endpoint string, param url.Values, t any) e
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func PostUrl(client http.Client, endpoint string, t any) error {
|
||||
response, err := http.Post(endpoint, ApplicationJson, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
decoder := json.NewDecoder(response.Body)
|
||||
err = decoder.Decode(&t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func PostBodyUrl(client http.Client, endpoint string, body any, t any) error {
|
||||
jsonBody, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := http.Post(endpoint, ApplicationJson, bytes.NewBuffer(jsonBody))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
decoder := json.NewDecoder(response.Body)
|
||||
err = decoder.Decode(&t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user