material.go 474 B

12345678910111213141516171819202122
  1. package repo
  2. import (
  3. "mats/db/model"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. )
  6. func MaterialGetById(ctx *RepoSession, id string, project []string) *model.Material {
  7. eid, _ := primitive.ObjectIDFromHex(id)
  8. option := DocSearchOptions{
  9. CollectName: CollectionMaterials,
  10. Query: Map{"_id": eid},
  11. Project: project,
  12. }
  13. entity := &model.Material{}
  14. ok, err := RepoSeachDoc(ctx, &option, entity)
  15. if err != nil || !ok {
  16. return nil
  17. }
  18. return entity
  19. }