image.go 836 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package mappers
  2. import (
  3. "git.dmitriygnatenko.ru/dima/homethings/internal/dto"
  4. "git.dmitriygnatenko.ru/dima/homethings/internal/models"
  5. )
  6. func ToImageResponse(req models.Image) dto.ImageResponse {
  7. var placeIDPtr, thingIDPtr *int
  8. if req.PlaceID.Valid {
  9. placeID := int(req.PlaceID.Int64)
  10. placeIDPtr = &placeID
  11. }
  12. if req.ThingID.Valid {
  13. thingID := int(req.ThingID.Int64)
  14. thingIDPtr = &thingID
  15. }
  16. return dto.ImageResponse{
  17. ID: req.ID,
  18. Image: req.Image,
  19. PlaceID: placeIDPtr,
  20. ThingID: thingIDPtr,
  21. CreatedAt: req.CreatedAt.Format(defaultDateTimeLayout),
  22. }
  23. }
  24. func ToImagesResponse(images []models.Image) dto.ImagesResponse {
  25. res := make([]dto.ImageResponse, 0, len(images))
  26. for _, image := range images {
  27. res = append(res, ToImageResponse(image))
  28. }
  29. return dto.ImagesResponse{Images: res}
  30. }