MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / Collections

Method Collections

component/user.go:308–348  ·  view source on GitHub ↗

UserCollections get collections of owner or visible to current user

(ctx context.Context, req *types.UserCollectionReq)

Source from the content-addressed store, hash-verified

306
307// UserCollections get collections of owner or visible to current user
308func (c *UserComponent) Collections(ctx context.Context, req *types.UserCollectionReq) ([]types.Collection, int, error) {
309 userExists, err := c.us.IsExist(ctx, req.Owner)
310 if err != nil {
311 newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err)
312 slog.Error(newError.Error())
313 return nil, 0, newError
314 }
315
316 if !userExists {
317 return nil, 0, errors.New("user not exists")
318 }
319
320 if req.CurrentUser != "" {
321 cuserExists, err := c.us.IsExist(ctx, req.CurrentUser)
322 if err != nil {
323 newError := fmt.Errorf("failed to check for the presence of current user,error:%w", err)
324 slog.Error(newError.Error())
325 return nil, 0, newError
326 }
327
328 if !cuserExists {
329 return nil, 0, errors.New("current user not exists")
330 }
331 }
332
333 onlyPublic := req.Owner != req.CurrentUser
334 collections, total, err := c.cos.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic)
335 if err != nil {
336 newError := fmt.Errorf("failed to get collections by username,%w", err)
337 return nil, 0, newError
338 }
339
340 var newCollection []types.Collection
341 temporaryVariable, _ := json.Marshal(collections)
342 err = json.Unmarshal(temporaryVariable, &newCollection)
343 if err != nil {
344 return nil, 0, err
345 }
346
347 return newCollection, total, nil
348}
349
350func (c *UserComponent) LikeCollection(ctx context.Context, req *types.UserLikesRequest) error {
351 user, err := c.us.FindByUsername(ctx, req.CurrentUser)

Callers 1

UserCollectionsMethod · 0.45

Calls 3

ErrorMethod · 0.80
IsExistMethod · 0.45
ByUsernameMethod · 0.45

Tested by

no test coverage detected