Add applications

This commit is contained in:
2022-02-16 15:30:38 +01:00
parent 205adeb118
commit f35f277b16
10 changed files with 248 additions and 21 deletions

View 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,
}
}

View File

@@ -0,0 +1,7 @@
package applications
import "context"
type Repository interface {
CreateApplication(ctx context.Context, name string, userId int, projectId int) (int, error)
}

View 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
}