You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by "Anan1225 (via GitHub)" <gi...@apache.org> on 2024/09/28 05:21:55 UTC
[PR] Add importer plugin type [incubator-answer]
Anan1225 opened a new pull request, #1122:
URL: https://github.com/apache/incubator-answer/pull/1122
OSPP Project
1. To realize add questions from Slack Slash Command, add a new plugin type importer.
2. Main function: get question detail from Client Response, then directly add question to Answer.
see [issue 151](https://github.com/apache/incubator-answer-plugins/issues/151) and plugin [user-center-slack](https://github.com/apache/incubator-answer-plugins/pull/230)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add importer plugin type [incubator-answer]
Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars commented on code in PR #1122:
URL: https://github.com/apache/incubator-answer/pull/1122#discussion_r1800780724
##########
plugin/importer.go:
##########
@@ -30,7 +32,11 @@ type QuestionImporterInfo struct {
type Importer interface {
Base
- GetQuestion(ctx *gin.Context) (questionInfo *QuestionImporterInfo, err error)
+ RegisterImporterFunc(ctx context.Context, importer ImporterFunc)
+}
+
+type ImporterFunc interface {
+ AddQuestion(ctx context.Context, questionInfo QuestionImporterInfo)
Review Comment:
It's better to return an error here. `AddQuestion(ctx context.Context, questionInfo QuestionImporterInfo) (err error)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add importer plugin type [incubator-answer]
Posted by "Anan1225 (via GitHub)" <gi...@apache.org>.
Anan1225 commented on code in PR #1122:
URL: https://github.com/apache/incubator-answer/pull/1122#discussion_r1802258683
##########
plugin/importer.go:
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package plugin
+
+import "github.com/gin-gonic/gin"
+
+type QuestionImporterInfo struct {
+ Title string `json:"title"`
+ Content string `json:"content"`
+ Tags []string `json:"tags"`
+ UserEmail string `json:"user_email"`
+}
+
+type Importer interface {
+ Base
+ GetQuestion(ctx *gin.Context) (questionInfo *QuestionImporterInfo, err error)
+}
Review Comment:
Solved
##########
plugin/importer.go:
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package plugin
+
+import "github.com/gin-gonic/gin"
+
+type QuestionImporterInfo struct {
+ Title string `json:"title"`
+ Content string `json:"content"`
+ Tags []string `json:"tags"`
+ UserEmail string `json:"user_email"`
+}
+
+type Importer interface {
+ Base
+ GetQuestion(ctx *gin.Context) (questionInfo *QuestionImporterInfo, err error)
+}
Review Comment:
Solved
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add importer plugin type [incubator-answer]
Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars merged PR #1122:
URL: https://github.com/apache/incubator-answer/pull/1122
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add importer plugin type [incubator-answer]
Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars commented on code in PR #1122:
URL: https://github.com/apache/incubator-answer/pull/1122#discussion_r1802239189
##########
internal/service/importer/importer_service.go:
##########
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package importer
+
+import (
+ "context"
+
+ "github.com/apache/incubator-answer/internal/base/handler"
+ "github.com/apache/incubator-answer/internal/base/reason"
+ "github.com/apache/incubator-answer/internal/base/translator"
+ "github.com/apache/incubator-answer/internal/base/validator"
+ "github.com/apache/incubator-answer/internal/schema"
+ "github.com/apache/incubator-answer/internal/service/content"
+ "github.com/apache/incubator-answer/internal/service/permission"
+ "github.com/apache/incubator-answer/internal/service/rank"
+ usercommon "github.com/apache/incubator-answer/internal/service/user_common"
+ "github.com/apache/incubator-answer/plugin"
+ "github.com/gin-gonic/gin"
+ "github.com/segmentfault/pacman/errors"
+ "github.com/segmentfault/pacman/log"
+)
+
+// ImporterService importer service
+type ImporterService struct {
+ questionService *content.QuestionService
+ rankService *rank.RankService
+ userCommon *usercommon.UserCommon
+}
+
+// NewRankService new rank service
+func NewImporterService(
+ questionService *content.QuestionService,
+ rankService *rank.RankService,
+ userCommon *usercommon.UserCommon) *ImporterService {
+ return &ImporterService{
+ questionService: questionService,
+ rankService: rankService,
+ userCommon: userCommon,
+ }
+}
+
+type ImporterFunc struct {
+ importerService *ImporterService
+}
+
+func (ipfunc *ImporterFunc) AddQuestion(ctx context.Context, questionInfo plugin.QuestionImporterInfo) (err error) {
+ ipfunc.importerService.ImportQuestion(ctx, questionInfo)
+ return nil
+}
+
+func (ip *ImporterService) NewImporterFunc() plugin.ImporterFunc {
+ return &ImporterFunc{importerService: ip}
+}
+
+func (ip *ImporterService) ImportQuestion(ctx context.Context, questionInfo plugin.QuestionImporterInfo) (err error) {
+ req := &schema.QuestionAdd{}
+ errFields := make([]*validator.FormErrorField, 0)
+ // To limit rate, remove the following code from comment: Part 1/2
+ // reject, rejectKey := ipc.rateLimitMiddleware.DuplicateRequestRejection(ctx, req)
+ // if reject {
+ // return
+ // }
+ user_info, exist, err := ip.userCommon.GetByEmail(ctx, questionInfo.UserEmail)
Review Comment:
userInfo
##########
internal/service/importer/importer_service.go:
##########
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package importer
+
+import (
+ "context"
+
+ "github.com/apache/incubator-answer/internal/base/handler"
+ "github.com/apache/incubator-answer/internal/base/reason"
+ "github.com/apache/incubator-answer/internal/base/translator"
+ "github.com/apache/incubator-answer/internal/base/validator"
+ "github.com/apache/incubator-answer/internal/schema"
+ "github.com/apache/incubator-answer/internal/service/content"
+ "github.com/apache/incubator-answer/internal/service/permission"
+ "github.com/apache/incubator-answer/internal/service/rank"
+ usercommon "github.com/apache/incubator-answer/internal/service/user_common"
+ "github.com/apache/incubator-answer/plugin"
+ "github.com/gin-gonic/gin"
+ "github.com/segmentfault/pacman/errors"
+ "github.com/segmentfault/pacman/log"
+)
+
+// ImporterService importer service
+type ImporterService struct {
+ questionService *content.QuestionService
+ rankService *rank.RankService
+ userCommon *usercommon.UserCommon
+}
+
+// NewRankService new rank service
+func NewImporterService(
+ questionService *content.QuestionService,
+ rankService *rank.RankService,
+ userCommon *usercommon.UserCommon) *ImporterService {
+ return &ImporterService{
+ questionService: questionService,
+ rankService: rankService,
+ userCommon: userCommon,
+ }
+}
+
+type ImporterFunc struct {
+ importerService *ImporterService
+}
+
+func (ipfunc *ImporterFunc) AddQuestion(ctx context.Context, questionInfo plugin.QuestionImporterInfo) (err error) {
+ ipfunc.importerService.ImportQuestion(ctx, questionInfo)
+ return nil
+}
+
+func (ip *ImporterService) NewImporterFunc() plugin.ImporterFunc {
+ return &ImporterFunc{importerService: ip}
+}
+
+func (ip *ImporterService) ImportQuestion(ctx context.Context, questionInfo plugin.QuestionImporterInfo) (err error) {
+ req := &schema.QuestionAdd{}
+ errFields := make([]*validator.FormErrorField, 0)
+ // To limit rate, remove the following code from comment: Part 1/2
+ // reject, rejectKey := ipc.rateLimitMiddleware.DuplicateRequestRejection(ctx, req)
+ // if reject {
+ // return
+ // }
+ user_info, exist, err := ip.userCommon.GetByEmail(ctx, questionInfo.UserEmail)
+ if err != nil {
+ log.Errorf("error: %v", err)
+ return err
+ }
+ if !exist {
+ log.Errorf("error: User Email not found")
+ return err
Review Comment:
The `err` is nil. You need to return the `fmt.Errorf("...")`
##########
internal/service/plugin_common/plugin_common_service.go:
##########
@@ -126,6 +135,7 @@ func (ps *PluginCommonService) GetUserPluginConfig(ctx context.Context, req *sch
}
func (ps *PluginCommonService) initPluginData() {
+ fmt.Println("init plugin data")
Review Comment:
Remove it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org