(ctx context.Context, req CreateRepoDiscussionRequest)
| 24 | } |
| 25 | |
| 26 | func (c *DiscussionComponent) CreateRepoDiscussion(ctx context.Context, req CreateRepoDiscussionRequest) (*CreateDiscussionResponse, error) { |
| 27 | //TODO:check if the user can access the repo |
| 28 | |
| 29 | //get repo by namespace and name |
| 30 | repo, err := c.rs.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) |
| 31 | if err != nil { |
| 32 | return nil, fmt.Errorf("failed to find repo by path '%s/%s/%s': %w", req.RepoType, req.Namespace, req.Name, err) |
| 33 | } |
| 34 | user, err := c.us.FindByUsername(ctx, req.CurrentUser) |
| 35 | if err != nil { |
| 36 | return nil, fmt.Errorf("failed to find user by username '%s': %w", req.CurrentUser, err) |
| 37 | } |
| 38 | discussion, err := c.ds.Create(ctx, database.Discussion{ |
| 39 | Title: req.Title, |
| 40 | DiscussionableID: repo.ID, |
| 41 | DiscussionableType: database.DiscussionableTypeRepo, |
| 42 | UserID: user.ID, |
| 43 | }) |
| 44 | if err != nil { |
| 45 | return nil, fmt.Errorf("failed to create discussion: %w", err) |
| 46 | } |
| 47 | resp := &CreateDiscussionResponse{ |
| 48 | ID: discussion.ID, |
| 49 | User: &DiscussionResponse_User{ |
| 50 | ID: user.ID, |
| 51 | Username: user.Username, |
| 52 | Avatar: user.Avatar, |
| 53 | }, |
| 54 | Title: discussion.Title, |
| 55 | CommentCount: discussion.CommentCount, |
| 56 | CreatedAt: discussion.CreatedAt, |
| 57 | } |
| 58 | return resp, nil |
| 59 | } |
| 60 | |
| 61 | func (c *DiscussionComponent) GetDiscussion(ctx context.Context, id int64) (*ShowDiscussionResponse, error) { |
| 62 | discussion, err := c.ds.FindByID(ctx, id) |
nothing calls this directly
no test coverage detected