features/bootstrapping #1

Merged
jtom38 merged 24 commits from features/bootstrapping into main 2024-06-02 19:55:25 -07:00
2 changed files with 66 additions and 1 deletions
Showing only changes of commit d5fffa1d66 - Show all commits

View File

@ -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
}

View File

@ -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
}