product_photo.go 842 B

12345678910111213141516171819202122232425262728293031323334
  1. package db
  2. import (
  3. "context"
  4. "youngee_m_api/model/gorm_model"
  5. )
  6. func GetProductPhotoByProductID(ctx context.Context, productID int64) ([]gorm_model.YounggeeProductPhoto, error) {
  7. db := GetReadDB(ctx)
  8. var productPhotos []gorm_model.YounggeeProductPhoto
  9. err := db.Where("product_id = ?", productID).Find(&productPhotos).Error
  10. if err != nil {
  11. return nil, err
  12. }
  13. return productPhotos, nil
  14. }
  15. func CreateProjectPhoto(ctx context.Context, projectPhotos []gorm_model.ProjectPhoto) error {
  16. db := GetReadDB(ctx)
  17. err := db.Create(&projectPhotos).Error
  18. if err != nil {
  19. return err
  20. }
  21. return nil
  22. }
  23. func DeleteProjectPhotoByProjecttID(ctx context.Context, productID int64) error {
  24. db := GetReadDB(ctx)
  25. err := db.Where("project_id = ?", productID).Delete(&gorm_model.ProjectPhoto{}).Error
  26. if err != nil {
  27. return err
  28. }
  29. return nil
  30. }