Skip to content

Commit

Permalink
Merge pull request #33 from ProjectBARO/feat/grpc-update-fcm-token
Browse files Browse the repository at this point in the history
οΏ½fcm 토큰 μˆ˜μ • κΈ°λŠ₯ κ΅¬ν˜„ (gRPC)
  • Loading branch information
YehyeokBang authored Feb 3, 2024
2 parents fb31530 + 0fb238c commit 76d8417
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 83 deletions.
23 changes: 18 additions & 5 deletions app/report/services/report_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ func NewReportService(reportRepository repositories.ReportRepositoryInterface, u
}
}

var REQUEST_URL string
var client *http.Client

func init() {
REQUEST_URL = os.Getenv("AI_SERVER_API_URL")
client = &http.Client{}
}

func (service *ReportService) Analysis(c *gin.Context, input types.RequestAnalysis) (string, error) {
user, err := service.UserUtil.FindCurrentUser(c)
if err != nil {
return "Not Found User", err
}

REQUEST_URL := os.Getenv("AI_SERVER_API_URL")

u, _ := url.Parse(REQUEST_URL)

q := u.Query()
Expand All @@ -55,7 +61,16 @@ func (service *ReportService) Analysis(c *gin.Context, input types.RequestAnalys

message := "Video submitted successfully"

go Predict(*service, u.String(), *user, input)
errCh := make(chan error, 1)
go func() {
errCh <- Predict(*service, u.String(), *user, input)
}()

defer func() {
if err := <-errCh; err != nil {
fmt.Println(err, " [", user.ID, ", ", input.VideoURL, "]")
}
}()

return message, nil
}
Expand Down Expand Up @@ -100,8 +115,6 @@ func HandleRequest(url string) (types.ResponseAnalysis, error) {
return types.ResponseAnalysis{}, err
}

client := &http.Client{}

response, err := client.Do(req)
if err != nil {
return types.ResponseAnalysis{}, err
Expand Down
21 changes: 20 additions & 1 deletion app/user/pb/user_pb_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func NewUserPbApp(userRepository repositories.UserRepositoryInterface, userUtil
func (app *UserPbApp) Login(c context.Context, req *userpb.RequestCreateUser) (*userpb.ResponseToken, error) {
user := models.User{
Name: req.Name,
Nickname: req.Nickname,
Nickname: req.Name,
FcmToken: req.FcmToken,
Email: req.Email,
Age: int(req.Age),
Gender: req.Gender,
Expand Down Expand Up @@ -64,6 +65,24 @@ func (app *UserPbApp) GetUserInfo(c context.Context, req *userpb.Empty) (*userpb
}, nil
}

func (app *UserPbApp) UpdateFcmToken(c context.Context, req *userpb.RequestUpdateFcmToken) (*userpb.ResponseUpdateFcmToken, error) {
userID := c.Value(auth.UserIDKey).(string)

user, err := app.UserRepository.FindByID(userID)
if err != nil {
return nil, err
}

user.FcmToken = req.FcmToken

_, err = app.UserRepository.Update(&user)
if err != nil {
return nil, err
}

return &userpb.ResponseUpdateFcmToken{Message: "Fcm token updated successfully"}, nil
}

func (app *UserPbApp) UpdateUserInfo(c context.Context, req *userpb.RequestUpdateUser) (*userpb.ResponseUser, error) {
userID := c.Value(auth.UserIDKey).(string)

Expand Down
Loading

0 comments on commit 76d8417

Please sign in to comment.