status updates

This commit is contained in:
Fran Jurmanović
2025-05-06 23:46:02 +02:00
parent d5140783ca
commit a1bcc080f1
9 changed files with 175 additions and 61 deletions

View File

@@ -62,3 +62,22 @@ func (as ServerRepository) GetAll(ctx context.Context) *[]model.Server {
db.Find(&ServerModel)
return ServerModel
}
// UpdateServer
// Updates Server row from Server table.
//
// Args:
// context.Context: Application context
// Returns:
// model.Server: Server object from database.
func (as ServerRepository) UpdateServer(ctx context.Context, body *model.Server) *model.Server {
db := as.db.WithContext(ctx)
existingServer := new(model.Server)
result := db.Where("id=?", body.ID).First(existingServer)
if !errors.Is(result.Error, gorm.ErrRecordNotFound) {
body.ID = existingServer.ID
}
db.Save(body)
return body
}