GetInfo get object simple information
(ctx context.Context, objectID string)
| 186 | |
| 187 | // GetInfo get object simple information |
| 188 | func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *schema.SimpleObjectInfo, err error) { |
| 189 | objectType, err := obj.GetObjectTypeStrByObjectID(objectID) |
| 190 | if err != nil { |
| 191 | return nil, err |
| 192 | } |
| 193 | switch objectType { |
| 194 | case constant.QuestionObjectType: |
| 195 | questionInfo, exist, err := os.questionRepo.GetQuestion(ctx, objectID) |
| 196 | if err != nil { |
| 197 | return nil, err |
| 198 | } |
| 199 | if !exist { |
| 200 | break |
| 201 | } |
| 202 | objInfo = &schema.SimpleObjectInfo{ |
| 203 | ObjectID: questionInfo.ID, |
| 204 | ObjectCreatorUserID: questionInfo.UserID, |
| 205 | QuestionID: questionInfo.ID, |
| 206 | QuestionCreatorUserID: questionInfo.UserID, |
| 207 | QuestionStatus: questionInfo.Status, |
| 208 | QuestionShow: questionInfo.Show, |
| 209 | ObjectType: objectType, |
| 210 | Title: questionInfo.Title, |
| 211 | Content: questionInfo.ParsedText, // todo trim |
| 212 | } |
| 213 | case constant.AnswerObjectType: |
| 214 | answerInfo, exist, err := os.answerRepo.GetAnswer(ctx, objectID) |
| 215 | if err != nil { |
| 216 | return nil, err |
| 217 | } |
| 218 | if !exist { |
| 219 | break |
| 220 | } |
| 221 | questionInfo, exist, err := os.questionRepo.GetQuestion(ctx, answerInfo.QuestionID) |
| 222 | if err != nil { |
| 223 | return nil, err |
| 224 | } |
| 225 | if !exist { |
| 226 | break |
| 227 | } |
| 228 | objInfo = &schema.SimpleObjectInfo{ |
| 229 | ObjectID: answerInfo.ID, |
| 230 | ObjectCreatorUserID: answerInfo.UserID, |
| 231 | QuestionID: answerInfo.QuestionID, |
| 232 | QuestionCreatorUserID: questionInfo.UserID, |
| 233 | QuestionStatus: questionInfo.Status, |
| 234 | QuestionShow: questionInfo.Show, |
| 235 | AnswerStatus: answerInfo.Status, |
| 236 | AnswerID: answerInfo.ID, |
| 237 | ObjectType: objectType, |
| 238 | Title: questionInfo.Title, // this should be question title |
| 239 | Content: answerInfo.ParsedText, // todo trim |
| 240 | } |
| 241 | case constant.CommentObjectType: |
| 242 | commentInfo, exist, err := os.commentRepo.GetComment(ctx, objectID) |
| 243 | if err != nil { |
| 244 | return nil, err |
| 245 | } |
no test coverage detected