Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/plantuml/contexts/YamlManyFilesContext.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@startuml YamlManyFilesContext

!include ../interfaces/IDataContext.puml

package infrastructure {
class YamlManyFilesContext<ItemIdType comparable, ItemType interfaces.IEntityModel<ItemIdType>> {
}

YamlManyFilesContext .down.|> IDataContext
}

@enduml
6 changes: 6 additions & 0 deletions docs/plantuml/controllers/DeviceTemplateController.puml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ package controllers{

DeviceTemplateController::service -- DeviceTemplateService

DeviceTemplateController -[hidden]l- BootStageTemplateFile

DeviceTemplateController -[hidden]l- DeviceTemplateService



@enduml
6 changes: 3 additions & 3 deletions docs/plantuml/entities/DeviceTemplateControlDesc.puml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ package domain {
+NextBoot string
}

note right of DeviceTemplateControlDesc::Emergency
note left of DeviceTemplateControlDesc::Emergency
How to control device power in case of emergency. As example: POE(For Rpi4), IPMI, ILO or PowerSwitch
end note

note right of DeviceTemplateControlDesc::Power
note left of DeviceTemplateControlDesc::Power
How to control device power. As example: POE(For Rpi4), IPMI, ILO or PowerSwitch
end note

note right of DeviceTemplateControlDesc::NextBoot
note left of DeviceTemplateControlDesc::NextBoot
How to change next boot device. As example: IPMI, ILO or NONE.
For example NONE is used for Rpi4, we control next boot by u-boot files in boot stages.
end note
Expand Down
6 changes: 3 additions & 3 deletions docs/plantuml/entities/DeviceTemplateNetworkInterface.puml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ package domain {
--
+Management boolean
}
note right of DeviceTemplateNetworkInterface::Name
note left of DeviceTemplateNetworkInterface::Name
This field is unique within device template network interfaces
end note

note right of DeviceTemplateNetworkInterface::POEIn
note left of DeviceTemplateNetworkInterface::POEIn
Only one network interface can be mark as POEIn
end note

note right of DeviceTemplateNetworkInterface::Management
note left of DeviceTemplateNetworkInterface::Management
Only one network interface can be mark as management
end note
}
Expand Down
37 changes: 37 additions & 0 deletions docs/plantuml/interfaces/IDataContext.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@startuml IDataContext

package app {
interface IDataContext<ItemIdType comparable, ItemType IEntityModel<ItemIdType>> {
+Add(item ItemType) (ItemType, error)
--
+Update(id ItemIdType, item ItemType) error
--
+Delete(id ItemIdType) error
--
+Get() (map[ItemIdType]ItemType, error)
--
+GetByID(id ItemIdType) (ItemType, error)
}

note left of IDataContext::Add
Add new item
end note

note left of IDataContext::Update
Update item by id
end note

note left of IDataContext::Delete
Delete item by id
end note

note left of IDataContext::Get
Get all items
end note

note left of IDataContext::GetByID
GetByID get item by id
end note
}

@enduml
26 changes: 26 additions & 0 deletions docs/plantuml/repositories/SliceDeviceTemplateRepository.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@startuml SliceDeviceTemplateRepository

!include SliceGenericRepository.puml
!include ../contexts/YamlManyFilesContext.puml
!include ../entities/DeviceTemplate.puml

package infrastructure {
class SliceDeviceTemplateRepository

SliceDeviceTemplateRepository -down-* SliceGenericRepository

note "EntityType is DeviceTemplate \nEntityIDType is string" as DTTypeNote

SliceGenericRepository::sliceCtx -- YamlManyFilesContext
SliceDeviceTemplateRepository .down. DTTypeNote
SliceGenericRepository <.up. DTTypeNote
DeviceTemplate .. DTTypeNote

IDataContext -[hidden]- IGenericRepository

DeviceTemplateNetworkInterface -[hidden]u- BootStageTemplate
}

infrastructure -[hidden]- domain

@enduml
14 changes: 14 additions & 0 deletions docs/plantuml/repositories/SliceGenericRepository.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@startuml SliceGenericRepository

!include ../interfaces/IGenericRepository.puml


package infrastructure {
class SliceGenericRepository<EntityIDType comparable, EntityType interfaces.IEntityModel<EntityIDType>> {
-sliceCtx interfaces.IDataContext<EntityIDType, EntityType>
}

SliceGenericRepository .down.|> IGenericRepository
}

@enduml
26 changes: 23 additions & 3 deletions docs/plantuml/services/DeviceTemplateService.puml
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
@startuml

!include ../storages/YamlDeviceTemplateStorage.puml
!include ../repositories/SliceDeviceTemplateRepository.puml
!include ../dto/DeviceTemplate/DeviceTemplateDto.puml

package app {
class DeviceTemplateService {
-storage IGenericTemplateStorage<DeviceTemplate>
-repo interfaces.IGenericRepository<string, domain.DeviceTemplate>
--
+GetList(ctx context.Context, search, orderBy, orderDirection string, page, pageSize int) (dtos.PaginatedItemsDto[dtos.DeviceTemplateDto], error)
--
+GetByName(ctx context.Context, name string) (dtos.DeviceTemplateDto, error)
}
DeviceTemplateService::storage -- YamlDeviceTemplateStorage
DeviceTemplateService::repo -- SliceDeviceTemplateRepository

note as DeviceTemplateTypes
DTOs that are used by this service
end note

DeviceTemplateService .down. DeviceTemplateTypes

DeviceTemplateTypes .down.. DeviceTemplateDto

DeviceTemplateControlDesc -[hidden]down- DeviceTemplateService

DeviceTemplateService -[hidden]down- dtos

YamlManyFilesContext -[hidden]down- IDataContext

DeviceTemplateService -[hidden]down- IGenericRepository


}



