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

Revert "Merge pull request #277 from seungkyua/20240314_revert" #278

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
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
1,362 changes: 615 additions & 747 deletions api/swagger/docs.go

Large diffs are not rendered by default.

1,362 changes: 615 additions & 747 deletions api/swagger/swagger.json

Large diffs are not rendered by default.

837 changes: 373 additions & 464 deletions api/swagger/swagger.yaml

Large diffs are not rendered by default.

63 changes: 31 additions & 32 deletions internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/openinfradev/tks-api/internal/model"
"github.com/openinfradev/tks-api/internal/repository"
"github.com/openinfradev/tks-api/pkg/domain"
)

func InitDB() (*gorm.DB, error) {
Expand Down Expand Up @@ -60,68 +59,68 @@ func migrateSchema(db *gorm.DB) error {
if err := db.AutoMigrate(&repository.CacheEmailCode{}); err != nil {
return err
}
if err := db.AutoMigrate(&domain.User{}); err != nil {
if err := db.AutoMigrate(&model.User{}); err != nil {
return err
}
if err := db.AutoMigrate(&domain.Role{}); err != nil {
if err := db.AutoMigrate(&model.Role{}); err != nil {
return err
}

// Organization
if err := db.AutoMigrate(&domain.Organization{}); err != nil {
if err := db.AutoMigrate(&model.Organization{}); err != nil {
return err
}

// CloudAccount
if err := db.AutoMigrate(&repository.CloudAccount{}); err != nil {
if err := db.AutoMigrate(&model.CloudAccount{}); err != nil {
return err
}

// StackTemplate
if err := db.AutoMigrate(&repository.StackTemplate{}); err != nil {
if err := db.AutoMigrate(&model.StackTemplate{}); err != nil {
return err
}

// Cluster
if err := db.AutoMigrate(&repository.Cluster{}); err != nil {
if err := db.AutoMigrate(&model.Cluster{}); err != nil {
return err
}
if err := db.AutoMigrate(&repository.ClusterFavorite{}); err != nil {
if err := db.AutoMigrate(&model.ClusterFavorite{}); err != nil {
return err
}

// Services
if err := db.AutoMigrate(&repository.AppGroup{}); err != nil {
if err := db.AutoMigrate(&model.AppGroup{}); err != nil {
return err
}
if err := db.AutoMigrate(&repository.Application{}); err != nil {
if err := db.AutoMigrate(&model.Application{}); err != nil {
return err
}

// AppServe
if err := db.AutoMigrate(&domain.AppServeApp{}); err != nil {
if err := db.AutoMigrate(&model.AppServeApp{}); err != nil {
return err
}
if err := db.AutoMigrate(&domain.AppServeAppTask{}); err != nil {
if err := db.AutoMigrate(&model.AppServeAppTask{}); err != nil {
return err
}

// Alert
if err := db.AutoMigrate(&repository.Alert{}); err != nil {
if err := db.AutoMigrate(&model.Alert{}); err != nil {
return err
}
if err := db.AutoMigrate(&repository.AlertAction{}); err != nil {
if err := db.AutoMigrate(&model.AlertAction{}); err != nil {
return err
}

// Role
if err := db.AutoMigrate(&domain.Role{}); err != nil {
if err := db.AutoMigrate(&model.Role{}); err != nil {
return err
}
if err := db.AutoMigrate(&domain.Permission{}); err != nil {
if err := db.AutoMigrate(&model.Permission{}); err != nil {
return err
}
if err := db.AutoMigrate(&domain.Endpoint{}); err != nil {
if err := db.AutoMigrate(&model.Endpoint{}); err != nil {
return err
}

Expand All @@ -139,6 +138,20 @@ func migrateSchema(db *gorm.DB) error {
return err
}

// Audit
if err := db.AutoMigrate(&model.Audit{}); err != nil {
return err
}

// PolicyTemplate
if err := db.AutoMigrate(&model.PolicyTemplateSupportedVersion{}); err != nil {
return err
}

if err := db.AutoMigrate(&model.PolicyTemplate{}); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -172,7 +185,7 @@ func EnsureDefaultRows(db *gorm.DB) error {
}
for _, ep := range api.ApiMap {
if _, ok := storedEps[ep.Name]; !ok {
if err := repoFactory.Endpoint.Create(&domain.Endpoint{
if err := repoFactory.Endpoint.Create(&model.Endpoint{
Name: ep.Name,
Group: ep.Group,
}); err != nil {
Expand All @@ -181,19 +194,5 @@ func EnsureDefaultRows(db *gorm.DB) error {
}
}

// Audit
if err := db.AutoMigrate(&repository.Audit{}); err != nil {
return err
}

// PolicyTemplate
if err := db.AutoMigrate(&repository.PolicyTemplateSupportedVersion{}); err != nil {
return err
}

if err := db.AutoMigrate(&repository.PolicyTemplate{}); err != nil {
return err
}

return nil
}
4 changes: 3 additions & 1 deletion internal/delivery/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const (
Admin_UpdateStackTemplate
Admin_DeleteStackTemplate
Admin_UpdateStackTemplateOrganizations
GetOrganizationStackTemplates
GetOrganizationStackTemplate

// Dashboard
GetChartsDashboard // 대시보드/대시보드/조회
Expand All @@ -119,7 +121,7 @@ const (

// Stack
GetStacks // 스택관리/조회
CreateStack // // 스택관리/생성
CreateStack // 스택관리/생성
CheckStackName // 스택관리/조회
GetStack // 스택관리/조회
UpdateStack // 스택관리/수정
Expand Down
16 changes: 16 additions & 0 deletions internal/delivery/api/generated_endpoints.go.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ var ApiMap = map[Endpoint]EndpointInfo{
Name: "Admin_UpdateStackTemplateOrganizations",
Group: "StackTemplate",
},
GetOrganizationStackTemplates: {
Name: "GetOrganizationStackTemplates",
Group: "StackTemplate",
},
GetOrganizationStackTemplate: {
Name: "GetOrganizationStackTemplate",
Group: "StackTemplate",
},
GetChartsDashboard: {
Name: "GetChartsDashboard",
Group: "Dashboard",
Expand Down Expand Up @@ -880,6 +888,10 @@ func (e Endpoint) String() string {
return "Admin_DeleteStackTemplate"
case Admin_UpdateStackTemplateOrganizations:
return "Admin_UpdateStackTemplateOrganizations"
case GetOrganizationStackTemplates:
return "GetOrganizationStackTemplates"
case GetOrganizationStackTemplate:
return "GetOrganizationStackTemplate"
case GetChartsDashboard:
return "GetChartsDashboard"
case GetChartDashboard:
Expand Down Expand Up @@ -1248,6 +1260,10 @@ func GetEndpoint(name string) Endpoint {
return Admin_DeleteStackTemplate
case "Admin_UpdateStackTemplateOrganizations":
return Admin_UpdateStackTemplateOrganizations
case "GetOrganizationStackTemplates":
return GetOrganizationStackTemplates
case "GetOrganizationStackTemplate":
return GetOrganizationStackTemplate
case "GetChartsDashboard":
return GetChartsDashboard
case "GetChartDashboard":
Expand Down
3 changes: 2 additions & 1 deletion internal/delivery/http/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/openinfradev/tks-api/internal/helper"
"github.com/openinfradev/tks-api/internal/model"
"github.com/openinfradev/tks-api/internal/pagination"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
Expand Down Expand Up @@ -272,7 +273,7 @@ func (h *AlertHandler) CreateAlertAction(w http.ResponseWriter, r *http.Request)

log.InfoWithContext(r.Context(), "alert : ", helper.ModelToJson(input))

var dto domain.AlertAction
var dto model.AlertAction
if err = serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/delivery/http/app-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/gorilla/mux"
"github.com/openinfradev/tks-api/internal/helper"
"github.com/openinfradev/tks-api/internal/model"
"github.com/openinfradev/tks-api/internal/pagination"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
Expand Down Expand Up @@ -43,7 +44,7 @@ func (h *AppGroupHandler) CreateAppGroup(w http.ResponseWriter, r *http.Request)
return
}

var dto domain.AppGroup
var dto model.AppGroup
if err = serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}
Expand Down Expand Up @@ -264,7 +265,7 @@ func (h *AppGroupHandler) CreateApplication(w http.ResponseWriter, r *http.Reque
return
}

var dto domain.Application
var dto model.Application
if err := serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}
Expand Down
51 changes: 37 additions & 14 deletions internal/delivery/http/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gorilla/mux"

"github.com/openinfradev/tks-api/internal"
"github.com/openinfradev/tks-api/internal/model"
"github.com/openinfradev/tks-api/internal/pagination"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
Expand Down Expand Up @@ -115,7 +116,7 @@ func (h *AppServeAppHandler) CreateAppServeApp(w http.ResponseWriter, r *http.Re

(appReq).SetDefaultValue()

var app domain.AppServeApp
var app model.AppServeApp
if err = serializer.Map(appReq, &app); err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "", ""))
return
Expand All @@ -131,7 +132,7 @@ func (h *AppServeAppHandler) CreateAppServeApp(w http.ResponseWriter, r *http.Re
app.Status = "PREPARING"
app.CreatedAt = now

var task domain.AppServeAppTask
var task model.AppServeAppTask
if err = serializer.Map(appReq, &task); err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "", ""))
return
Expand Down Expand Up @@ -230,7 +231,7 @@ func (h *AppServeAppHandler) CreateAppServeApp(w http.ResponseWriter, r *http.Re
// @Param soertColumn query string false "sortColumn"
// @Param sortOrder query string false "sortOrder"
// @Param filters query []string false "filters"
// @Success 200 {object} []domain.AppServeApp
// @Success 200 {object} []model.AppServeApp
// @Router /organizations/{organizationId}/projects/{projectId}/app-serve-apps [get]
// @Security JWT
func (h *AppServeAppHandler) GetAppServeApps(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -264,7 +265,13 @@ func (h *AppServeAppHandler) GetAppServeApps(w http.ResponseWriter, r *http.Requ
}

var out domain.GetAppServeAppsResponse
out.AppServeApps = apps
out.AppServeApps = make([]domain.AppServeAppResponse, len(apps))
for i, app := range apps {
if err := serializer.Map(app, &out.AppServeApps[i]); err != nil {
log.InfoWithContext(r.Context(), err)
continue
}
}

if out.Pagination, err = pg.Response(); err != nil {
log.InfoWithContext(r.Context(), err)
Expand Down Expand Up @@ -317,7 +324,7 @@ func (h *AppServeAppHandler) GetAppServeApp(w http.ResponseWriter, r *http.Reque
return
}

newTasks := make([]domain.AppServeAppTask, 0)
newTasks := make([]model.AppServeAppTask, 0)

for idx, t := range app.AppServeAppTasks {
// Rollbacking to latest task should be blocked.
Expand All @@ -330,7 +337,10 @@ func (h *AppServeAppHandler) GetAppServeApp(w http.ResponseWriter, r *http.Reque
app.AppServeAppTasks = newTasks

var out domain.GetAppServeAppResponse
out.AppServeApp = *app
if err := serializer.Map(app, &out.AppServeApp); err != nil {
log.InfoWithContext(r.Context(), err)
}

// NOTE: makeStages function's been changed to use task instead of app
//out.Stages = makeStages(app)

Expand Down Expand Up @@ -377,7 +387,9 @@ func (h *AppServeAppHandler) GetAppServeAppLatestTask(w http.ResponseWriter, r *
}

var out domain.GetAppServeAppTaskResponse
out.AppServeAppTask = *task
if err := serializer.Map(task, &out.AppServeAppTask); err != nil {
log.InfoWithContext(r.Context(), err)
}

ResponseJSON(w, r, http.StatusOK, out)
}
Expand Down Expand Up @@ -435,7 +447,7 @@ func (h *AppServeAppHandler) GetNumOfAppsOnStack(w http.ResponseWriter, r *http.
// @Param sortColumn query string false "sortColumn"
// @Param sortOrder query string false "sortOrder"
// @Param filters query []string false "filters"
// @Success 200 {object} []domain.AppServeApp
// @Success 200 {object} []model.AppServeApp
// @Router /organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/tasks [get]
// @Security JWT
func (h *AppServeAppHandler) GetAppServeAppTasksByAppId(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -463,7 +475,13 @@ func (h *AppServeAppHandler) GetAppServeAppTasksByAppId(w http.ResponseWriter, r
}

var out domain.GetAppServeAppTasksResponse
out.AppServeAppTasks = tasks
out.AppServeAppTasks = make([]domain.AppServeAppTaskResponse, len(tasks))
for i, task := range tasks {
if err := serializer.Map(task, &out.AppServeAppTasks[i]); err != nil {
log.InfoWithContext(r.Context(), err)
continue
}
}

if out.Pagination, err = pg.Response(); err != nil {
log.InfoWithContext(r.Context(), err)
Expand Down Expand Up @@ -533,14 +551,19 @@ func (h *AppServeAppHandler) GetAppServeAppTaskDetail(w http.ResponseWriter, r *
}

var out domain.GetAppServeAppTaskResponse
out.AppServeApp = *app
out.AppServeAppTask = *task
if err := serializer.Map(app, &out.AppServeApp); err != nil {
log.InfoWithContext(r.Context(), err)
}
if err := serializer.Map(task, &out.AppServeAppTask); err != nil {
log.InfoWithContext(r.Context(), err)
}

out.Stages = makeStages(task, app)

ResponseJSON(w, r, http.StatusOK, out)
}

func makeStages(task *domain.AppServeAppTask, app *domain.AppServeApp) []domain.StageResponse {
func makeStages(task *model.AppServeAppTask, app *model.AppServeApp) []domain.StageResponse {
stages := make([]domain.StageResponse, 0)

var stage domain.StageResponse
Expand Down Expand Up @@ -582,7 +605,7 @@ func makeStages(task *domain.AppServeAppTask, app *domain.AppServeApp) []domain.
return stages
}

func makeStage(task *domain.AppServeAppTask, app *domain.AppServeApp, pl string) domain.StageResponse {
func makeStage(task *model.AppServeAppTask, app *model.AppServeApp, pl string) domain.StageResponse {
taskStatus := task.Status
strategy := task.Strategy

Expand Down Expand Up @@ -774,7 +797,7 @@ func (h *AppServeAppHandler) UpdateAppServeApp(w http.ResponseWriter, r *http.Re
// from existing app config.
//appReq.SetDefaultValue()

var task domain.AppServeAppTask
var task model.AppServeAppTask
//tasks := app.AppServeAppTasks
//sort.Slice(tasks, func(i, j int) bool {
// return tasks[i].CreatedAt.String() > tasks[j].CreatedAt.String()
Expand Down
Loading
Loading