thing_notification.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package mappers
  2. import (
  3. "time"
  4. "git.dmitriygnatenko.ru/dima/homethings/internal/dto"
  5. "git.dmitriygnatenko.ru/dima/homethings/internal/models"
  6. )
  7. func ConvertToAddThingNotificationRequestModel(req dto.AddThingNotificationRequest) (*models.AddThingNotificationRequest, error) {
  8. date, err := time.Parse(time.RFC3339, req.NotificationDate)
  9. if err != nil {
  10. return nil, err
  11. }
  12. return &models.AddThingNotificationRequest{
  13. ThingID: req.ThingID,
  14. NotificationDate: date,
  15. }, nil
  16. }
  17. func ConvertToUpdateThingNotificationRequestModel(thingID int, req dto.UpdateThingNotificationRequest) (*models.UpdateThingNotificationRequest, error) {
  18. date, err := time.Parse(time.RFC3339, req.NotificationDate)
  19. if err != nil {
  20. return nil, err
  21. }
  22. return &models.UpdateThingNotificationRequest{
  23. ThingID: thingID,
  24. NotificationDate: date,
  25. }, nil
  26. }
  27. func ConvertToThingNotificationResponseDTO(req models.ThingNotification) dto.ThingNotificationResponse {
  28. return dto.ThingNotificationResponse{
  29. ThingID: req.ThingID,
  30. NotificationDate: req.NotificationDate.Format(defaultDateTimeLayout),
  31. CreatedAt: req.CreatedAt.Format(defaultDateTimeLayout),
  32. UpdatedAt: req.UpdatedAt.Format(defaultDateTimeLayout),
  33. }
  34. }
  35. func ConvertToThingNotificationExtResponseDTO(req models.ExtThingNotification) dto.ThingNotificationExtResponse {
  36. return dto.ThingNotificationExtResponse{
  37. ThingID: req.ThingID,
  38. PlaceID: req.PlaceID,
  39. ThingTitle: req.ThingTitle,
  40. PlaceTitle: req.PlaceTitle,
  41. NotificationDate: req.NotificationDate.Format(defaultDateTimeLayout),
  42. CreatedAt: req.CreatedAt.Format(defaultDateTimeLayout),
  43. UpdatedAt: req.UpdatedAt.Format(defaultDateTimeLayout),
  44. }
  45. }
  46. func ConvertToThingNotificationsExtResponseDTO(req []models.ExtThingNotification) dto.ThingNotificationsExtResponse {
  47. res := make([]dto.ThingNotificationExtResponse, 0, len(req))
  48. for _, notification := range req {
  49. res = append(res, ConvertToThingNotificationExtResponseDTO(notification))
  50. }
  51. return dto.ThingNotificationsExtResponse{Notifications: res}
  52. }