From df321cafdae6992e6de73ceb56ff0572413522a5 Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Sun, 24 Sep 2023 17:49:44 +0900 Subject: [PATCH 01/20] use go-traq --- utils/api.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/utils/api.go b/utils/api.go index 59b5d0fa..7eab4ad9 100644 --- a/utils/api.go +++ b/utils/api.go @@ -1,6 +1,7 @@ package utils import ( + "context" "crypto/hmac" "crypto/sha1" "encoding/hex" @@ -12,6 +13,7 @@ import ( "strings" "github.com/labstack/echo/v4" + "github.com/traPtitech/go-traq" ) const baseURL = "https://q.trap.jp/api/v3" @@ -44,6 +46,30 @@ func RequestWebhook(message, secret, channelID, webhookID string, embed int) err if res.StatusCode >= 400 { return errors.New(http.StatusText(res.StatusCode)) } + + // ここから go-traq 書き換え + xTRAQSignature := calcSignature(message, secret) + configuration := traq.NewConfiguration() + apiClient := traq.NewAPIClient(configuration) + if channelID != "" { + res, err := apiClient.WebhookApi.PostWebhook(context.Background(),webhookID).XTRAQChannelId(channelID).XTRAQSignature(xTRAQSignature).Embed(int32(embed)).Body(message).Execute() + if err != nil{ + return err + } + if res.StatusCode >= 400 { + return errors.New(http.StatusText(res.StatusCode)) + } + }else{ + res, err := apiClient.WebhookApi.PostWebhook(context.Background(),webhookID).XTRAQSignature(xTRAQSignature).Embed(int32(embed)).Body(message).Execute() + if err != nil{ + return err + } + if res.StatusCode >= 400 { + return errors.New(http.StatusText(res.StatusCode)) + } + } + // ここまで go-traq 書き換え + return nil } From 2566f5fc315c5ab58f829c0bcc5d4ece79f86f45 Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Sun, 24 Sep 2023 18:50:56 +0900 Subject: [PATCH 02/20] disable previous code --- utils/api.go | 82 ++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/utils/api.go b/utils/api.go index 7eab4ad9..c3af0808 100644 --- a/utils/api.go +++ b/utils/api.go @@ -7,12 +7,12 @@ import ( "encoding/hex" "errors" "net/http" - "net/url" - "path" - "strconv" - "strings" + // "net/url" + // "path" + // "strconv" + // "strings" - "github.com/labstack/echo/v4" + // "github.com/labstack/echo/v4" "github.com/traPtitech/go-traq" ) @@ -20,54 +20,46 @@ const baseURL = "https://q.trap.jp/api/v3" // RequestWebhook q.trap/jp にメッセージを送信します。 func RequestWebhook(message, secret, channelID, webhookID string, embed int) error { - u, err := url.Parse(baseURL + "/webhooks") - if err != nil { - return err - } - u.Path = path.Join(u.Path, webhookID) - query := u.Query() - query.Set("embed", strconv.Itoa(embed)) - u.RawQuery = query.Encode() + // u, err := url.Parse(baseURL + "/webhooks") + // if err != nil { + // return err + // } + // u.Path = path.Join(u.Path, webhookID) + // query := u.Query() + // query.Set("embed", strconv.Itoa(embed)) + // u.RawQuery = query.Encode() - req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(message)) - if err != nil { - return err - } - req.Header.Set(echo.HeaderContentType, echo.MIMETextPlain) - req.Header.Set("X-TRAQ-Signature", calcSignature(message, secret)) - if channelID != "" { - req.Header.Set("X-TRAQ-Channel-Id", channelID) - } + // req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(message)) + // if err != nil { + // return err + // } + // req.Header.Set(echo.HeaderContentType, echo.MIMETextPlain) + // req.Header.Set("X-TRAQ-Signature", calcSignature(message, secret)) + // if channelID != "" { + // req.Header.Set("X-TRAQ-Channel-Id", channelID) + // } - res, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - if res.StatusCode >= 400 { - return errors.New(http.StatusText(res.StatusCode)) - } + // res, err := http.DefaultClient.Do(req) + // if err != nil { + // return err + // } + // if res.StatusCode >= 400 { + // return errors.New(http.StatusText(res.StatusCode)) + // } // ここから go-traq 書き換え xTRAQSignature := calcSignature(message, secret) configuration := traq.NewConfiguration() apiClient := traq.NewAPIClient(configuration) - if channelID != "" { - res, err := apiClient.WebhookApi.PostWebhook(context.Background(),webhookID).XTRAQChannelId(channelID).XTRAQSignature(xTRAQSignature).Embed(int32(embed)).Body(message).Execute() - if err != nil{ - return err - } - if res.StatusCode >= 400 { - return errors.New(http.StatusText(res.StatusCode)) - } - }else{ - res, err := apiClient.WebhookApi.PostWebhook(context.Background(),webhookID).XTRAQSignature(xTRAQSignature).Embed(int32(embed)).Body(message).Execute() - if err != nil{ - return err - } - if res.StatusCode >= 400 { - return errors.New(http.StatusText(res.StatusCode)) - } + + res, err := apiClient.WebhookApi.PostWebhook(context.Background(),webhookID).XTRAQChannelId(channelID).XTRAQSignature(xTRAQSignature).Embed(int32(embed)).Body(message).Execute() + if err != nil{ + return err } + if res.StatusCode >= 400 { + return errors.New(http.StatusText(res.StatusCode)) + } + // ここまで go-traq 書き換え return nil From 9a6859d64be7e05cfd5c45e412ea6aeb2dcfe5a2 Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Sun, 24 Sep 2023 21:27:06 +0900 Subject: [PATCH 03/20] use go-traq GetUser (WIP) --- infra/traq/user.go | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index 744e23e2..9f48b60b 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -1,6 +1,7 @@ package traq import ( + "context" "encoding/json" "fmt" "net/http" @@ -13,19 +14,34 @@ import ( ) func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { - URL := fmt.Sprintf("%s/users/%s", repo.URL, userID) - req, err := http.NewRequest(http.MethodGet, URL, nil) - if err != nil { - return nil, err + // URL := fmt.Sprintf("%s/users/%s", repo.URL, userID) + // req, err := http.NewRequest(http.MethodGet, URL, nil) + // if err != nil { + // return nil, err + // } + // data, err := repo.doRequest(token, req) + // if err != nil { + // return nil, err + // } + + + // ここから go-traq 書き換え + + traqconf := traq.NewConfiguration() + conf := oauth2.Config{ + } - data, err := repo.doRequest(token, req) - if err != nil { - return nil, err + traqconf.HTTPClient = conf.Client(context.TODO(),token) + apiClient := traq.NewAPIClient(traqconf) + userDtail,_,err := apiClient.UserApi.GetUser(context.Background(),userID.String()).Execute() + if err!=nil{ + return nil,err } - user := new(traq.User) - err = json.Unmarshal(data, &user) + return user, err + + // ここまで go-traq 書き換え } func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]*traq.User, error) { From 5c3a1680b0f594a50622db206a149b1ff784dace Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Sun, 24 Sep 2023 21:32:06 +0900 Subject: [PATCH 04/20] revert --- infra/traq/user.go | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index 9f48b60b..20e800bc 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -14,32 +14,34 @@ import ( ) func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { - // URL := fmt.Sprintf("%s/users/%s", repo.URL, userID) - // req, err := http.NewRequest(http.MethodGet, URL, nil) - // if err != nil { - // return nil, err - // } - // data, err := repo.doRequest(token, req) - // if err != nil { - // return nil, err - // } + URL := fmt.Sprintf("%s/users/%s", repo.URL, userID) + req, err := http.NewRequest(http.MethodGet, URL, nil) + if err != nil { + return nil, err + } + data, err := repo.doRequest(token, req) + if err != nil { + return nil, err + } + user := new(traq.User) + err = json.Unmarshal(data, &user) + return user, err // ここから go-traq 書き換え - traqconf := traq.NewConfiguration() - conf := oauth2.Config{ + // traqconf := traq.NewConfiguration() + // conf := oauth2.Config{ - } - traqconf.HTTPClient = conf.Client(context.TODO(),token) - apiClient := traq.NewAPIClient(traqconf) - userDtail,_,err := apiClient.UserApi.GetUser(context.Background(),userID.String()).Execute() - if err!=nil{ - return nil,err - } - user := new(traq.User) - - return user, err + // } + // traqconf.HTTPClient = conf.Client(context.TODO(),token) + // apiClient := traq.NewAPIClient(traqconf) + // userDtail,_,err := apiClient.UserApi.GetUser(context.Background(),userID.String()).Execute() + // if err!=nil{ + // return nil,err + // } + // user := new(traq.User) + // return user, err // ここまで go-traq 書き換え } From 86d2298b273addddb651eda736b86861a13fdf9c Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 12 Oct 2023 22:09:51 +0900 Subject: [PATCH 05/20] use go-traq GetUserMe add converter MyUserdetail -> User --- infra/traq/user.go | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index 20e800bc..79d0d8e4 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -1,6 +1,7 @@ package traq import ( + //"context" "context" "encoding/json" "fmt" @@ -13,6 +14,8 @@ import ( "golang.org/x/oauth2" ) + + func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { URL := fmt.Sprintf("%s/users/%s", repo.URL, userID) req, err := http.NewRequest(http.MethodGet, URL, nil) @@ -68,18 +71,41 @@ func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) return users, err } + func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { - URL := fmt.Sprintf("%s/users/me", repo.URL) - req, err := http.NewRequest(http.MethodGet, URL, nil) - if err != nil { - return nil, err - } - data, err := repo.doRequest(token, req) - if err != nil { - return nil, err + // URL := fmt.Sprintf("%s/users/me", repo.URL) + // req, err := http.NewRequest(http.MethodGet, URL, nil) + // if err != nil { + // return nil, err + // } + // data, err := repo.doRequest(token, req) + // if err != nil { + // return nil, err + // } + + // ここから go-traq 書き換え + traqconf := traq.NewConfiguration() + conf :=TraQDefaultConfig + traqconf.HTTPClient=conf.Client(context.Background(),token) + client := traq.NewAPIClient(traqconf) + + data,_,err:= client.MeApi.GetMe(context.Background()).Execute() + if err != nil{ + return nil,err } + user := convertMyUserdetailToUser(data) + return user, err + // ここまで go-traq 書き換え +} +func convertMyUserdetailToUser (userdetail *traq.MyUserDetail) *traq.User{ user := new(traq.User) - err = json.Unmarshal(data, &user) - return user, err + user.Id=userdetail.Id + user.Name=userdetail.Name + user.DisplayName=userdetail.DisplayName + user.IconFileId=userdetail.IconFileId + user.Bot=userdetail.Bot + user.State=userdetail.State + user.UpdatedAt=userdetail.UpdatedAt + return user } From 8c0016b2fe670313a6779891a8e1611085f7100c Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Mon, 16 Oct 2023 21:10:43 +0900 Subject: [PATCH 06/20] use go-traq userAPI --- infra/traq/user.go | 133 +++++++++++++++++++++++++++++---------------- 1 file changed, 87 insertions(+), 46 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index 79d0d8e4..ac96eaf6 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -3,11 +3,11 @@ package traq import ( //"context" "context" - "encoding/json" + // "encoding/json" "fmt" - "net/http" - "net/url" - "strconv" + // "net/http" + // "net/url" + // "strconv" "github.com/gofrs/uuid" "github.com/traPtitech/go-traq" @@ -17,58 +17,74 @@ import ( func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { - URL := fmt.Sprintf("%s/users/%s", repo.URL, userID) - req, err := http.NewRequest(http.MethodGet, URL, nil) - if err != nil { - return nil, err - } - data, err := repo.doRequest(token, req) - if err != nil { - return nil, err - } - - user := new(traq.User) - err = json.Unmarshal(data, &user) - return user, err - - // ここから go-traq 書き換え - - // traqconf := traq.NewConfiguration() - // conf := oauth2.Config{ - + // URL := fmt.Sprintf("%s/users/%s", repo.URL, userID) + // req, err := http.NewRequest(http.MethodGet, URL, nil) + // if err != nil { + // return nil, err // } - // traqconf.HTTPClient = conf.Client(context.TODO(),token) - // apiClient := traq.NewAPIClient(traqconf) - // userDtail,_,err := apiClient.UserApi.GetUser(context.Background(),userID.String()).Execute() - // if err!=nil{ - // return nil,err + // data, err := repo.doRequest(token, req) + // if err != nil { + // return nil, err // } + // user := new(traq.User) + // err = json.Unmarshal(data, &user) + // return user, err + // ここから go-traq 書き換え + + traqconf := traq.NewConfiguration() + conf := TraQDefaultConfig + traqconf.HTTPClient = conf.Client(context.Background(),token) + apiClient := traq.NewAPIClient(traqconf) + userDtail,_,err := apiClient.UserApi.GetUser(context.Background(),userID.String()).Execute() + if err!=nil{ + fmt.Println("GetUserError") + return nil,err + } + user := convertUserdetailToUser(userDtail) + fmt.Println("GetUserDetailSuccess") + return user, err + // ここまで go-traq 書き換え } func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]*traq.User, error) { - URL, err := url.Parse(fmt.Sprintf("%s/users", repo.URL)) - if err != nil { - return nil, err - } - q := URL.Query() - q.Set("include-suspended", strconv.FormatBool(includeSuspended)) - URL.RawQuery = q.Encode() - req, err := http.NewRequest(http.MethodGet, URL.String(), nil) - if err != nil { - return nil, err - } - data, err := repo.doRequest(token, req) - if err != nil { - return nil, err - } + // URL, err := url.Parse(fmt.Sprintf("%s/users", repo.URL)) + // if err != nil { + // return nil, err + // } + // q := URL.Query() + // q.Set("include-suspended", strconv.FormatBool(includeSuspended)) + // URL.RawQuery = q.Encode() + // req, err := http.NewRequest(http.MethodGet, URL.String(), nil) + // if err != nil { + // return nil, err + // } + // data, err := repo.doRequest(token, req) + // if err != nil { + // return nil, err + // } - users := make([]*traq.User, 0) - err = json.Unmarshal(data, &users) - return users, err + // users := make([]*traq.User, 0) + // err = json.Unmarshal(data, &users) + + // return users, err + + traqconf := traq.NewConfiguration() + conf := TraQDefaultConfig + traqconf.HTTPClient = conf.Client(context.Background(),token) + apiClient := traq.NewAPIClient(traqconf) + users,_,err := apiClient.UserApi.GetUsers(context.Background()).IncludeSuspended(includeSuspended).Execute() + if err!=nil{ + fmt.Println("GetUsersError") + return nil,err + } + res_users := convertUsersToUsers(users) + fmt.Println("GetUsersSuccess") + fmt.Println(res_users) + return res_users, err } @@ -82,6 +98,10 @@ func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { // if err != nil { // return nil, err // } + + // user := new(traq.User) + // err = json.Unmarshal(data, &user) + // return user, err // ここから go-traq 書き換え traqconf := traq.NewConfiguration() @@ -94,6 +114,7 @@ func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { return nil,err } user := convertMyUserdetailToUser(data) + fmt.Println("GetUserMeSuccess") return user, err // ここまで go-traq 書き換え } @@ -109,3 +130,23 @@ func convertMyUserdetailToUser (userdetail *traq.MyUserDetail) *traq.User{ user.UpdatedAt=userdetail.UpdatedAt return user } + +func convertUserdetailToUser (userdetail *traq.UserDetail) *traq.User{ + user := new(traq.User) + user.Id=userdetail.Id + user.Name=userdetail.Name + user.DisplayName=userdetail.DisplayName + user.IconFileId=userdetail.IconFileId + user.Bot=userdetail.Bot + user.State=userdetail.State + user.UpdatedAt=userdetail.UpdatedAt + return user +} +func convertUsersToUsers(users []traq.User) []*traq.User{ + new_users:=make([]*traq.User,len(users)) + for i,_user := range users{ + user:=_user + new_users[i] = &user + } + return new_users +} \ No newline at end of file From a0716588a4389d9c400121b6e939254100005020 Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 26 Oct 2023 20:24:59 +0900 Subject: [PATCH 07/20] disable debag code --- infra/traq/user.go | 70 +++++----------------------------------------- 1 file changed, 7 insertions(+), 63 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index ac96eaf6..7c2b0519 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -4,7 +4,7 @@ import ( //"context" "context" // "encoding/json" - "fmt" + // "fmt" // "net/http" // "net/url" // "strconv" @@ -17,93 +17,38 @@ import ( func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { - // URL := fmt.Sprintf("%s/users/%s", repo.URL, userID) - // req, err := http.NewRequest(http.MethodGet, URL, nil) - // if err != nil { - // return nil, err - // } - // data, err := repo.doRequest(token, req) - // if err != nil { - // return nil, err - // } - - // user := new(traq.User) - // err = json.Unmarshal(data, &user) - - // return user, err - - // ここから go-traq 書き換え - traqconf := traq.NewConfiguration() conf := TraQDefaultConfig traqconf.HTTPClient = conf.Client(context.Background(),token) apiClient := traq.NewAPIClient(traqconf) userDtail,_,err := apiClient.UserApi.GetUser(context.Background(),userID.String()).Execute() if err!=nil{ - fmt.Println("GetUserError") + // fmt.Println("GetUserError") return nil,err } user := convertUserdetailToUser(userDtail) - fmt.Println("GetUserDetailSuccess") + // fmt.Println("GetUserDetailSuccess") return user, err - - // ここまで go-traq 書き換え } func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]*traq.User, error) { - // URL, err := url.Parse(fmt.Sprintf("%s/users", repo.URL)) - // if err != nil { - // return nil, err - // } - // q := URL.Query() - // q.Set("include-suspended", strconv.FormatBool(includeSuspended)) - // URL.RawQuery = q.Encode() - // req, err := http.NewRequest(http.MethodGet, URL.String(), nil) - // if err != nil { - // return nil, err - // } - // data, err := repo.doRequest(token, req) - // if err != nil { - // return nil, err - // } - - // users := make([]*traq.User, 0) - // err = json.Unmarshal(data, &users) - - // return users, err - traqconf := traq.NewConfiguration() conf := TraQDefaultConfig traqconf.HTTPClient = conf.Client(context.Background(),token) apiClient := traq.NewAPIClient(traqconf) users,_,err := apiClient.UserApi.GetUsers(context.Background()).IncludeSuspended(includeSuspended).Execute() if err!=nil{ - fmt.Println("GetUsersError") + // fmt.Println("GetUsersError") return nil,err } res_users := convertUsersToUsers(users) - fmt.Println("GetUsersSuccess") - fmt.Println(res_users) + // fmt.Println("GetUsersSuccess") + // fmt.Println(res_users) return res_users, err } func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { - // URL := fmt.Sprintf("%s/users/me", repo.URL) - // req, err := http.NewRequest(http.MethodGet, URL, nil) - // if err != nil { - // return nil, err - // } - // data, err := repo.doRequest(token, req) - // if err != nil { - // return nil, err - // } - - // user := new(traq.User) - // err = json.Unmarshal(data, &user) - // return user, err - - // ここから go-traq 書き換え traqconf := traq.NewConfiguration() conf :=TraQDefaultConfig traqconf.HTTPClient=conf.Client(context.Background(),token) @@ -114,9 +59,8 @@ func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { return nil,err } user := convertMyUserdetailToUser(data) - fmt.Println("GetUserMeSuccess") + // fmt.Println("GetUserMeSuccess") return user, err - // ここまで go-traq 書き換え } func convertMyUserdetailToUser (userdetail *traq.MyUserDetail) *traq.User{ From 82393b71d54debd5dbf11c839a3f443d191b834e Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 26 Oct 2023 21:14:18 +0900 Subject: [PATCH 08/20] Delete unused code --- infra/traq/user.go | 83 +++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 49 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index 7c2b0519..5a92ee21 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -1,96 +1,81 @@ package traq import ( - //"context" "context" - // "encoding/json" - // "fmt" - // "net/http" - // "net/url" - // "strconv" "github.com/gofrs/uuid" "github.com/traPtitech/go-traq" "golang.org/x/oauth2" ) - - func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { traqconf := traq.NewConfiguration() conf := TraQDefaultConfig - traqconf.HTTPClient = conf.Client(context.Background(),token) + traqconf.HTTPClient = conf.Client(context.Background(), token) apiClient := traq.NewAPIClient(traqconf) - userDtail,_,err := apiClient.UserApi.GetUser(context.Background(),userID.String()).Execute() - if err!=nil{ - // fmt.Println("GetUserError") - return nil,err + userDtail, _, err := apiClient.UserApi.GetUser(context.Background(), userID.String()).Execute() + if err != nil { + return nil, err } user := convertUserdetailToUser(userDtail) - // fmt.Println("GetUserDetailSuccess") return user, err } func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]*traq.User, error) { traqconf := traq.NewConfiguration() conf := TraQDefaultConfig - traqconf.HTTPClient = conf.Client(context.Background(),token) + traqconf.HTTPClient = conf.Client(context.Background(), token) apiClient := traq.NewAPIClient(traqconf) - users,_,err := apiClient.UserApi.GetUsers(context.Background()).IncludeSuspended(includeSuspended).Execute() - if err!=nil{ - // fmt.Println("GetUsersError") - return nil,err + users, _, err := apiClient.UserApi.GetUsers(context.Background()).IncludeSuspended(includeSuspended).Execute() + if err != nil { + return nil, err } res_users := convertUsersToUsers(users) - // fmt.Println("GetUsersSuccess") - // fmt.Println(res_users) return res_users, err } - func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { traqconf := traq.NewConfiguration() - conf :=TraQDefaultConfig - traqconf.HTTPClient=conf.Client(context.Background(),token) + conf := TraQDefaultConfig + traqconf.HTTPClient = conf.Client(context.Background(), token) client := traq.NewAPIClient(traqconf) - data,_,err:= client.MeApi.GetMe(context.Background()).Execute() - if err != nil{ - return nil,err + data, _, err := client.MeApi.GetMe(context.Background()).Execute() + if err != nil { + return nil, err } user := convertMyUserdetailToUser(data) - // fmt.Println("GetUserMeSuccess") return user, err } -func convertMyUserdetailToUser (userdetail *traq.MyUserDetail) *traq.User{ +func convertMyUserdetailToUser(userdetail *traq.MyUserDetail) *traq.User { user := new(traq.User) - user.Id=userdetail.Id - user.Name=userdetail.Name - user.DisplayName=userdetail.DisplayName - user.IconFileId=userdetail.IconFileId - user.Bot=userdetail.Bot - user.State=userdetail.State - user.UpdatedAt=userdetail.UpdatedAt + user.Id = userdetail.Id + user.Name = userdetail.Name + user.DisplayName = userdetail.DisplayName + user.IconFileId = userdetail.IconFileId + user.Bot = userdetail.Bot + user.State = userdetail.State + user.UpdatedAt = userdetail.UpdatedAt return user } -func convertUserdetailToUser (userdetail *traq.UserDetail) *traq.User{ +func convertUserdetailToUser(userdetail *traq.UserDetail) *traq.User { user := new(traq.User) - user.Id=userdetail.Id - user.Name=userdetail.Name - user.DisplayName=userdetail.DisplayName - user.IconFileId=userdetail.IconFileId - user.Bot=userdetail.Bot - user.State=userdetail.State - user.UpdatedAt=userdetail.UpdatedAt + user.Id = userdetail.Id + user.Name = userdetail.Name + user.DisplayName = userdetail.DisplayName + user.IconFileId = userdetail.IconFileId + user.Bot = userdetail.Bot + user.State = userdetail.State + user.UpdatedAt = userdetail.UpdatedAt return user } -func convertUsersToUsers(users []traq.User) []*traq.User{ - new_users:=make([]*traq.User,len(users)) - for i,_user := range users{ - user:=_user +func convertUsersToUsers(users []traq.User) []*traq.User { + new_users := make([]*traq.User, len(users)) + for i, _user := range users { + user := _user new_users[i] = &user } return new_users -} \ No newline at end of file +} From 862b47af4f882e94be3e8ad5248e19a2c0fd7507 Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 26 Oct 2023 21:18:06 +0900 Subject: [PATCH 09/20] delete unused variable --- utils/api.go | 43 ++++--------------------------------------- 1 file changed, 4 insertions(+), 39 deletions(-) diff --git a/utils/api.go b/utils/api.go index c3af0808..a9e04d15 100644 --- a/utils/api.go +++ b/utils/api.go @@ -7,61 +7,26 @@ import ( "encoding/hex" "errors" "net/http" - // "net/url" - // "path" - // "strconv" - // "strings" - // "github.com/labstack/echo/v4" "github.com/traPtitech/go-traq" ) -const baseURL = "https://q.trap.jp/api/v3" + // RequestWebhook q.trap/jp にメッセージを送信します。 func RequestWebhook(message, secret, channelID, webhookID string, embed int) error { - // u, err := url.Parse(baseURL + "/webhooks") - // if err != nil { - // return err - // } - // u.Path = path.Join(u.Path, webhookID) - // query := u.Query() - // query.Set("embed", strconv.Itoa(embed)) - // u.RawQuery = query.Encode() - - // req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(message)) - // if err != nil { - // return err - // } - // req.Header.Set(echo.HeaderContentType, echo.MIMETextPlain) - // req.Header.Set("X-TRAQ-Signature", calcSignature(message, secret)) - // if channelID != "" { - // req.Header.Set("X-TRAQ-Channel-Id", channelID) - // } - - // res, err := http.DefaultClient.Do(req) - // if err != nil { - // return err - // } - // if res.StatusCode >= 400 { - // return errors.New(http.StatusText(res.StatusCode)) - // } - - // ここから go-traq 書き換え xTRAQSignature := calcSignature(message, secret) configuration := traq.NewConfiguration() - apiClient := traq.NewAPIClient(configuration) + apiClient := traq.NewAPIClient(configuration) - res, err := apiClient.WebhookApi.PostWebhook(context.Background(),webhookID).XTRAQChannelId(channelID).XTRAQSignature(xTRAQSignature).Embed(int32(embed)).Body(message).Execute() - if err != nil{ + res, err := apiClient.WebhookApi.PostWebhook(context.Background(), webhookID).XTRAQChannelId(channelID).XTRAQSignature(xTRAQSignature).Embed(int32(embed)).Body(message).Execute() + if err != nil { return err } if res.StatusCode >= 400 { return errors.New(http.StatusText(res.StatusCode)) } - // ここまで go-traq 書き換え - return nil } From 5c7fa49dc1c0490bb876db87f385b1d73757e51a Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 26 Oct 2023 23:01:15 +0900 Subject: [PATCH 10/20] fix format --- utils/api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/api.go b/utils/api.go index a9e04d15..a5f6ab23 100644 --- a/utils/api.go +++ b/utils/api.go @@ -11,15 +11,15 @@ import ( "github.com/traPtitech/go-traq" ) - - // RequestWebhook q.trap/jp にメッセージを送信します。 func RequestWebhook(message, secret, channelID, webhookID string, embed int) error { xTRAQSignature := calcSignature(message, secret) configuration := traq.NewConfiguration() apiClient := traq.NewAPIClient(configuration) - res, err := apiClient.WebhookApi.PostWebhook(context.Background(), webhookID).XTRAQChannelId(channelID).XTRAQSignature(xTRAQSignature).Embed(int32(embed)).Body(message).Execute() + res, err := apiClient.WebhookApi.PostWebhook(context.Background(), webhookID). + XTRAQChannelId(channelID).XTRAQSignature(xTRAQSignature). + Embed(int32(embed)).Body(message).Execute() if err != nil { return err } From b2613cdf0e67632bade7d908735a5ed81e26359d Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 26 Oct 2023 23:02:00 +0900 Subject: [PATCH 11/20] make func MakeApiClient with token --- infra/traq/traq.go | 9 +++++++++ infra/traq/user.go | 21 ++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/infra/traq/traq.go b/infra/traq/traq.go index f1ba96c9..93d09d12 100644 --- a/infra/traq/traq.go +++ b/infra/traq/traq.go @@ -9,6 +9,7 @@ import ( "net/http" "net/url" + "github.com/traPtitech/go-traq" "github.com/traPtitech/knoQ/utils/random" "golang.org/x/oauth2" ) @@ -77,3 +78,11 @@ func (repo *TraQRepository) doRequest(token *oauth2.Token, req *http.Request) ([ } return io.ReadAll(resp.Body) } + +func MakeApiClient(token *oauth2.Token) *traq.APIClient { + traqconf := traq.NewConfiguration() + conf := TraQDefaultConfig + traqconf.HTTPClient = conf.Client(context.Background(), token) + apiClient := traq.NewAPIClient(traqconf) + return apiClient +} diff --git a/infra/traq/user.go b/infra/traq/user.go index 5a92ee21..4774f77f 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -9,23 +9,17 @@ import ( ) func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { - traqconf := traq.NewConfiguration() - conf := TraQDefaultConfig - traqconf.HTTPClient = conf.Client(context.Background(), token) - apiClient := traq.NewAPIClient(traqconf) - userDtail, _, err := apiClient.UserApi.GetUser(context.Background(), userID.String()).Execute() + apiClient := MakeApiClient(token) + userDetail, _, err := apiClient.UserApi.GetUser(context.Background(), userID.String()).Execute() if err != nil { return nil, err } - user := convertUserdetailToUser(userDtail) + user := convertUserdetailToUser(userDetail) return user, err } func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]*traq.User, error) { - traqconf := traq.NewConfiguration() - conf := TraQDefaultConfig - traqconf.HTTPClient = conf.Client(context.Background(), token) - apiClient := traq.NewAPIClient(traqconf) + apiClient := MakeApiClient(token) users, _, err := apiClient.UserApi.GetUsers(context.Background()).IncludeSuspended(includeSuspended).Execute() if err != nil { return nil, err @@ -35,12 +29,9 @@ func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) } func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { - traqconf := traq.NewConfiguration() - conf := TraQDefaultConfig - traqconf.HTTPClient = conf.Client(context.Background(), token) - client := traq.NewAPIClient(traqconf) + apiClient := MakeApiClient(token) - data, _, err := client.MeApi.GetMe(context.Background()).Execute() + data, _, err := apiClient.MeApi.GetMe(context.Background()).Execute() if err != nil { return nil, err } From 2f0d59990f3426a72c9ddf0c99bbe8ec7177b6de Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 26 Oct 2023 23:05:11 +0900 Subject: [PATCH 12/20] expand converter func UserDetail,MyUserDetail->User --- infra/traq/user.go | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index 4774f77f..cfa63012 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -14,7 +14,14 @@ func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*tra if err != nil { return nil, err } - user := convertUserdetailToUser(userDetail) + user := new(traq.User) + user.Id = userDetail.Id + user.Name = userDetail.Name + user.DisplayName = userDetail.DisplayName + user.IconFileId = userDetail.IconFileId + user.Bot = userDetail.Bot + user.State = userDetail.State + user.UpdatedAt = userDetail.UpdatedAt return user, err } @@ -31,37 +38,21 @@ func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { apiClient := MakeApiClient(token) - data, _, err := apiClient.MeApi.GetMe(context.Background()).Execute() + userDetail, _, err := apiClient.MeApi.GetMe(context.Background()).Execute() if err != nil { return nil, err } - user := convertMyUserdetailToUser(data) - return user, err -} - -func convertMyUserdetailToUser(userdetail *traq.MyUserDetail) *traq.User { user := new(traq.User) - user.Id = userdetail.Id - user.Name = userdetail.Name - user.DisplayName = userdetail.DisplayName - user.IconFileId = userdetail.IconFileId - user.Bot = userdetail.Bot - user.State = userdetail.State - user.UpdatedAt = userdetail.UpdatedAt - return user + user.Id = userDetail.Id + user.Name = userDetail.Name + user.DisplayName = userDetail.DisplayName + user.IconFileId = userDetail.IconFileId + user.Bot = userDetail.Bot + user.State = userDetail.State + user.UpdatedAt = userDetail.UpdatedAt + return user, err } -func convertUserdetailToUser(userdetail *traq.UserDetail) *traq.User { - user := new(traq.User) - user.Id = userdetail.Id - user.Name = userdetail.Name - user.DisplayName = userdetail.DisplayName - user.IconFileId = userdetail.IconFileId - user.Bot = userdetail.Bot - user.State = userdetail.State - user.UpdatedAt = userdetail.UpdatedAt - return user -} func convertUsersToUsers(users []traq.User) []*traq.User { new_users := make([]*traq.User, len(users)) for i, _user := range users { From 7608d82e8e0c13508b923a029257ed780153ecc5 Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 9 Nov 2023 20:34:39 +0900 Subject: [PATCH 13/20] add context to func MakeApiClient --- infra/traq/traq.go | 4 ++-- infra/traq/user.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/infra/traq/traq.go b/infra/traq/traq.go index 93d09d12..2d5c76c5 100644 --- a/infra/traq/traq.go +++ b/infra/traq/traq.go @@ -79,10 +79,10 @@ func (repo *TraQRepository) doRequest(token *oauth2.Token, req *http.Request) ([ return io.ReadAll(resp.Body) } -func MakeApiClient(token *oauth2.Token) *traq.APIClient { +func MakeApiClient(token *oauth2.Token, ctx context.Context) *traq.APIClient { traqconf := traq.NewConfiguration() conf := TraQDefaultConfig - traqconf.HTTPClient = conf.Client(context.Background(), token) + traqconf.HTTPClient = conf.Client(ctx, token) apiClient := traq.NewAPIClient(traqconf) return apiClient } diff --git a/infra/traq/user.go b/infra/traq/user.go index cfa63012..dcdb03e9 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -9,7 +9,7 @@ import ( ) func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { - apiClient := MakeApiClient(token) + apiClient := MakeApiClient(token, context.Background()) userDetail, _, err := apiClient.UserApi.GetUser(context.Background(), userID.String()).Execute() if err != nil { return nil, err @@ -26,17 +26,18 @@ func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*tra } func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]*traq.User, error) { - apiClient := MakeApiClient(token) + apiClient := MakeApiClient(token, context.Background()) users, _, err := apiClient.UserApi.GetUsers(context.Background()).IncludeSuspended(includeSuspended).Execute() if err != nil { return nil, err } + // return users,err res_users := convertUsersToUsers(users) return res_users, err } func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { - apiClient := MakeApiClient(token) + apiClient := MakeApiClient(token, context.Background()) userDetail, _, err := apiClient.MeApi.GetMe(context.Background()).Execute() if err != nil { From d352c8ada177deb0862748c918fe33c880df81cd Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 9 Nov 2023 20:57:39 +0900 Subject: [PATCH 14/20] change return value of GetUsers --- infra/traq/user.go | 8 ++++---- repository/user.go | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index dcdb03e9..312426ed 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -25,15 +25,15 @@ func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*tra return user, err } -func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]*traq.User, error) { +func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]traq.User, error) { apiClient := MakeApiClient(token, context.Background()) users, _, err := apiClient.UserApi.GetUsers(context.Background()).IncludeSuspended(includeSuspended).Execute() if err != nil { return nil, err } - // return users,err - res_users := convertUsersToUsers(users) - return res_users, err + return users,err + // res_users := convertUsersToUsers(users) + // return res_users, err } func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { diff --git a/repository/user.go b/repository/user.go index 83abb4c3..c7760806 100644 --- a/repository/user.go +++ b/repository/user.go @@ -181,10 +181,11 @@ func (repo *Repository) IsPrevilege(info *domain.ConInfo) bool { return user.Privilege } -func traQUserMap(users []*traq.User) map[uuid.UUID]*traq.User { +func traQUserMap(users []traq.User) map[uuid.UUID]*traq.User { userMap := make(map[uuid.UUID]*traq.User) - for _, user := range users { - userMap[uuid.Must(uuid.FromString(user.GetId()))] = user + for _, u := range users { + user:=u + userMap[uuid.Must(uuid.FromString(user.GetId()))] = &user } return userMap } From 43166d6f566737cf5785c7471434990d857af3b4 Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 9 Nov 2023 20:59:47 +0900 Subject: [PATCH 15/20] delete unused converter --- infra/traq/user.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index 312426ed..6a78f844 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -31,9 +31,7 @@ func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) if err != nil { return nil, err } - return users,err - // res_users := convertUsersToUsers(users) - // return res_users, err + return users, err } func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { @@ -53,12 +51,3 @@ func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { user.UpdatedAt = userDetail.UpdatedAt return user, err } - -func convertUsersToUsers(users []traq.User) []*traq.User { - new_users := make([]*traq.User, len(users)) - for i, _user := range users { - user := _user - new_users[i] = &user - } - return new_users -} From 3956f65d612f898fa109c0f9b505c02cdf9b22ae Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Thu, 9 Nov 2023 21:59:07 +0900 Subject: [PATCH 16/20] set context.TODO --- infra/traq/user.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index 6a78f844..1bcca09e 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -9,8 +9,9 @@ import ( ) func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { - apiClient := MakeApiClient(token, context.Background()) - userDetail, _, err := apiClient.UserApi.GetUser(context.Background(), userID.String()).Execute() + ctx := context.TODO() + apiClient := MakeApiClient(token, ctx) + userDetail, _, err := apiClient.UserApi.GetUser(ctx, userID.String()).Execute() if err != nil { return nil, err } @@ -26,8 +27,9 @@ func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*tra } func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]traq.User, error) { - apiClient := MakeApiClient(token, context.Background()) - users, _, err := apiClient.UserApi.GetUsers(context.Background()).IncludeSuspended(includeSuspended).Execute() + ctx := context.TODO() + apiClient := MakeApiClient(token, ctx) + users, _, err := apiClient.UserApi.GetUsers(ctx).IncludeSuspended(includeSuspended).Execute() if err != nil { return nil, err } @@ -35,9 +37,10 @@ func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) } func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { - apiClient := MakeApiClient(token, context.Background()) + ctx := context.TODO() + apiClient := MakeApiClient(token, ctx) - userDetail, _, err := apiClient.MeApi.GetMe(context.Background()).Execute() + userDetail, _, err := apiClient.MeApi.GetMe(ctx).Execute() if err != nil { return nil, err } From 866f6012c8e2f5df8bcbbc192c929ef5fb17b3b9 Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Tue, 19 Dec 2023 21:02:25 +0900 Subject: [PATCH 17/20] fix --- infra/traq/traq.go | 2 +- infra/traq/user.go | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/infra/traq/traq.go b/infra/traq/traq.go index 2d5c76c5..adfe458d 100644 --- a/infra/traq/traq.go +++ b/infra/traq/traq.go @@ -79,7 +79,7 @@ func (repo *TraQRepository) doRequest(token *oauth2.Token, req *http.Request) ([ return io.ReadAll(resp.Body) } -func MakeApiClient(token *oauth2.Token, ctx context.Context) *traq.APIClient { +func NewAPIClient(ctx context.Context, token *oauth2.Token) *traq.APIClient { traqconf := traq.NewConfiguration() conf := TraQDefaultConfig traqconf.HTTPClient = conf.Client(ctx, token) diff --git a/infra/traq/user.go b/infra/traq/user.go index 1bcca09e..891bd610 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -10,8 +10,12 @@ import ( func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*traq.User, error) { ctx := context.TODO() - apiClient := MakeApiClient(token, ctx) - userDetail, _, err := apiClient.UserApi.GetUser(ctx, userID.String()).Execute() + apiClient := NewAPIClient(ctx, token) + userDetail, resp, err := apiClient.UserApi.GetUser(ctx, userID.String()).Execute() + if err != nil { + return nil, err + } + err = handleStatusCode(resp.StatusCode) if err != nil { return nil, err } @@ -28,8 +32,12 @@ func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*tra func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]traq.User, error) { ctx := context.TODO() - apiClient := MakeApiClient(token, ctx) - users, _, err := apiClient.UserApi.GetUsers(ctx).IncludeSuspended(includeSuspended).Execute() + apiClient := NewAPIClient(ctx, token) + users, resp, err := apiClient.UserApi.GetUsers(ctx).IncludeSuspended(includeSuspended).Execute() + if err != nil { + return nil, err + } + err = handleStatusCode(resp.StatusCode) if err != nil { return nil, err } @@ -38,12 +46,12 @@ func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { ctx := context.TODO() - apiClient := MakeApiClient(token, ctx) - - userDetail, _, err := apiClient.MeApi.GetMe(ctx).Execute() + apiClient := NewAPIClient(ctx, token) + userDetail, resp, err := apiClient.MeApi.GetMe(ctx).Execute() if err != nil { return nil, err } + err = handleStatusCode(resp.StatusCode) user := new(traq.User) user.Id = userDetail.Id user.Name = userDetail.Name From bee1a24dcdc51261f30c573539ecfef182bf314c Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Tue, 19 Dec 2023 21:04:36 +0900 Subject: [PATCH 18/20] fix AIPClient context --- infra/traq/user.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/infra/traq/user.go b/infra/traq/user.go index 891bd610..b6cccc18 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -52,6 +52,9 @@ func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { return nil, err } err = handleStatusCode(resp.StatusCode) + if err != nil { + return nil, err + } user := new(traq.User) user.Id = userDetail.Id user.Name = userDetail.Name From eab806278beb7eefd4de78dc625071aee5e8618d Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Tue, 19 Dec 2023 21:12:30 +0900 Subject: [PATCH 19/20] fix context --- utils/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/api.go b/utils/api.go index a5f6ab23..1932e508 100644 --- a/utils/api.go +++ b/utils/api.go @@ -13,11 +13,11 @@ import ( // RequestWebhook q.trap/jp にメッセージを送信します。 func RequestWebhook(message, secret, channelID, webhookID string, embed int) error { - xTRAQSignature := calcSignature(message, secret) configuration := traq.NewConfiguration() apiClient := traq.NewAPIClient(configuration) - res, err := apiClient.WebhookApi.PostWebhook(context.Background(), webhookID). + xTRAQSignature := calcSignature(message, secret) + res, err := apiClient.WebhookApi.PostWebhook(context.TODO(), webhookID). XTRAQChannelId(channelID).XTRAQSignature(xTRAQSignature). Embed(int32(embed)).Body(message).Execute() if err != nil { From 965039f8fab94435413713aebe6b7317f04c5bdb Mon Sep 17 00:00:00 2001 From: Nzt3 Date: Tue, 19 Dec 2023 21:33:02 +0900 Subject: [PATCH 20/20] change comverter --- infra/traq/user.go | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/infra/traq/user.go b/infra/traq/user.go index b6cccc18..32d4751c 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -19,15 +19,16 @@ func (repo *TraQRepository) GetUser(token *oauth2.Token, userID uuid.UUID) (*tra if err != nil { return nil, err } - user := new(traq.User) - user.Id = userDetail.Id - user.Name = userDetail.Name - user.DisplayName = userDetail.DisplayName - user.IconFileId = userDetail.IconFileId - user.Bot = userDetail.Bot - user.State = userDetail.State - user.UpdatedAt = userDetail.UpdatedAt - return user, err + user := traq.User{ + Id: userDetail.Id, + Name: userDetail.Name, + DisplayName: userDetail.DisplayName, + IconFileId: userDetail.IconFileId, + Bot: userDetail.Bot, + State: userDetail.State, + UpdatedAt: userDetail.UpdatedAt, + } + return &user, err } func (repo *TraQRepository) GetUsers(token *oauth2.Token, includeSuspended bool) ([]traq.User, error) { @@ -55,13 +56,15 @@ func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) { if err != nil { return nil, err } - user := new(traq.User) - user.Id = userDetail.Id - user.Name = userDetail.Name - user.DisplayName = userDetail.DisplayName - user.IconFileId = userDetail.IconFileId - user.Bot = userDetail.Bot - user.State = userDetail.State - user.UpdatedAt = userDetail.UpdatedAt - return user, err + user := traq.User{ + Id: userDetail.Id, + Name: userDetail.Name, + DisplayName: userDetail.DisplayName, + IconFileId: userDetail.IconFileId, + Bot: userDetail.Bot, + State: userDetail.State, + UpdatedAt: userDetail.UpdatedAt, + } + + return &user, err }