Skip to content

Commit

Permalink
Merge pull request #149 from openinfradev/serialize
Browse files Browse the repository at this point in the history
feature. refactoring serializer
  • Loading branch information
cho4036 authored Sep 14, 2023
2 parents 48ae58b + c5cd804 commit 08c035d
Show file tree
Hide file tree
Showing 22 changed files with 249 additions and 224 deletions.
15 changes: 8 additions & 7 deletions internal/delivery/http/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/gorilla/mux"
"github.com/openinfradev/tks-api/internal/helper"
"github.com/openinfradev/tks-api/internal/pagination"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
"github.com/openinfradev/tks-api/pkg/domain"
"github.com/openinfradev/tks-api/pkg/httpErrors"
Expand Down Expand Up @@ -126,13 +127,13 @@ func (h *AlertHandler) GetAlerts(w http.ResponseWriter, r *http.Request) {
var out domain.GetAlertsResponse
out.Alerts = make([]domain.AlertResponse, len(alerts))
for i, alert := range alerts {
if err := domain.Map(alert, &out.Alerts[i]); err != nil {
if err := serializer.Map(alert, &out.Alerts[i]); err != nil {
log.InfoWithContext(r.Context(), err)
}

outAlertActions := make([]domain.AlertActionResponse, len(alert.AlertActions))
for j, alertAction := range alert.AlertActions {
if err := domain.Map(alertAction, &outAlertActions[j]); err != nil {
if err := serializer.Map(alertAction, &outAlertActions[j]); err != nil {
log.InfoWithContext(r.Context(), err)
}
}
Expand All @@ -142,13 +143,13 @@ func (h *AlertHandler) GetAlerts(w http.ResponseWriter, r *http.Request) {
}
}

if err := domain.Map(*pg, &out.Pagination); err != nil {
if err := serializer.Map(*pg, &out.Pagination); err != nil {
log.InfoWithContext(r.Context(), err)
}
/*
outFilters := make([]domain.FilterResponse, len(pg.Filters))
for j, filter := range pg.Filters {
if err := domain.Map(filter, &outFilters[j]); err != nil {
if err := serializer.Map(filter, &outFilters[j]); err != nil {
log.InfoWithContext(r.Context(), err)
}
}
Expand Down Expand Up @@ -190,12 +191,12 @@ func (h *AlertHandler) GetAlert(w http.ResponseWriter, r *http.Request) {
}

var out domain.GetAlertResponse
if err := domain.Map(alert, &out.Alert); err != nil {
if err := serializer.Map(alert, &out.Alert); err != nil {
log.InfoWithContext(r.Context(), err)
}
outAlertActions := make([]domain.AlertActionResponse, len(alert.AlertActions))
for j, alertAction := range alert.AlertActions {
if err := domain.Map(alertAction, &outAlertActions[j]); err != nil {
if err := serializer.Map(alertAction, &outAlertActions[j]); err != nil {
log.InfoWithContext(r.Context(), err)
continue
}
Expand Down Expand Up @@ -279,7 +280,7 @@ func (h *AlertHandler) CreateAlertAction(w http.ResponseWriter, r *http.Request)
log.InfoWithContext(r.Context(), "alert : ", helper.ModelToJson(input))

var dto domain.AlertAction
if err = domain.Map(input, &dto); err != nil {
if err = serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}
dto.AlertId = alertId
Expand Down
13 changes: 7 additions & 6 deletions internal/delivery/http/app-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/gorilla/mux"
"github.com/openinfradev/tks-api/internal/helper"
"github.com/openinfradev/tks-api/internal/pagination"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
"github.com/openinfradev/tks-api/pkg/domain"
"github.com/openinfradev/tks-api/pkg/httpErrors"
Expand Down Expand Up @@ -42,7 +43,7 @@ func (h *AppGroupHandler) CreateAppGroup(w http.ResponseWriter, r *http.Request)
}

var dto domain.AppGroup
if err = domain.Map(input, &dto); err != nil {
if err = serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down Expand Up @@ -96,13 +97,13 @@ func (h *AppGroupHandler) GetAppGroups(w http.ResponseWriter, r *http.Request) {
var out domain.GetAppGroupsResponse
out.AppGroups = make([]domain.AppGroupResponse, len(appGroups))
for i, appGroup := range appGroups {
if err := domain.Map(appGroup, &out.AppGroups[i]); err != nil {
if err := serializer.Map(appGroup, &out.AppGroups[i]); err != nil {
log.InfoWithContext(r.Context(), err)
continue
}
}

if err := domain.Map(*pg, &out.Pagination); err != nil {
if err := serializer.Map(*pg, &out.Pagination); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down Expand Up @@ -138,7 +139,7 @@ func (h *AppGroupHandler) GetAppGroup(w http.ResponseWriter, r *http.Request) {
}

var out domain.GetAppGroupResponse
if err := domain.Map(appGroup, &out.AppGroup); err != nil {
if err := serializer.Map(appGroup, &out.AppGroup); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down Expand Up @@ -222,7 +223,7 @@ func (h *AppGroupHandler) GetApplications(w http.ResponseWriter, r *http.Request
var out domain.GetApplicationsResponse
out.Applications = make([]domain.ApplicationResponse, len(applications))
for i, application := range applications {
if err := domain.Map(application, &out.Applications[i]); err != nil {
if err := serializer.Map(application, &out.Applications[i]); err != nil {
log.InfoWithContext(r.Context(), err)
continue
}
Expand Down Expand Up @@ -262,7 +263,7 @@ func (h *AppGroupHandler) CreateApplication(w http.ResponseWriter, r *http.Reque
}

var dto domain.Application
if err := domain.Map(input, &dto); err != nil {
if err := serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}
dto.AppGroupId = appGroupId
Expand Down
15 changes: 8 additions & 7 deletions internal/delivery/http/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/openinfradev/tks-api/internal"
"github.com/openinfradev/tks-api/internal/pagination"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
"github.com/openinfradev/tks-api/pkg/domain"
"github.com/openinfradev/tks-api/pkg/httpErrors"
Expand Down Expand Up @@ -106,7 +107,7 @@ func (h *AppServeAppHandler) CreateAppServeApp(w http.ResponseWriter, r *http.Re
(appReq).SetDefaultValue()

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

var task domain.AppServeAppTask
if err = domain.Map(appReq, &task); err != nil {
if err = serializer.Map(appReq, &task); err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "", ""))
return
}
Expand Down Expand Up @@ -191,7 +192,7 @@ func (h *AppServeAppHandler) CreateAppServeApp(w http.ResponseWriter, r *http.Re
}

var out domain.CreateAppServeAppResponse
if err = domain.Map(app, &out); err != nil {
if err = serializer.Map(app, &out); err != nil {
ErrorJSON(w, r, err)
return
}
Expand Down Expand Up @@ -253,7 +254,7 @@ func (h *AppServeAppHandler) GetAppServeApps(w http.ResponseWriter, r *http.Requ
var out domain.GetAppServeAppsResponse
out.AppServeApps = apps

if err := domain.Map(*pg, &out.Pagination); err != nil {
if err := serializer.Map(*pg, &out.Pagination); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down Expand Up @@ -634,18 +635,18 @@ func (h *AppServeAppHandler) UpdateAppServeApp(w http.ResponseWriter, r *http.Re
// break
// }
//}
//if err = domain.Map(latestTask, &task); err != nil {
//if err = serializer.Map(latestTask, &task); err != nil {
// ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "", ""))
// return
//}

var latestTask = app.AppServeAppTasks[0]
if err = domain.Map(latestTask, &task); err != nil {
if err = serializer.Map(latestTask, &task); err != nil {
//ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "", ""))
return
}

if err = domain.Map(appReq, &task); err != nil {
if err = serializer.Map(appReq, &task); err != nil {
//ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "", ""))
return
}
Expand Down
3 changes: 2 additions & 1 deletion internal/delivery/http/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/openinfradev/tks-api/internal"
"github.com/openinfradev/tks-api/internal/middleware/auth/request"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
"github.com/openinfradev/tks-api/pkg/domain"
"github.com/openinfradev/tks-api/pkg/httpErrors"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) {
}

var out domain.LoginResponse
if err = domain.Map(user, &out.User); err != nil {
if err = serializer.Map(user, &out.User); err != nil {
log.ErrorWithContext(r.Context(), err)
}

Expand Down
13 changes: 7 additions & 6 deletions internal/delivery/http/cloud-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gorilla/mux"
"github.com/openinfradev/tks-api/internal/middleware/auth/request"
"github.com/openinfradev/tks-api/internal/pagination"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
"github.com/openinfradev/tks-api/pkg/domain"
"github.com/openinfradev/tks-api/pkg/httpErrors"
Expand Down Expand Up @@ -52,7 +53,7 @@ func (h *CloudAccountHandler) CreateCloudAccount(w http.ResponseWriter, r *http.
}

var dto domain.CloudAccount
if err = domain.Map(input, &dto); err != nil {
if err = serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}
dto.OrganizationId = organizationId
Expand Down Expand Up @@ -107,13 +108,13 @@ func (h *CloudAccountHandler) GetCloudAccounts(w http.ResponseWriter, r *http.Re
var out domain.GetCloudAccountsResponse
out.CloudAccounts = make([]domain.CloudAccountResponse, len(cloudAccounts))
for i, cloudAccount := range cloudAccounts {
if err := domain.Map(cloudAccount, &out.CloudAccounts[i]); err != nil {
if err := serializer.Map(cloudAccount, &out.CloudAccounts[i]); err != nil {
log.InfoWithContext(r.Context(), err)
continue
}
}

if err := domain.Map(*pg, &out.Pagination); err != nil {
if err := serializer.Map(*pg, &out.Pagination); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down Expand Up @@ -152,7 +153,7 @@ func (h *CloudAccountHandler) GetCloudAccount(w http.ResponseWriter, r *http.Req
}

var out domain.GetCloudAccountResponse
if err := domain.Map(cloudAccount, &out.CloudAccount); err != nil {
if err := serializer.Map(cloudAccount, &out.CloudAccount); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down Expand Up @@ -198,7 +199,7 @@ func (h *CloudAccountHandler) UpdateCloudAccount(w http.ResponseWriter, r *http.
}

var dto domain.CloudAccount
if err = domain.Map(input, &dto); err != nil {
if err = serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}
dto.ID = cloudAccountId
Expand Down Expand Up @@ -247,7 +248,7 @@ func (h *CloudAccountHandler) DeleteCloudAccount(w http.ResponseWriter, r *http.
}

var dto domain.CloudAccount
if err = domain.Map(input, &dto); err != nil {
if err = serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}
dto.ID = parsedId
Expand Down
11 changes: 6 additions & 5 deletions internal/delivery/http/cluster.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/pagination"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
"github.com/openinfradev/tks-api/pkg/domain"
"github.com/openinfradev/tks-api/pkg/httpErrors"
Expand Down Expand Up @@ -55,13 +56,13 @@ func (h *ClusterHandler) GetClusters(w http.ResponseWriter, r *http.Request) {
var out domain.GetClustersResponse
out.Clusters = make([]domain.ClusterResponse, len(clusters))
for i, cluster := range clusters {
if err := domain.Map(cluster, &out.Clusters[i]); err != nil {
if err := serializer.Map(cluster, &out.Clusters[i]); err != nil {
log.InfoWithContext(r.Context(), err)
continue
}
}

if err := domain.Map(*pg, &out.Pagination); err != nil {
if err := serializer.Map(*pg, &out.Pagination); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down Expand Up @@ -93,7 +94,7 @@ func (h *ClusterHandler) GetCluster(w http.ResponseWriter, r *http.Request) {
}

var out domain.GetClusterResponse
if err := domain.Map(cluster, &out.Cluster); err != nil {
if err := serializer.Map(cluster, &out.Cluster); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down Expand Up @@ -149,11 +150,11 @@ func (h *ClusterHandler) CreateCluster(w http.ResponseWriter, r *http.Request) {
}

var dto domain.Cluster
if err = domain.Map(input, &dto); err != nil {
if err = serializer.Map(input, &dto); err != nil {
log.InfoWithContext(r.Context(), err)
}

if err = domain.Map(input, &dto.Conf); err != nil {
if err = serializer.Map(input, &dto.Conf); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down
9 changes: 5 additions & 4 deletions internal/delivery/http/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/gorilla/mux"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/internal/usecase"
"github.com/openinfradev/tks-api/pkg/domain"
"github.com/openinfradev/tks-api/pkg/httpErrors"
Expand Down Expand Up @@ -72,7 +73,7 @@ func (h *DashboardHandler) GetCharts(w http.ResponseWriter, r *http.Request) {
var out domain.GetDashboardChartsResponse
out.Charts = make([]domain.DashboardChartResponse, len(charts))
for i, chart := range charts {
if err := domain.Map(chart, &out.Charts[i]); err != nil {
if err := serializer.Map(chart, &out.Charts[i]); err != nil {
log.InfoWithContext(r.Context(), err)
continue
}
Expand Down Expand Up @@ -150,7 +151,7 @@ func (h *DashboardHandler) GetChart(w http.ResponseWriter, r *http.Request) {
}

var out domain.DashboardChartResponse
if err := domain.Map(charts[0], &out); err != nil {
if err := serializer.Map(charts[0], &out); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down Expand Up @@ -189,7 +190,7 @@ func (h *DashboardHandler) GetStacks(w http.ResponseWriter, r *http.Request) {
var out domain.GetDashboardStacksResponse
out.Stacks = make([]domain.DashboardStackResponse, len(stacks))
for i, stack := range stacks {
if err := domain.Map(stack, &out.Stacks[i]); err != nil {
if err := serializer.Map(stack, &out.Stacks[i]); err != nil {
log.InfoWithContext(r.Context(), err)
continue
}
Expand Down Expand Up @@ -226,7 +227,7 @@ func (h *DashboardHandler) GetResources(w http.ResponseWriter, r *http.Request)
return
}
var out domain.GetDashboardResourcesResponse
if err := domain.Map(resources, &out.Resources); err != nil {
if err := serializer.Map(resources, &out.Resources); err != nil {
log.InfoWithContext(r.Context(), err)
}

Expand Down
Loading

0 comments on commit 08c035d

Please sign in to comment.