stufflog graphql server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1001 B

  1. package models
  2. import "unicode"
  3. // A Project is a vague category for issues. It's use depend on the user's judgement, as it could represent
  4. // an entire hobby/job or a single project within one.
  5. type Project struct {
  6. ID string `db:"project_id"`
  7. Name string `db:"name"`
  8. Description string `db:"description"`
  9. DailyPoints int `db:"daily_points"`
  10. }
  11. type ProjectFilter struct {
  12. ProjectIDs []string
  13. Search *string
  14. Permission *ProjectFilterPermission
  15. }
  16. type ProjectFilterPermission struct {
  17. UserID string
  18. MinLevel int
  19. MaxLevel int
  20. }
  21. func (project *Project) ValidKey() bool {
  22. if len(project.ID) < 1 || len(project.ID) > 16 {
  23. return false
  24. }
  25. for _, r := range project.ID {
  26. if !unicode.IsNumber(r) && !unicode.IsUpper(r) && !unicode.Is(unicode.Hiragana, r) && !unicode.Is(unicode.Katakana, r) && !unicode.Is(unicode.Han, r) {
  27. return false
  28. }
  29. }
  30. return true
  31. }
  32. func (pfp *ProjectFilterPermission) Valid() bool {
  33. return pfp.UserID != "" && pfp.MinLevel > 0
  34. }