1 /*
2 * Copyright (C) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #define MLOG_TAG "MEDIA_CLOUD_DTO"
17
18 #include "photos_dto.h"
19
20 #include <sstream>
21
22 namespace OHOS::Media::CloudSync {
GetAttachment(std::stringstream & ss) const23 void PhotosDto::GetAttachment(std::stringstream &ss) const
24 {
25 bool first = true;
26 for (auto &node : attachment) {
27 if (!first) {
28 ss << ", ";
29 }
30 ss << "\"" << node.first << "\": " << node.second.ToString();
31 first = false;
32 }
33 }
34
GetBasicInfo(std::stringstream & ss) const35 void PhotosDto::GetBasicInfo(std::stringstream &ss) const
36 {
37 ss << "\"cloudId\": \"" << this->cloudId << "\", "
38 << "\"data\": \"" << this->data << "\", "
39 << "\"path\": \"" << this->path << "\", "
40 << "\"size\": " << this->size << ", "
41 << "\"dateModified\": " << this->dateModified << ", "
42 << "\"dirty\": " << this->dirty << ", "
43 << "\"dateTrashed\": " << this->dateTrashed << ", "
44 << "\"localId\": " << this->localId << ", "
45 << "\"dkRecordId\": \"" << this->dkRecordId << "\", "
46 << "\"cloudVersion\": " << this->cloudVersion << ", "
47 << "\"fileId\": " << this->fileId << ", "
48 << "\"fileType\": " << this->fileType << ", "
49 << "\"relativePath\": \"" << this->relativePath << "\", ";
50 }
51
GetAttributesInfo(std::stringstream & ss) const52 void PhotosDto::GetAttributesInfo(std::stringstream &ss) const
53 {
54 ss << "\"ownerAlbumId\": " << this->ownerAlbumId << ", "
55 << "\"syncStatus\": " << this->syncStatus << ", "
56 << "\"thumbStatus\": " << this->thumbStatus << ", "
57 << "\"orientation\": " << this->orientation << ", "
58 << "\"subtype\": " << this->subtype << ", "
59 << "\"movingPhotoEffectMode\": " << this->movingPhotoEffectMode << ", "
60 << "\"originalSubtype\": " << this->originalSubtype << ", "
61 << "\"livePhotoCachePath\": \"" << this->livePhotoCachePath << "\", "
62 << "\"mimeType\": " << this->mimeType << ", "
63 << "\"mediaType\": " << this->mediaType << ", "
64 << "\"serverErrorCode\": " << this->serverErrorCode << ", "
65 << "\"cloudAlbumId\": " << this->cloudAlbumId << ", "
66 << "\"rotation\": " << this->rotation << ", "
67 << "\"version\": " << this->version << ", "
68 << "\"errorType\": " << this->errorType << ", ";
69 }
70
GetPropertiesInfo(std::stringstream & ss) const71 void PhotosDto::GetPropertiesInfo(std::stringstream &ss) const
72 {
73 ss << "\"metaDateModified\": " << this->metaDateModified << ", "
74 << "\"editedTimeMs\": " << this->editedTimeMs << ", "
75 << "\"modifyTime\": " << this->modifiedTime << ", "
76 << "\"createTime\": " << this->createTime << ", "
77 << "\"dateAdded\": " << this->dateAdded << ", ";
78 }
79
ToString() const80 std::string PhotosDto::ToString() const
81 {
82 std::stringstream ss;
83 ss << "{";
84 this->GetBasicInfo(ss);
85 this->GetAttributesInfo(ss);
86 this->GetPropertiesInfo(ss);
87 ss << "\"isSuccess\": " << std::to_string(this->isSuccess) << ", \"errorDetails\":[";
88 for (uint32_t i = 0; i < errorDetails.size(); ++i) {
89 if (i != errorDetails.size() - 1) {
90 ss << errorDetails[i].ToString() << ",";
91 continue;
92 }
93 ss << errorDetails[i].ToString();
94 }
95 ss << "]";
96 ss << "\"attachment\": {";
97 this->GetAttachment(ss);
98 ss << "}"
99 << "}";
100 return ss.str();
101 }
102 } // namespace OHOS::Media::CloudSync