softplayer-backend/api/v1/application.go

53 lines
1.2 KiB
Go
Raw Normal View History

2024-05-04 17:48:19 +00:00
package v1
import (
"context"
"git.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
proto "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/applications"
ctrl "sigs.k8s.io/controller-runtime"
)
func NewApplicationsGrpcImpl(controller ctrl.Manager) *ApplicationServer {
return &ApplicationServer{
controller: controller,
}
}
type ApplicationServer struct {
proto.UnimplementedApplicationsServer
controller ctrl.Manager
}
// Create an environment
func (app *ApplicationServer) Create(ctx context.Context, in *proto.CreateOptions) (*proto.ApplicationFull, error) {
data := &controllers.ApplicationData{
Name: in.Metadata.Name,
Application: in.Spec.Application,
Version: in.Spec.Version,
Environemnt: in.Spec.EnvironemntId,
Config: in.Spec.Config,
RawConfig: "",
}
application := &controllers.Application{
UserID: in.GetOwnerId().GetUuid(),
Controller: app.controller,
Data: data,
Token: in.GetToken().GetToken(),
}
err := application.Create(ctx)
if err != nil {
return nil, err
}
return &proto.ApplicationFull{
Metadata: in.GetMetadata(),
Id: &proto.ApplicationId{
Uuid: application.Data.UUID,
},
Spec: in.GetSpec(),
}, nil
}