refactor
This commit is contained in:
@@ -245,10 +245,11 @@ func (c *Client) GetProjects(
|
||||
|
||||
func (c *Client) GetProject(
|
||||
ctx context.Context,
|
||||
jwt string,
|
||||
workspaceID string,
|
||||
projectID string,
|
||||
) (*Project, error) {
|
||||
path := fmt.Sprintf("api/v1/internal/projects/%s/%s", workspaceID, projectID)
|
||||
path := fmt.Sprintf("api/v1/workspaces/%s/projects/%s", workspaceID, projectID)
|
||||
|
||||
var project Project
|
||||
err := c.do(
|
||||
@@ -257,6 +258,7 @@ func (c *Client) GetProject(
|
||||
path,
|
||||
nil,
|
||||
&project,
|
||||
withBearer(jwt),
|
||||
)
|
||||
|
||||
return &project, err
|
||||
@@ -558,13 +560,14 @@ type PlacementDetails struct {
|
||||
}
|
||||
|
||||
type PlacementOutput struct {
|
||||
ID string `json:"id"`
|
||||
Status string `json:"status"`
|
||||
Comment *string `json:"comment,omitempty"`
|
||||
InviteLink string `json:"invite_link"`
|
||||
InviteLinkType string `json:"invite_link_type"`
|
||||
Channel Channel `json:"channel"`
|
||||
Details *PlacementDetails `json:"details,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Status string `json:"status"`
|
||||
Comment *string `json:"comment,omitempty"`
|
||||
InviteLink string `json:"invite_link"`
|
||||
InviteLinkType string `json:"invite_link_type"`
|
||||
Channel Channel `json:"channel"`
|
||||
Details *PlacementDetails `json:"details,omitempty"`
|
||||
PlacementPosts []PlacementPostOutput `json:"placement_posts,omitempty"`
|
||||
}
|
||||
|
||||
type PlacementPostOutput struct {
|
||||
@@ -594,10 +597,6 @@ type GetPlacementsOutput struct {
|
||||
Placements []PlacementOutput `json:"placements"`
|
||||
}
|
||||
|
||||
type GetPlacementPostsOutput struct {
|
||||
PlacementPosts []PlacementPostOutput `json:"placement_posts"`
|
||||
}
|
||||
|
||||
func (c *Client) CreatePlacements(
|
||||
ctx context.Context,
|
||||
jwt string,
|
||||
@@ -664,39 +663,6 @@ func (c *Client) GetPlacement(
|
||||
return &placement, err
|
||||
}
|
||||
|
||||
func (c *Client) GetPlacementPosts(
|
||||
ctx context.Context,
|
||||
jwt string,
|
||||
workspaceID string,
|
||||
projectID *string,
|
||||
placementID *string,
|
||||
) (*GetPlacementPostsOutput, error) {
|
||||
q := url.Values{}
|
||||
if projectID != nil && *projectID != "" {
|
||||
q.Set("project_id", *projectID)
|
||||
}
|
||||
if placementID != nil && *placementID != "" {
|
||||
q.Set("placement_id", *placementID)
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("api/v1/workspaces/%s/placement_posts", workspaceID)
|
||||
if len(q) > 0 {
|
||||
path += "?" + q.Encode()
|
||||
}
|
||||
|
||||
var resp GetPlacementPostsOutput
|
||||
err := c.do(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
path,
|
||||
nil,
|
||||
&resp,
|
||||
withBearer(jwt),
|
||||
)
|
||||
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Workspace Members
|
||||
// ============================================================================
|
||||
|
||||
@@ -37,7 +37,7 @@ func (s *Login) Enter(b *bot.Bot, mode bot.RenderMode) {
|
||||
ParseMode: echotron.HTML,
|
||||
})
|
||||
if err != nil {
|
||||
log.Err(err)
|
||||
log.Err(err).Msg("SendMessage error")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -215,6 +215,7 @@ func (s *MyProjects) HandleCallback(b *bot.Bot, u *echotron.Update) {
|
||||
// Получаем проект напрямую по ID
|
||||
project, err := b.Backend.GetProject(
|
||||
context.Background(),
|
||||
b.Session.JWT,
|
||||
s.WorkspaceID,
|
||||
projectID,
|
||||
)
|
||||
|
||||
@@ -44,26 +44,9 @@ func (s *PlacementDetails) renderDetails(b *bot.Bot, mode bot.RenderMode, jwt st
|
||||
return
|
||||
}
|
||||
|
||||
placementPosts, err := b.Backend.GetPlacementPosts(
|
||||
context.Background(),
|
||||
jwt,
|
||||
s.WorkspaceID,
|
||||
&s.ProjectID,
|
||||
&s.PlacementID,
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get placement posts")
|
||||
}
|
||||
|
||||
var placementPost *backend.PlacementPostOutput
|
||||
if placementPosts != nil {
|
||||
for i := range placementPosts.PlacementPosts {
|
||||
post := &placementPosts.PlacementPosts[i]
|
||||
if post.PlacementID == s.PlacementID {
|
||||
placementPost = post
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(placement.PlacementPosts) > 0 {
|
||||
placementPost = &placement.PlacementPosts[0]
|
||||
}
|
||||
|
||||
text := "<b>Детали размещения</b>\n\n"
|
||||
|
||||
Reference in New Issue
Block a user