| | 1 | | using MRA.Infrastructure.Settings; |
| | 2 | | using MRA.DTO.Models; |
| | 3 | | using MRA.DTO.Mapper.Interfaces; |
| | 4 | | using MRA.Infrastructure.Database.Documents.Interfaces; |
| | 5 | | using MRA.Infrastructure.Database.Documents.MongoDb; |
| | 6 | | using MRA.DTO.Enums.Drawing; |
| | 7 | |
|
| | 8 | | namespace MRA.DTO.Mapper; |
| | 9 | |
|
| | 10 | | public class DrawingMapper : IDocumentMapper<DrawingModel, IDrawingDocument> |
| | 11 | | { |
| | 12 | | private readonly string _urlBase; |
| | 13 | |
|
| 20 | 14 | | public DrawingMapper(AppSettings appConfig) |
| | 15 | | { |
| 20 | 16 | | _urlBase = appConfig.AzureStorage.BlobPath; |
| 20 | 17 | | } |
| | 18 | |
|
| | 19 | | public DrawingModel ConvertToModel(IDrawingDocument drawingDocument) |
| | 20 | | { |
| 30 | 21 | | var dateDrawingAt = drawingDocument.drawingAt.ToUniversalTime(); |
| | 22 | |
|
| 30 | 23 | | return new DrawingModel |
| 30 | 24 | | { |
| 30 | 25 | | Id = drawingDocument.Id, |
| 30 | 26 | | Path = drawingDocument.path, |
| 30 | 27 | | Type = drawingDocument.type, |
| 30 | 28 | | Title = drawingDocument.title, |
| 30 | 29 | | Name = drawingDocument.name, |
| 30 | 30 | | Date = dateDrawingAt.ToString("yyyy/MM/dd"), |
| 30 | 31 | | DateHyphen = dateDrawingAt.ToString("yyyy-MM-dd"), |
| 30 | 32 | | DateObject = dateDrawingAt, |
| 30 | 33 | | Time = drawingDocument.time ?? 0, |
| 30 | 34 | | ProductType = drawingDocument.product_type, |
| 30 | 35 | | ProductName = drawingDocument.product_name, |
| 30 | 36 | | ListComments = drawingDocument.list_comments, |
| 30 | 37 | | ListCommentsStyle = drawingDocument.list_comments_style, |
| 30 | 38 | | ListCommentsPros = drawingDocument.list_comments_pros, |
| 30 | 39 | | ListCommentsCons = drawingDocument.list_comments_cons, |
| 30 | 40 | | Filter = drawingDocument.filter, |
| 30 | 41 | | Views = drawingDocument.views, |
| 30 | 42 | | Likes = drawingDocument.likes, |
| 30 | 43 | | ModelName = drawingDocument.model_name, |
| 30 | 44 | | UrlBase = _urlBase, |
| 30 | 45 | | Favorite = drawingDocument.favorite, |
| 30 | 46 | | ReferenceUrl = drawingDocument.reference_url, |
| 30 | 47 | | PathThumbnail = drawingDocument.path_thumbnail, |
| 30 | 48 | | Software = drawingDocument.software, |
| 30 | 49 | | Paper = drawingDocument.paper, |
| 30 | 50 | | SpotifyUrl = drawingDocument.spotify_url, |
| 30 | 51 | | InstagramUrl = drawingDocument.instagram_url, |
| 30 | 52 | | TwitterUrl = drawingDocument.twitter_url, |
| 30 | 53 | | ScorePopular = drawingDocument.score_popular, |
| 30 | 54 | | ScoreCritic = drawingDocument.score_critic, |
| 30 | 55 | | VotesPopular = drawingDocument.votes_popular, |
| 30 | 56 | | Tags = drawingDocument.tags, |
| 30 | 57 | | Visible = drawingDocument.visible ?? true, |
| 30 | 58 | | }; |
| | 59 | | } |
| | 60 | |
|
| | 61 | | public IDrawingDocument ConvertToDocument(DrawingModel drawing) |
| | 62 | | { |
| 7 | 63 | | var dateDrawingAt = new DateTime(drawing.DateObject.Year, drawing.DateObject.Month, drawing.DateObject.Day, |
| 7 | 64 | | 0, 0, 0, DateTimeKind.Utc).ToUniversalTime(); |
| | 65 | |
|
| 7 | 66 | | return new DrawingMongoDocument |
| 7 | 67 | | { |
| 7 | 68 | | Id = drawing.Id, |
| 7 | 69 | | path = drawing.Path, |
| 7 | 70 | | type = drawing.Type, |
| 7 | 71 | | title = drawing.Title, |
| 7 | 72 | | drawingAt = dateDrawingAt, |
| 7 | 73 | | time = drawing.Time, |
| 7 | 74 | | name = drawing.Name, |
| 7 | 75 | | product_type = drawing.ProductType, |
| 7 | 76 | | product_name = drawing.ProductName, |
| 7 | 77 | | list_comments = drawing.ListComments, |
| 7 | 78 | | list_comments_pros = drawing.ListCommentsPros, |
| 7 | 79 | | list_comments_cons = drawing.ListCommentsCons, |
| 7 | 80 | | list_comments_style = drawing.ListCommentsStyle, |
| 7 | 81 | | views = drawing.Views, |
| 7 | 82 | | likes = drawing.Likes, |
| 7 | 83 | | filter = drawing.Filter, |
| 7 | 84 | | model_name = drawing.ModelName, |
| 7 | 85 | | favorite = drawing.Favorite, |
| 7 | 86 | | reference_url = drawing.ReferenceUrl, |
| 7 | 87 | | twitter_url = drawing.TwitterUrl, |
| 7 | 88 | | instagram_url = drawing.InstagramUrl, |
| 7 | 89 | | path_thumbnail = drawing.PathThumbnail, |
| 7 | 90 | | software = drawing.Software, |
| 7 | 91 | | paper = drawing.Paper, |
| 7 | 92 | | spotify_url = drawing.SpotifyUrl, |
| 7 | 93 | | tags = drawing.Tags, |
| 7 | 94 | | votes_popular = drawing.VotesPopular, |
| 7 | 95 | | score_critic = drawing.ScoreCritic, |
| 7 | 96 | | score_popular = drawing.ScorePopular, |
| 7 | 97 | | visible = drawing.Visible |
| 7 | 98 | | }; |
| | 99 | | } |
| | 100 | | } |