Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix slack error #126

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions pkg/service/answer.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package service

import (
"fmt"
"time"
"net/http"
"bytes"
"io"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"strings"
"time"

"github.com/google/uuid"
"github.com/ictsc/ictsc-rikka/pkg/entity"
Expand Down Expand Up @@ -76,28 +78,38 @@ func (s *AnswerService) Create(req *CreateAnswerRequest) (*entity.Answer, error)
return nil, errors.New("problem id is invalid")
}

answer, err := s.answerRepo.Create(ans)
if err != nil {
return nil, err
}

//TODO: クリーンアーキテクチャ的にここでするべきではないので後でプレゼンターにする
{
text := fmt.Sprintf("<https://contest.mgmt.ictsc.net/scoring/%s?answer_id=%s |新着解答> 問題名:%s チーム名:%s",
strings.ToLower(problem.Code), answer.ID, problem.Title, req.UserGroup.Name)

param := struct {
Text string `json:"text"`
Text string `json:"text"`
Channel string `json:"channel"`
}{
Text: "<https://contest.mgmt.ictsc.net/#/problems/"+ req.ProblemID.String() + "|新着解答> 問題名:" + problem.Title + " チーム名:" + req.UserGroup.Name + "",
Text: text,
Channel: "#problem-" + strings.ToLower(problem.Code),
}
json_str, err := json.Marshal(param)
if err != nil { fmt.Println(err.Error()) }
fmt.Println(string(json_str))
resp, err := http.Post(s.webhook,"application/json",bytes.NewBuffer(json_str))
if err != nil { fmt.Println(err.Error()) }
body, err := io.ReadAll(resp.Body)
if err != nil { fmt.Println(err.Error()) }
fmt.Println(string(body))
if err != nil {
log.Println(err.Error())
return answer, nil
}
resp, err := http.Post(s.webhook, "application/json", bytes.NewBuffer(json_str))
if err != nil {
log.Println(err.Error())
return answer, nil
}
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}

return s.answerRepo.Create(ans)
return answer, nil
}

func (s *AnswerService) FindByID(group *entity.UserGroup, id uuid.UUID) (*entity.Answer, error) {
Expand Down