Skip to content

Commit

Permalink
feat: plugin creation support (#5630)
Browse files Browse the repository at this point in the history
* wip: new plugin creation api and min plugin api with only shared plugin list

* wip: create new plugin version code

* wip:plugin type SHARED by default

* wip:find plugin either by identifier or by id while creating a new version of existing plugin

* wip: create new plugin tag logic improved

* wip: optimize GetAllFilteredPluginParentMetadata query

* wip: create plugin tag new flow

* wip: minor fix

* wip: minor fix

* wip: minor fix

* wip: newTagsPresent -> areNewTagsPresent

* wip: icon is not  mandatory code incorporated

* wip:minor refactoring

* wip: prevent duplicate version from being created and save tags relation only when

* wip: minor fix

* wip: details api, get all plugin data or non

* wip: code review incorp part -1

* wip: code review incorp part -2

* wip: code review incorp part -3

* wip: remove code duplication

* wip: hardcode isExposed to true

* wip: hardcode StepType= inline

* wip: set default VariableStepIndex= 1
  • Loading branch information
prakash100198 authored Sep 2, 2024
1 parent c66ccf5 commit 4296366
Show file tree
Hide file tree
Showing 8 changed files with 757 additions and 103 deletions.
67 changes: 67 additions & 0 deletions api/restHandler/GlobalPluginRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

type GlobalPluginRestHandler interface {
PatchPlugin(w http.ResponseWriter, r *http.Request)
CreatePlugin(w http.ResponseWriter, r *http.Request)

GetAllGlobalVariables(w http.ResponseWriter, r *http.Request)
ListAllPlugins(w http.ResponseWriter, r *http.Request)
Expand All @@ -46,6 +47,7 @@ type GlobalPluginRestHandler interface {
GetPluginDetailByIds(w http.ResponseWriter, r *http.Request)
GetAllUniqueTags(w http.ResponseWriter, r *http.Request)
MigratePluginData(w http.ResponseWriter, r *http.Request)
GetAllPluginMinData(w http.ResponseWriter, r *http.Request)
}

func NewGlobalPluginRestHandler(logger *zap.SugaredLogger, globalPluginService plugin.GlobalPluginService,
Expand Down Expand Up @@ -420,3 +422,68 @@ func (handler *GlobalPluginRestHandlerImpl) MigratePluginData(w http.ResponseWri
}
common.WriteJsonResp(w, nil, nil, http.StatusOK)
}

func (handler *GlobalPluginRestHandlerImpl) CreatePlugin(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
token := r.Header.Get("token")
appId, err := common.ExtractIntQueryParam(w, r, "appId", 0)
if err != nil {
return
}
ok, err := handler.IsUserAuthorized(token, appId)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
decoder := json.NewDecoder(r.Body)
var pluginDataDto bean.PluginParentMetadataDto
err = decoder.Decode(&pluginDataDto)
if err != nil {
handler.logger.Errorw("request err, CreatePlugin", "error", err, "payload", pluginDataDto)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
handler.logger.Infow("request payload received for creating plugins", pluginDataDto, "userId", userId)

pluginVersionId, err := handler.globalPluginService.CreatePluginOrVersions(&pluginDataDto, userId)
if err != nil {
handler.logger.Errorw("service error, error in creating plugin", "pluginCreateRequestDto", pluginDataDto, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

common.WriteJsonResp(w, nil, bean.NewPluginMinDto().WithPluginVersionId(pluginVersionId), http.StatusOK)
}

func (handler *GlobalPluginRestHandlerImpl) GetAllPluginMinData(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
appId, err := common.ExtractIntQueryParam(w, r, "appId", 0)
if err != nil {
return
}
ok, err := handler.IsUserAuthorized(token, appId)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}

pluginDetail, err := handler.globalPluginService.GetAllPluginMinData()
if err != nil {
handler.logger.Errorw("error in getting all unique tags", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, nil, pluginDetail, http.StatusOK)
}
5 changes: 4 additions & 1 deletion api/router/GlobalPluginRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type GlobalPluginRouterImpl struct {
func (impl *GlobalPluginRouterImpl) initGlobalPluginRouter(globalPluginRouter *mux.Router) {
globalPluginRouter.Path("/migrate").
HandlerFunc(impl.globalPluginRestHandler.MigratePluginData).Methods("PUT")

globalPluginRouter.Path("/create").
HandlerFunc(impl.globalPluginRestHandler.CreatePlugin).Methods("POST")
// versioning impact handling to be done for below apis,
globalPluginRouter.Path("").
HandlerFunc(impl.globalPluginRestHandler.PatchPlugin).Methods("POST")
Expand All @@ -68,5 +69,7 @@ func (impl *GlobalPluginRouterImpl) initGlobalPluginRouter(globalPluginRouter *m

globalPluginRouter.Path("/list/tags").
HandlerFunc(impl.globalPluginRestHandler.GetAllUniqueTags).Methods("GET")
globalPluginRouter.Path("/list/v2/min").
HandlerFunc(impl.globalPluginRestHandler.GetAllPluginMinData).Methods("GET")

}
9 changes: 9 additions & 0 deletions internal/util/ErrorUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"net/http"
"strconv"
)

type ApiError struct {
Expand All @@ -36,6 +37,14 @@ type ApiError struct {
UserDetailMessage string `json:"userDetailMessage,omitempty"`
}

func GetApiError(code int, userMessage, internalMessage string) *ApiError {
return &ApiError{
HttpStatusCode: code,
Code: strconv.Itoa(code),
InternalMessage: internalMessage,
UserMessage: userMessage,
}
}
func NewApiError() *ApiError {
return &ApiError{}
}
Expand Down
Loading

0 comments on commit 4296366

Please sign in to comment.