-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(integration): 增加 Integration API 和相关功能
- 在 init.go 中初始化 IntegrationApi 变量,并在初始化函数中创建 IntegrationService。 - 新增 integration.go 文件,定义了 IntegrationApiImpl 结构体及其方法,包括 GetIntegration CreateIntegration UpdateIntegration 和 DeleteIntegration。 - 在 template.go 文件中,为现有的模板 API 方法增加了 SuccessMessage 函数调用。 - 新增 dao/integration.go 文件,定义了 IntegrationDB 结构体及其方法,包括 GetIntegrationByName CreateIntegration UpdateIntegrationByName 和 DeleteIntegrationByName。 - 在 entity/error.go 文件中,添加了与 Integration 相关的错误码和错误消息常量。 - 新增 entity/integration.go 文件,定义了与 Integration 相关的请求和响应结构体。 - 在 model/integration.go 文件中,为 Integration 模型的 Name 字段添加了 unique 约束。 - 更新 service/global.go 文件,在初始化数据库时创建 integrationDatabase 对象。 - 新增 service/integration.go 文件,定义了 IntegrationService 结构体及其方法,包括 GetIntegration CreateIntegration UpdateIntegration 和 DeleteIntegration。 - 在 router/integration.go 文件中,定义了 IntegrationApiRouterGroup 变量,包含了与 Integration 相关的路由配置。 - 在 router/router.go 文件中,添加了 IntegrationApiRouterGroup 到路由引擎中。 - 更新 go.mod 和 go.sum 文件,升级了 github.com/alioth-center/infrastructure 依赖到 v1.2.18 版本。
- Loading branch information
Showing
25 changed files
with
780 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/alioth-center/foreseen/app/entity" | ||
"github.com/alioth-center/foreseen/app/service" | ||
"github.com/alioth-center/infrastructure/network/http" | ||
) | ||
|
||
var IntegrationApi IntegrationApiImpl | ||
|
||
type IntegrationApiImpl struct { | ||
srv *service.IntegrationService | ||
} | ||
|
||
func (impl IntegrationApiImpl) GetIntegration() http.Chain[*entity.GetIntegrationRequest, *entity.GetIntegrationResponse] { | ||
return http.NewChain[*entity.GetIntegrationRequest, *entity.GetIntegrationResponse]( | ||
service.CheckToken[*entity.GetIntegrationRequest], | ||
service.SuccessMessage[*entity.GetIntegrationRequest], | ||
impl.srv.GetIntegration, | ||
) | ||
} | ||
|
||
func (impl IntegrationApiImpl) CreateIntegration() http.Chain[*entity.CreateIntegrationRequest, *entity.CreateIntegrationResponse] { | ||
return http.NewChain[*entity.CreateIntegrationRequest, *entity.CreateIntegrationResponse]( | ||
service.CheckToken[*entity.CreateIntegrationRequest], | ||
service.SuccessMessage[*entity.CreateIntegrationRequest], | ||
impl.srv.CreateIntegration, | ||
) | ||
} | ||
|
||
func (impl IntegrationApiImpl) UpdateIntegration() http.Chain[*entity.UpdateIntegrationRequest, *entity.UpdateIntegrationResponse] { | ||
return http.NewChain[*entity.UpdateIntegrationRequest, *entity.UpdateIntegrationResponse]( | ||
service.CheckToken[*entity.UpdateIntegrationRequest], | ||
service.SuccessMessage[*entity.UpdateIntegrationRequest], | ||
impl.srv.UpdateIntegration, | ||
) | ||
} | ||
|
||
func (impl IntegrationApiImpl) DeleteIntegration() http.Chain[*entity.DeleteIntegrationRequest, *entity.DeleteIntegrationResponse] { | ||
return http.NewChain[*entity.DeleteIntegrationRequest, *entity.DeleteIntegrationResponse]( | ||
service.CheckToken[*entity.DeleteIntegrationRequest], | ||
service.SuccessMessage[*entity.DeleteIntegrationRequest], | ||
impl.srv.DeleteIntegration, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dao | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/alioth-center/foreseen/app/model" | ||
"github.com/alioth-center/infrastructure/database" | ||
) | ||
|
||
type IntegrationDB struct { | ||
core database.DatabaseV2 | ||
} | ||
|
||
func NewIntegrationDB(core database.DatabaseV2) *IntegrationDB { | ||
return &IntegrationDB{core: core} | ||
} | ||
|
||
func (db *IntegrationDB) GetIntegrationByName(ctx context.Context, name string) (integration *model.Integration, err error) { | ||
integration = new(model.Integration) | ||
return integration, db.core.GetDataBySingleCondition(ctx, integration, model.IntegrationCols.Name, name) | ||
} | ||
|
||
func (db *IntegrationDB) CreateIntegration(ctx context.Context, integration *model.Integration) (created bool, err error) { | ||
return db.core.CreateSingleDataIfNotExist(ctx, integration) | ||
} | ||
|
||
func (db *IntegrationDB) UpdateIntegrationByName(ctx context.Context, name string, updates *model.Integration) (err error) { | ||
return db.core.UpdateDataBySingleCondition(ctx, updates, model.IntegrationCols.Name, name) | ||
} | ||
|
||
func (db *IntegrationDB) DeleteIntegrationByName(ctx context.Context, name string) (deleted bool, err error) { | ||
sess := db.core.GetGormCore(ctx).Delete(&model.Integration{}, &model.Integration{Name: name}) | ||
return sess.RowsAffected > 0, sess.Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package entity | ||
|
||
import "github.com/alioth-center/infrastructure/network/http" | ||
|
||
type GetIntegrationRequest http.NoBody | ||
|
||
type GetIntegrationResult struct { | ||
IntegrationID int `json:"integration_id"` | ||
IntegrationName string `json:"integration_name"` | ||
} | ||
|
||
type GetIntegrationResponse = BaseResponse | ||
|
||
type CreateIntegrationRequest struct { | ||
Name string `json:"name" vc:"key:name,required"` | ||
Secrets []string `json:"secrets" vc:"key:secrets,required"` | ||
} | ||
|
||
type CreateIntegrationResult struct { | ||
IntegrationID int `json:"integration_id"` | ||
IntegrationName string `json:"integration_name"` | ||
} | ||
|
||
type CreateIntegrationResponse = BaseResponse | ||
|
||
type UpdateIntegrationRequest struct { | ||
Secrets []string `json:"secrets" vc:"key:secrets,required"` | ||
} | ||
|
||
type UpdateIntegrationResult struct { | ||
IntegrationID int `json:"integration_id"` | ||
IntegrationName string `json:"integration_name"` | ||
} | ||
|
||
type UpdateIntegrationResponse = BaseResponse | ||
|
||
type DeleteIntegrationRequest http.NoBody | ||
|
||
type DeleteIntegrationResult http.NoResponse | ||
|
||
type DeleteIntegrationResponse = BaseResponse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.