@enduml
17 changes: 0 additions & 17 deletions docs/plantuml/storages/YamlDeviceTemplateStorage.puml

This file was deleted.

219 changes: 0 additions & 219 deletions docs/plantuml/storages/YamlDeviceTemplateStorage.svg

This file was deleted.

9 changes: 0 additions & 9 deletions docs/plantuml/storages/YamlGenericTemplateStorage.puml

This file was deleted.

46 changes: 0 additions & 46 deletions docs/plantuml/storages/YamlGenericTemplateStorage.svg

This file was deleted.

41 changes: 41 additions & 0 deletions src/app/interfaces/IDataContext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package interfaces

//IDataContext is an interface for custom data context
type IDataContext[ItemIdType comparable, ItemType IEntityModel[ItemIdType]] interface {
//Add new item
//
//Params
// item - item to add
//Return
// ItemType - added item
// error - if an error occurs, otherwise nil
Add(item ItemType) (ItemType, error)
//Update item by id
//
//Params
// id - item id
// item - item to update
//Return
// error - if an error occurs, otherwise nil
Update(id ItemIdType, item ItemType) error
//Delete item by id
//
//Params
// id - item id
//Return
// error - if an error occurs, otherwise nil
Delete(id ItemIdType) error
//Get all items
//
//Return
// map[ItemIdType]ItemType - items map
Get() (map[ItemIdType]ItemType, error)
//GetByID get item by id
//
//Params
// id - item id
//Return
// ItemType - found item
// error - if an error occurs, otherwise nil
GetByID(id ItemIdType) (ItemType, error)
}
26 changes: 13 additions & 13 deletions src/app/services/DeviceTemplateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (

//DeviceTemplateService device template service structure for domain.DeviceTemplate
type DeviceTemplateService struct {
storage interfaces.IGenericTemplateStorage[domain.DeviceTemplate]
logger *logrus.Logger
repo interfaces.IGenericRepository[string, domain.DeviceTemplate]
logger *logrus.Logger
}

//NewDeviceTemplateService constructor for DeviceTemplateService
//Params
// storage - generic storage for domain.DeviceTemplate
// repo - generic repo for domain.DeviceTemplate
// log - logrus logger
func NewDeviceTemplateService(storage interfaces.IGenericTemplateStorage[domain.DeviceTemplate], log *logrus.Logger) (*DeviceTemplateService, error) {
func NewDeviceTemplateService(repository interfaces.IGenericRepository[string, domain.DeviceTemplate], log *logrus.Logger) (*DeviceTemplateService, error) {
return &DeviceTemplateService{
storage: storage,
logger: log,
repo: repository,
logger: log,
}, nil
}

Expand All @@ -50,15 +50,15 @@ func (d *DeviceTemplateService) GetList(ctx context.Context, search, orderBy, or
if pageSize < 1 {
pageSizeFinal = 10
}
queryBuilder := d.storage.NewQueryBuilder(ctx)
queryBuilder := d.repo.NewQueryBuilder(ctx)
if len(search) > 3 {
queryBuilder = d.addSearchInAllFields(search, queryBuilder)
}
templatesArr, err := d.storage.GetList(ctx, orderBy, orderDirection, pageFinal, pageSizeFinal, queryBuilder)
templatesArr, err := d.repo.GetList(ctx, orderBy, orderDirection, pageFinal, pageSizeFinal, queryBuilder)
if err != nil {
return paginatedItemsDto, err
}
count, err := d.storage.Count(ctx, queryBuilder)
count, err := d.repo.Count(ctx, queryBuilder)
if err != nil {
return paginatedItemsDto, errors.Internal.Wrap(err, "failed to count device templates")
}
Expand All @@ -73,16 +73,16 @@ func (d *DeviceTemplateService) GetList(ctx context.Context, search, orderBy, or
return paginatedItemsDto, nil
}

//GetByName Get ethernet switch by name
//GetByName Get device template by name
//Params
// ctx - context is used only for logging
// name - device template name
//Return
// *dtos.DeviceTemplateDto - point to ethernet switch dto
// *dtos.DeviceTemplateDto - point to device template dto
// error - if an error occurs, otherwise nil
func (d *DeviceTemplateService) GetByName(ctx context.Context, templateName string) (dtos.DeviceTemplateDto, error) {
dto := *new(dtos.DeviceTemplateDto)
template, err := d.storage.GetByName(ctx, templateName)
template, err := d.repo.GetByID(ctx, templateName)
if err != nil {
return dto, err
}
Expand All @@ -94,7 +94,7 @@ func (d *DeviceTemplateService) addSearchInAllFields(search string, queryBuilder
template := new(domain.DeviceTemplate)
stringFieldNames := &[]string{}
utils.GetStringFieldsNames(template, stringFieldNames)
queryGroup := d.storage.NewQueryBuilder(nil)
queryGroup := d.repo.NewQueryBuilder(context.TODO())
for i := 0; i < len(*stringFieldNames); i++ {
fieldName := (*stringFieldNames)[i]
containPass := strings.Contains(strings.ToLower(fieldName), "pass")
Expand Down
1 change: 1 addition & 0 deletions src/domain/DeviceTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package domain

//DeviceTemplate represents yaml device template as a structure
type DeviceTemplate struct {
Entity[string]
//Name template name
Name string `yaml:"name"`
//Model device model
Expand Down
Loading