Add description_name
to clients
This commit is contained in:
@@ -119,10 +119,11 @@ func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
type body struct {
|
||||
FCMToken string `json:"fcm_token" binding:"required"`
|
||||
AgentModel string `json:"agent_model" binding:"required"`
|
||||
AgentVersion string `json:"agent_version" binding:"required"`
|
||||
ClientType models.ClientType `json:"client_type" binding:"required"`
|
||||
FCMToken string `json:"fcm_token" binding:"required"`
|
||||
AgentModel string `json:"agent_model" binding:"required"`
|
||||
AgentVersion string `json:"agent_version" binding:"required"`
|
||||
DescriptionName *string `json:"description_name"`
|
||||
ClientType models.ClientType `json:"client_type" binding:"required"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -147,7 +148,7 @@ func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to delete existing clients in db", err)
|
||||
}
|
||||
|
||||
client, err := h.database.CreateClient(ctx, u.UserID, clientType, b.FCMToken, b.AgentModel, b.AgentVersion)
|
||||
client, err := h.database.CreateClient(ctx, u.UserID, clientType, b.FCMToken, b.AgentModel, b.AgentVersion, b.DescriptionName)
|
||||
if err != nil {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create client in db", err)
|
||||
}
|
||||
@@ -230,9 +231,10 @@ func (h APIHandler) UpdateClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
ClientID models.ClientID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
type body struct {
|
||||
FCMToken *string `json:"fcm_token"`
|
||||
AgentModel *string `json:"agent_model"`
|
||||
AgentVersion *string `json:"agent_version"`
|
||||
FCMToken *string `json:"fcm_token"`
|
||||
AgentModel *string `json:"agent_model"`
|
||||
AgentVersion *string `json:"agent_version"`
|
||||
DescriptionName *string `json:"description_name"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -282,6 +284,20 @@ func (h APIHandler) UpdateClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
}
|
||||
}
|
||||
|
||||
if b.DescriptionName != nil {
|
||||
if *b.DescriptionName == "" {
|
||||
err = h.database.UpdateClientDescriptionName(ctx, u.ClientID, nil)
|
||||
if err != nil {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to update client", err)
|
||||
}
|
||||
} else {
|
||||
err = h.database.UpdateClientDescriptionName(ctx, u.ClientID, langext.Ptr(*b.DescriptionName))
|
||||
if err != nil {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to update client", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
client, err = h.database.GetClient(ctx, u.UserID, u.ClientID)
|
||||
if err != nil {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query (updated) client", err)
|
||||
|
@@ -28,13 +28,14 @@ import (
|
||||
// @Router /api/v2/users [POST]
|
||||
func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
type body struct {
|
||||
FCMToken string `json:"fcm_token"`
|
||||
ProToken *string `json:"pro_token"`
|
||||
Username *string `json:"username"`
|
||||
AgentModel string `json:"agent_model"`
|
||||
AgentVersion string `json:"agent_version"`
|
||||
ClientType models.ClientType `json:"client_type"`
|
||||
NoClient bool `json:"no_client"`
|
||||
FCMToken string `json:"fcm_token"`
|
||||
ProToken *string `json:"pro_token"`
|
||||
Username *string `json:"username"`
|
||||
AgentModel string `json:"agent_model"`
|
||||
AgentVersion string `json:"agent_version"`
|
||||
DescriptionName *string `json:"description_name"`
|
||||
ClientType models.ClientType `json:"client_type"`
|
||||
NoClient bool `json:"no_client"`
|
||||
}
|
||||
|
||||
var b body
|
||||
@@ -123,7 +124,7 @@ func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to delete existing clients in db", err)
|
||||
}
|
||||
|
||||
client, err := h.database.CreateClient(ctx, userobj.UserID, clientType, b.FCMToken, b.AgentModel, b.AgentVersion)
|
||||
client, err := h.database.CreateClient(ctx, userobj.UserID, clientType, b.FCMToken, b.AgentModel, b.AgentVersion, b.DescriptionName)
|
||||
if err != nil {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create client in db", err)
|
||||
}
|
||||
|
@@ -206,7 +206,7 @@ func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create admin-key in db", err)
|
||||
}
|
||||
|
||||
_, err = h.database.CreateClient(ctx, user.UserID, models.ClientTypeAndroid, *data.FCMToken, "compat", "compat")
|
||||
_, err = h.database.CreateClient(ctx, user.UserID, models.ClientTypeAndroid, *data.FCMToken, "compat", "compat", nil)
|
||||
if err != nil {
|
||||
return ginresp.CompatAPIError(0, "Failed to create client in db")
|
||||
}
|
||||
@@ -661,7 +661,7 @@ func (h CompatHandler) Update(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
}
|
||||
|
||||
_, err = h.database.CreateClient(ctx, user.UserID, models.ClientTypeAndroid, *data.FCMToken, "compat", "compat")
|
||||
_, err = h.database.CreateClient(ctx, user.UserID, models.ClientTypeAndroid, *data.FCMToken, "compat", "compat", nil)
|
||||
if err != nil {
|
||||
return ginresp.CompatAPIError(0, "Failed to create client")
|
||||
}
|
||||
|
Reference in New Issue
Block a user