add state history
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
// *dig.Container: Dig Container
|
||||
func InitializeRepositories(c *dig.Container) {
|
||||
c.Provide(NewApiRepository)
|
||||
c.Provide(NewStateHistoryRepository)
|
||||
c.Provide(NewServerRepository)
|
||||
c.Provide(NewConfigRepository)
|
||||
c.Provide(NewLookupRepository)
|
||||
|
||||
45
local/repository/stateHistory.go
Normal file
45
local/repository/stateHistory.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"acc-server-manager/local/model"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type StateHistoryRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewStateHistoryRepository(db *gorm.DB) *StateHistoryRepository {
|
||||
return &StateHistoryRepository{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
// GetAll
|
||||
// Gets All rows from Server table.
|
||||
//
|
||||
// Args:
|
||||
// context.Context: Application context
|
||||
// Returns:
|
||||
// model.ServerModel: Server object from database.
|
||||
func (as StateHistoryRepository) GetAll(ctx context.Context, id int) *[]model.StateHistory {
|
||||
db := as.db.WithContext(ctx)
|
||||
ServerModel := new([]model.StateHistory)
|
||||
db.Find(&ServerModel).Where("ID = ?", id)
|
||||
return ServerModel
|
||||
}
|
||||
|
||||
// UpdateServer
|
||||
// Updates Server row from Server table.
|
||||
//
|
||||
// Args:
|
||||
// context.Context: Application context
|
||||
// Returns:
|
||||
// model.Server: Server object from database.
|
||||
func (as StateHistoryRepository) Insert(ctx context.Context, body *model.StateHistory) *model.StateHistory {
|
||||
db := as.db.WithContext(ctx)
|
||||
db.Save(body)
|
||||
return body
|
||||
}
|
||||
Reference in New Issue
Block a user