mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
api: create model to api format convertor for project
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package convert
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
project_model "code.gitea.io/gitea/models/project"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
// ToProject converts a models.Project to api.Project
|
||||
func ToProject(ctx context.Context, project *project_model.Project) *api.Project {
|
||||
if project == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &api.Project{
|
||||
ID: project.ID,
|
||||
Title: project.Title,
|
||||
Description: project.Description,
|
||||
TemplateType: uint8(project.TemplateType),
|
||||
CardType: uint8(project.CardType),
|
||||
}
|
||||
}
|
||||
|
||||
// ToProjects converts a slice of models.Project to a slice of api.Project
|
||||
func ToProjects(ctx context.Context, projects []*project_model.Project) []*api.Project {
|
||||
if projects == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]*api.Project, len(projects))
|
||||
for i, project := range projects {
|
||||
result[i] = ToProject(ctx, project)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package convert
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
column_model "code.gitea.io/gitea/models/project"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
// ToProject converts a models.Project to api.Project
|
||||
func ToColumn(ctx context.Context, column *column_model.Column) *api.Column {
|
||||
if column == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &api.Column{
|
||||
ID: column.ID,
|
||||
Title: column.Title,
|
||||
Color: column.Color,
|
||||
}
|
||||
}
|
||||
|
||||
func ToColumns(ctx context.Context, columns column_model.ColumnList) []*api.Column {
|
||||
if columns == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var apiColumns []*api.Column
|
||||
for _, column := range columns {
|
||||
apiColumns = append(apiColumns, ToColumn(ctx, column))
|
||||
}
|
||||
return apiColumns
|
||||
}
|
||||
Reference in New Issue
Block a user