|
| 1 | +package dto |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + "github.com/Doer-org/glyph/internal/domain/entity" |
| 7 | +) |
| 8 | + |
| 9 | +type CommentDto struct { |
| 10 | + Id string `db:"id"` |
| 11 | + User_id string `db:"user_id"` |
| 12 | + Glyph_id string `db:"glyph_id"` |
| 13 | + Contents string `db:"contents"` |
| 14 | + Created_at time.Time `db:"created_at"` |
| 15 | +} |
| 16 | +type CommentByUserIdDto struct { |
| 17 | + Id string `db:"id"` |
| 18 | + Glyph_id string `db:"glyph_id"` |
| 19 | + Glyph_title string `db:"title"` |
| 20 | + Contents string `db:"contents"` |
| 21 | + Created_at time.Time `db:"created_at"` |
| 22 | +} |
| 23 | + |
| 24 | +type CommentsDto []CommentDto |
| 25 | +type CommentsByUserIdDto []CommentByUserIdDto |
| 26 | + |
| 27 | +func CommentEntityToDto(comment *entity.Comment) CommentDto { |
| 28 | + return CommentDto{ |
| 29 | + Id: comment.Id, |
| 30 | + User_id: comment.User_id, |
| 31 | + Glyph_id: comment.Glyph_id, |
| 32 | + Contents: comment.Contents, |
| 33 | + Created_at: comment.Created_at, |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +func CommentDtoToEntity(dto *CommentDto) *entity.Comment { |
| 38 | + dto.Created_at = dto.Created_at.In(time.FixedZone("Asia/Tokyo", 9*60*60)) |
| 39 | + return &entity.Comment{ |
| 40 | + Id: dto.Id, |
| 41 | + User_id: dto.User_id, |
| 42 | + Glyph_id: dto.Glyph_id, |
| 43 | + Contents: dto.Contents, |
| 44 | + Created_at: dto.Created_at, |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func CommentDtosToEntity(dtos CommentsDto) entity.Comments { |
| 49 | + var comments entity.Comments |
| 50 | + for _, dto := range dtos { |
| 51 | + comments = append(comments, CommentDtoToEntity(&dto)) |
| 52 | + } |
| 53 | + return comments |
| 54 | +} |
| 55 | + |
| 56 | +func CommentByUserIdDtoToEntity(dto *CommentByUserIdDto) *entity.CommentByUserId { |
| 57 | + dto.Created_at = dto.Created_at.In(time.FixedZone("Asia/Tokyo", 9*60*60)) |
| 58 | + return &entity.CommentByUserId{ |
| 59 | + Id: dto.Id, |
| 60 | + Glyph_id: dto.Glyph_id, |
| 61 | + Glyph_title: dto.Glyph_title, |
| 62 | + Contents: dto.Contents, |
| 63 | + Created_at: dto.Created_at, |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +func CommentByUserIdDtosToEntity(dtos CommentsByUserIdDto) entity.CommentsByUserId { |
| 68 | + var comments entity.CommentsByUserId |
| 69 | + for _, dto := range dtos { |
| 70 | + comments = append(comments, CommentByUserIdDtoToEntity(&dto)) |
| 71 | + } |
| 72 | + return comments |
| 73 | +} |
0 commit comments