woj-server/internal/service/problem/create_version.go

30 lines
706 B
Go
Raw Normal View History

package problem
import (
2023-07-14 21:47:11 +08:00
"git.0x7f.app/WOJ/woj-server/internal/e"
"git.0x7f.app/WOJ/woj-server/internal/model"
"github.com/jackc/pgtype"
"go.uber.org/zap"
)
type CreateVersionData struct {
ProblemID uint
StorageKey string
}
func (s *service) CreateVersion(data *CreateVersionData) (*model.ProblemVersion, e.Status) {
problemVersion := &model.ProblemVersion{
ProblemID: data.ProblemID,
Context: pgtype.JSON{Status: pgtype.Null},
StorageKey: data.StorageKey,
}
2023-07-15 16:19:49 +08:00
err := s.db.Get().Create(problemVersion).Error
if err != nil {
s.log.Warn("DatabaseError", zap.Error(err), zap.Any("problemVersion", problemVersion))
return nil, e.DatabaseError
}
return problemVersion, e.Success
}