Пример #1
0
func (s *ApiServer) LikeEntry(ctx context.Context, req *pb.LikeRequest) (*pb.Entry, error) {
	entry, err := store.GetEntry(s.rdb, req.Entry)
	if err != nil {
		return nil, err
	}

	uuid1, err := uuid.FromString(req.User)
	if err != nil {
		return nil, err
	}
	profile, err := store.GetProfileFromUuid(s.mdb, uuid1)
	if err != nil || profile == nil {
		return nil, err
	}

	if req.Like {
		var key *store.UUIDKey
		key, entry, err = store.Like(s.rdb, profile, entry)
		if err == nil {
			s.spread(key)
		}
	} else {
		entry, err = store.DeleteLike(s.rdb, profile, entry)
	}
	return entry, err
}
Пример #2
0
func (s *ApiServer) FetchEntry(ctx context.Context, req *pb.EntryRequest) (*pb.Feed, error) {
	entry, err := store.GetEntry(s.rdb, req.Uuid)
	if err != nil {
		return nil, err
	}
	err = fmtEntryProfile(s.mdb, entry)
	if err != nil {
		return nil, err
	}

	profile, err := store.GetProfile(s.mdb, entry.From.Id)
	if err != nil {
		return nil, err
	}
	if profile == nil {
		return nil, fmt.Errorf("404")
	}

	feed := &pb.Feed{
		Uuid:        profile.Uuid,
		Id:          profile.Id,
		Name:        profile.Name,
		Type:        profile.Type,
		Private:     profile.Private,
		SupId:       profile.SupId,
		Description: profile.Description,
		Entries:     []*pb.Entry{entry},
	}
	return feed, nil
}
Пример #3
0
func (s *ApiServer) DeleteComment(ctx context.Context, req *pb.CommentDeleteRequest) (*pb.Entry, error) {
	entry, err := store.GetEntry(s.rdb, req.Entry)
	if err != nil {
		return nil, err
	}

	profile, err := store.GetProfile(s.mdb, req.User)
	if err != nil || profile == nil {
		return nil, err
	}

	return store.DeleteComment(s.rdb, profile, entry, req.Comment)
}
Пример #4
0
func (s *ApiServer) CommentEntry(ctx context.Context, req *pb.CommentRequest) (*pb.Entry, error) {
	entry, err := store.GetEntry(s.rdb, req.Entry)
	if err != nil {
		return nil, err
	}

	profile, err := store.GetProfile(s.mdb, req.Comment.From.Id)
	if err != nil || profile == nil {
		return nil, err
	}

	key, entry, err := store.Comment(s.rdb, profile, entry, req.Comment)
	if err != nil {
		return nil, err
	}
	s.spread(key)
	return entry, nil
}