51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package service_internal
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.itzana.me/strafesnet/maps-service/pkg/internal"
|
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
)
|
|
|
|
// CreateScript implements createScript operation.
|
|
//
|
|
// Create a new script.
|
|
//
|
|
// POST /scripts
|
|
func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*api.ID, error) {
|
|
script, err := svc.DB.Scripts().Create(ctx, model.Script{
|
|
ID: 0,
|
|
Name: req.Name,
|
|
Hash: model.HashSource(req.Source),
|
|
Source: req.Source,
|
|
SubmissionID: req.SubmissionID.Or(0),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &api.ID{
|
|
ID: script.ID,
|
|
}, nil
|
|
}
|
|
|
|
// GetScript implements getScript operation.
|
|
//
|
|
// Get the specified script by ID.
|
|
//
|
|
// GET /scripts/{ScriptID}
|
|
func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (*api.Script, error) {
|
|
script, err := svc.DB.Scripts().Get(ctx, params.ScriptID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &api.Script{
|
|
ID: script.ID,
|
|
Name: script.Name,
|
|
Hash: model.HashFormat(script.Hash),
|
|
Source: script.Source,
|
|
SubmissionID: script.SubmissionID,
|
|
}, nil
|
|
}
|