You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
661 B

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
  1. package subscription
  2. import (
  3. "context"
  4. "practice_Go/api/subscription/v1"
  5. "practice_Go/internal/dao"
  6. "practice_Go/internal/model/do"
  7. "practice_Go/internal/model/dto"
  8. )
  9. func (c *ControllerV1) AddSubscription(ctx context.Context, req *v1.AddSubscriptionReq) (*dto.Result, error) {
  10. res := v1.AddSubscriptionRes{}
  11. _, err := dao.GoChannelSubscriptions.Ctx(ctx).Data(do.GoChannelSubscriptions{
  12. ChannelId: req.Id,
  13. UserId: req.UserId,
  14. }).Insert()
  15. _, err = dao.GoChannels.Ctx(ctx).Where("id",req.Id).Increment("subscription_count",1)
  16. if err != nil {
  17. return dto.Error(err.Error()), nil
  18. }
  19. res.Success = true
  20. return dto.SuccessWithData(res), nil
  21. }