2022-10-22 17:38:39 +08:00
|
|
|
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"
|
2022-10-23 17:29:35 +08:00
|
|
|
"github.com/jackc/pgtype"
|
2022-10-22 17:38:39 +08:00
|
|
|
"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,
|
2022-10-23 17:29:35 +08:00
|
|
|
Context: pgtype.JSON{Status: pgtype.Null},
|
2022-10-22 17:38:39 +08:00
|
|
|
StorageKey: data.StorageKey,
|
|
|
|
}
|
|
|
|
|
2023-07-15 16:19:49 +08:00
|
|
|
err := s.db.Get().Create(problemVersion).Error
|
2022-10-22 17:38:39 +08:00
|
|
|
if err != nil {
|
|
|
|
s.log.Warn("DatabaseError", zap.Error(err), zap.Any("problemVersion", problemVersion))
|
|
|
|
return nil, e.DatabaseError
|
|
|
|
}
|
|
|
|
|
|
|
|
return problemVersion, e.Success
|
|
|
|
}
|