12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package mappers
- import (
- "sort"
- "git.dmitriygnatenko.ru/dima/homethings/internal/dto"
- "git.dmitriygnatenko.ru/dima/homethings/internal/models"
- )
- func ToAddTagRequest(req dto.AddTagRequest) models.AddTagRequest {
- return models.AddTagRequest{
- Title: req.Title,
- Style: req.Style,
- }
- }
- func ToUpdateTagRequest(id int, req dto.UpdateTagRequest) models.UpdateTagRequest {
- return models.UpdateTagRequest{
- ID: id,
- Title: req.Title,
- Style: req.Style,
- }
- }
- func ToAddThingTagRequest(tagID int, thingID int) models.AddThingTagRequest {
- return models.AddThingTagRequest{
- ThingID: thingID,
- TagID: tagID,
- }
- }
- func ToDeleteThingTagRequest(tagID int, thingID int) models.DeleteThingTagRequest {
- return models.DeleteThingTagRequest{
- ThingID: thingID,
- TagID: tagID,
- }
- }
- func ToTagResponse(req models.Tag) dto.TagResponse {
- return dto.TagResponse{
- ID: req.ID,
- Title: req.Title,
- Style: req.Style,
- CreatedAt: req.CreatedAt.Format(defaultDateTimeLayout),
- UpdatedAt: req.UpdatedAt.Format(defaultDateTimeLayout),
- }
- }
- func ThingTagToTagResponse(req models.ThingTag) dto.TagResponse {
- return dto.TagResponse{
- ID: req.ID,
- Title: req.Title,
- Style: req.Style,
- CreatedAt: req.CreatedAt.Format(defaultDateTimeLayout),
- UpdatedAt: req.UpdatedAt.Format(defaultDateTimeLayout),
- }
- }
- func ToTagsResponse(req []models.Tag) dto.TagsResponse {
- res := make([]dto.TagResponse, 0, len(req))
- for _, p := range req {
- res = append(res, ToTagResponse(p))
- }
- sort.Slice(res, func(i, j int) bool {
- return res[i].Title < res[j].Title
- })
- return dto.TagsResponse{
- Tags: res,
- }
- }
|