Paul Pan
d42ee0ce54
1. merge woj-runner scripts into woj-server 2. add woj-runner app 3. refactor submission status problem ... 4. jwt middleware update Co-authored-by: cxy004 <cxy004@qq.com> Co-authored-by: wzt <w.zhongtao@qq.com>
31 lines
761 B
Go
31 lines
761 B
Go
package problem
|
|
|
|
import (
|
|
"github.com/WHUPRJ/woj-server/internal/e"
|
|
"github.com/WHUPRJ/woj-server/internal/model"
|
|
"go.uber.org/zap"
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
func (s *service) QueryFuzz(search string, associations bool, shouldEnable bool) ([]*model.Problem, e.Status) {
|
|
problems := make([]*model.Problem, 0)
|
|
|
|
query := s.db
|
|
if associations {
|
|
query = query.Preload(clause.Associations)
|
|
}
|
|
if shouldEnable {
|
|
query = query.Where("is_enabled = true")
|
|
}
|
|
query = query.
|
|
Where(s.db.Where("title LIKE ?", "%"+search+"%").
|
|
Or("statement LIKE ?", "%"+search+"%"))
|
|
err := query.Find(&problems).Error
|
|
if err != nil {
|
|
s.log.Warn("DatabaseError", zap.Error(err), zap.Any("search", search))
|
|
return nil, e.DatabaseError
|
|
}
|
|
|
|
return problems, e.Success
|
|
}
|