From 8ffa767dfed9ff4940b9b737f41b27e2acec34a8 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 27 Oct 2025 17:46:25 +0800 Subject: [PATCH] Add logo support to team creation and update functionality - Enhanced the team creation and update processes to include an optional logo field, allowing teams to have custom logos. - Updated the CreateTeamRequest and UpdateTeamRequest structures to accommodate the new logo field. - Modified the GinTeamCreate and GinTeamUpdate handlers to handle logo data appropriately. - Expanded test cases for team creation and updates to validate logo handling, ensuring comprehensive coverage for scenarios involving logos. --- openapi/tests/user/team_test.go | 32 ++++++++++++++++++++++++++++++++ openapi/user/team.go | 9 +++++++++ openapi/user/types.go | 3 +++ 3 files changed, 44 insertions(+) diff --git a/openapi/tests/user/team_test.go b/openapi/tests/user/team_test.go index 2dd06f99..4223e2d2 100644 --- a/openapi/tests/user/team_test.go +++ b/openapi/tests/user/team_test.go @@ -195,6 +195,19 @@ func TestTeamCreate(t *testing.T) { 201, "should create team with settings", }, + { + "create team with logo", + map[string]interface{}{ + "name": "Team with Logo", + "description": "Team with custom logo", + "logo": "__yao.attachment://test-logo-123", + }, + map[string]string{ + "Authorization": "Bearer " + tokenInfo.AccessToken, + }, + 201, + "should create team with logo", + }, { "create team without name", map[string]interface{}{ @@ -285,6 +298,9 @@ func TestTeamCreate(t *testing.T) { if description, ok := tc.body["description"]; ok { assert.Equal(t, description, team["description"], "Should have correct description") } + if logo, ok := tc.body["logo"]; ok { + assert.Equal(t, logo, team["logo"], "Should have correct logo") + } } } @@ -423,6 +439,7 @@ func TestTeamGet(t *testing.T) { assert.Contains(t, team, "team_id", "Should have team_id") assert.Contains(t, team, "name", "Should have team name") assert.Contains(t, team, "description", "Should have description") + // Logo field is optional, only present if set assert.Contains(t, team, "owner_id", "Should have owner_id") assert.Contains(t, team, "status", "Should have status") assert.Contains(t, team, "settings", "Should have settings") @@ -537,6 +554,18 @@ func TestTeamUpdate(t *testing.T) { 200, "should update team settings", }, + { + "update team logo", + getTeamID(createdTeam), + map[string]interface{}{ + "logo": "__yao.attachment://updated-logo-456", + }, + map[string]string{ + "Authorization": "Bearer " + tokenInfo.AccessToken, + }, + 200, + "should update team logo", + }, { "update non-existent team", "non-existent-team-id", @@ -609,6 +638,9 @@ func TestTeamUpdate(t *testing.T) { if description, ok := tc.body["description"]; ok { assert.Equal(t, description, team["description"], "Should have updated description") } + if logo, ok := tc.body["logo"]; ok { + assert.Equal(t, logo, team["logo"], "Should have updated logo") + } if settings, ok := tc.body["settings"]; ok { assert.Equal(t, settings, team["settings"], "Should have updated settings") } diff --git a/openapi/user/team.go b/openapi/user/team.go index c56e05c4..c15c9b67 100644 --- a/openapi/user/team.go +++ b/openapi/user/team.go @@ -179,6 +179,11 @@ func GinTeamCreate(c *gin.Context) { "description": req.Description, }) + // Add logo if provided + if req.Logo != "" { + teamData["logo"] = req.Logo + } + // Add settings if provided if req.Settings != nil { teamData["settings"] = req.Settings @@ -261,6 +266,9 @@ func GinTeamUpdate(c *gin.Context) { if req.Description != "" { updateData["description"] = req.Description } + if req.Logo != "" { + updateData["logo"] = req.Logo + } if req.Settings != nil { updateData["settings"] = req.Settings } @@ -953,6 +961,7 @@ func mapToTeamResponse(data maps.MapStr) TeamResponse { TeamID: toString(data["team_id"]), Name: toString(data["name"]), Description: toString(data["description"]), + Logo: toString(data["logo"]), OwnerID: toString(data["owner_id"]), Status: toString(data["status"]), IsVerified: toBool(data["is_verified"]), diff --git a/openapi/user/types.go b/openapi/user/types.go index 5882feb4..46760eec 100644 --- a/openapi/user/types.go +++ b/openapi/user/types.go @@ -355,6 +355,7 @@ type TeamResponse struct { TeamID string `json:"team_id"` Name string `json:"name"` Description string `json:"description,omitempty"` + Logo string `json:"logo,omitempty"` // Team logo URL or file ID OwnerID string `json:"owner_id"` Status string `json:"status"` IsVerified bool `json:"is_verified"` @@ -375,6 +376,7 @@ type TeamDetailResponse struct { type CreateTeamRequest struct { Name string `json:"name" binding:"required"` Description string `json:"description,omitempty"` + Logo string `json:"logo,omitempty"` // Team logo URL or file ID Settings *TeamSettings `json:"settings,omitempty"` } @@ -382,6 +384,7 @@ type CreateTeamRequest struct { type UpdateTeamRequest struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` + Logo string `json:"logo,omitempty"` // Team logo URL or file ID Settings *TeamSettings `json:"settings,omitempty"` }