Add applications
This commit is contained in:
15
services/entry/pkg/application/applications/model.go
Normal file
15
services/entry/pkg/application/applications/model.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package applications
|
||||
|
||||
type Application struct {
|
||||
Id int
|
||||
ProjectId int
|
||||
Name string
|
||||
}
|
||||
|
||||
func NewApplication(id int, projectId int, name string) *Application {
|
||||
return &Application{
|
||||
Id: id,
|
||||
ProjectId: projectId,
|
||||
Name: name,
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package applications
|
||||
|
||||
import "context"
|
||||
|
||||
type Repository interface {
|
||||
CreateApplication(ctx context.Context, name string, userId int, projectId int) (int, error)
|
||||
}
|
29
services/entry/pkg/application/applications/service.go
Normal file
29
services/entry/pkg/application/applications/service.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package applications
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
repository Repository
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewService(logger *zap.Logger, repository Repository) *Service {
|
||||
return &Service{
|
||||
logger: logger,
|
||||
repository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Service) CreateApplication(ctx context.Context, applicationName string, userId int, projectId int) (int, error) {
|
||||
if applicationName == "" {
|
||||
return -1, errors.New("application name is empty")
|
||||
}
|
||||
|
||||
applicationId, err := s.repository.CreateApplication(ctx, applicationName, userId, projectId)
|
||||
|
||||
return applicationId, err
|
||||
}
|
Reference in New Issue
Block a user