Move to string-ids for all entities (compat translation for existing data)
This commit is contained in:
@@ -151,7 +151,7 @@ func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid} [GET]
|
||||
func (h APIHandler) GetUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -200,7 +200,7 @@ func (h APIHandler) GetUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid} [PATCH]
|
||||
func (h APIHandler) UpdateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
type body struct {
|
||||
Username *string `json:"username"`
|
||||
@@ -306,7 +306,7 @@ func (h APIHandler) UpdateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/clients [GET]
|
||||
func (h APIHandler) ListClients(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
type response struct {
|
||||
Clients []models.ClientJSON `json:"clients"`
|
||||
@@ -351,8 +351,8 @@ func (h APIHandler) ListClients(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/clients/{cid} [GET]
|
||||
func (h APIHandler) GetClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
ClientID models.ClientID `uri:"cid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ClientID models.ClientID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -395,7 +395,7 @@ func (h APIHandler) GetClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/clients [POST]
|
||||
func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
type body struct {
|
||||
FCMToken string `json:"fcm_token" binding:"required"`
|
||||
@@ -456,8 +456,8 @@ func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/clients/{cid} [DELETE]
|
||||
func (h APIHandler) DeleteClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
ClientID models.ClientID `uri:"cid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ClientID models.ClientID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -511,7 +511,7 @@ func (h APIHandler) DeleteClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/channels [GET]
|
||||
func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
type query struct {
|
||||
Selector *string `json:"selector" form:"selector" enums:"owned,subscribed_any,all_any,subscribed,all"`
|
||||
@@ -603,8 +603,8 @@ func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/channels/{cid} [GET]
|
||||
func (h APIHandler) GetChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
ChannelID models.ChannelID `uri:"cid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -647,7 +647,7 @@ func (h APIHandler) GetChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/channels [POST]
|
||||
func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
type body struct {
|
||||
Name string `json:"name"`
|
||||
@@ -744,8 +744,8 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/channels/{cid} [PATCH]
|
||||
func (h APIHandler) UpdateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
ChannelID models.ChannelID `uri:"cid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
type body struct {
|
||||
RefreshSubscribeKey *bool `json:"subscribe_key"`
|
||||
@@ -869,8 +869,8 @@ func (h APIHandler) UpdateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/channels/{cid}/messages [GET]
|
||||
func (h APIHandler) ListChannelMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
ChannelUserID models.UserID `uri:"uid"`
|
||||
ChannelID models.ChannelID `uri:"cid"`
|
||||
ChannelUserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
type query struct {
|
||||
PageSize *int `json:"page_size" form:"page_size"`
|
||||
@@ -972,7 +972,7 @@ func (h APIHandler) ListChannelMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/subscriptions [GET]
|
||||
func (h APIHandler) ListUserSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
type query struct {
|
||||
Selector *string `json:"selector" form:"selector" enums:"owner_all,owner_confirmed,owner_unconfirmed,incoming_all,incoming_confirmed,incoming_unconfirmed"`
|
||||
@@ -1069,8 +1069,8 @@ func (h APIHandler) ListUserSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/channels/{cid}/subscriptions [GET]
|
||||
func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
ChannelID models.ChannelID `uri:"cid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
type response struct {
|
||||
Subscriptions []models.SubscriptionJSON `json:"subscriptions"`
|
||||
@@ -1123,8 +1123,8 @@ func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPRespons
|
||||
// @Router /api/users/{uid}/subscriptions/{sid} [GET]
|
||||
func (h APIHandler) GetSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
SubscriptionID models.SubscriptionID `uri:"sid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
SubscriptionID models.SubscriptionID `uri:"sid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -1170,8 +1170,8 @@ func (h APIHandler) GetSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/subscriptions/{sid} [DELETE]
|
||||
func (h APIHandler) CancelSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
SubscriptionID models.SubscriptionID `uri:"sid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
SubscriptionID models.SubscriptionID `uri:"sid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -1223,12 +1223,12 @@ func (h APIHandler) CancelSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/subscriptions [POST]
|
||||
func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
type body struct {
|
||||
ChannelOwnerUserID *models.UserID `json:"channel_owner_user_id"`
|
||||
ChannelOwnerUserID *models.UserID `json:"channel_owner_user_id" binding:"entityid"`
|
||||
ChannelInternalName *string `json:"channel_internal_name"`
|
||||
ChannelID *models.ChannelID `json:"channel_id"`
|
||||
ChannelID *models.ChannelID `json:"channel_id" binding:"entityid"`
|
||||
}
|
||||
type query struct {
|
||||
ChanSubscribeKey *string `json:"chan_subscribe_key" form:"chan_subscribe_key"`
|
||||
@@ -1312,8 +1312,8 @@ func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/users/{uid}/subscriptions/{sid} [PATCH]
|
||||
func (h APIHandler) UpdateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
SubscriptionID models.SubscriptionID `uri:"sid"`
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
SubscriptionID models.SubscriptionID `uri:"sid" binding:"entityid"`
|
||||
}
|
||||
type body struct {
|
||||
Confirmed *bool `form:"confirmed"`
|
||||
@@ -1454,7 +1454,7 @@ func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @ID api-messages-get
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param mid path int true "SCNMessageID"
|
||||
// @Param mid path int true "MessageID"
|
||||
//
|
||||
// @Success 200 {object} models.MessageJSON
|
||||
// @Failure 400 {object} ginresp.apiError "supplied values/parameters cannot be parsed / are invalid"
|
||||
@@ -1465,7 +1465,7 @@ func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/messages/{mid} [PATCH]
|
||||
func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
MessageID models.SCNMessageID `uri:"mid"`
|
||||
MessageID models.MessageID `uri:"mid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -1524,7 +1524,7 @@ func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @ID api-messages-delete
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param mid path int true "SCNMessageID"
|
||||
// @Param mid path int true "MessageID"
|
||||
//
|
||||
// @Success 200 {object} models.MessageJSON
|
||||
// @Failure 400 {object} ginresp.apiError "supplied values/parameters cannot be parsed / are invalid"
|
||||
@@ -1535,7 +1535,7 @@ func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Router /api/messages/{mid} [DELETE]
|
||||
func (h APIHandler) DeleteMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
MessageID models.SCNMessageID `uri:"mid"`
|
||||
MessageID models.MessageID `uri:"mid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
@@ -1561,12 +1561,12 @@ func (h APIHandler) DeleteMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 401, apierr.USER_AUTH_FAILED, "You are not authorized for this action", nil)
|
||||
}
|
||||
|
||||
err = h.database.DeleteMessage(ctx, msg.SCNMessageID)
|
||||
err = h.database.DeleteMessage(ctx, msg.MessageID)
|
||||
if err != nil {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to delete message", err)
|
||||
}
|
||||
|
||||
err = h.database.CancelPendingDeliveries(ctx, msg.SCNMessageID)
|
||||
err = h.database.CancelPendingDeliveries(ctx, msg.MessageID)
|
||||
if err != nil {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to cancel deliveries", err)
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"blackforestbytes.com/simplecloudnotifier/api/apierr"
|
||||
hl "blackforestbytes.com/simplecloudnotifier/api/apihighlight"
|
||||
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
|
||||
primarydb "blackforestbytes.com/simplecloudnotifier/db/impl/primary"
|
||||
"blackforestbytes.com/simplecloudnotifier/logic"
|
||||
@@ -24,6 +26,56 @@ func NewCompatHandler(app *logic.Application) CompatHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// SendMessageCompat swaggerdoc
|
||||
//
|
||||
// @Deprecated
|
||||
//
|
||||
// @Summary Send a new message (compatibility)
|
||||
// @Description All parameter can be set via query-parameter or form-data body. Only UserID, UserKey and Title are required
|
||||
// @Tags External
|
||||
//
|
||||
// @Param query_data query handler.SendMessageCompat.combined false " "
|
||||
// @Param form_data formData handler.SendMessageCompat.combined false " "
|
||||
//
|
||||
// @Success 200 {object} handler.sendMessageInternal.response
|
||||
// @Failure 400 {object} ginresp.apiError
|
||||
// @Failure 401 {object} ginresp.apiError
|
||||
// @Failure 403 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /send.php [POST]
|
||||
func (h MessageHandler) SendMessageCompat(g *gin.Context) ginresp.HTTPResponse {
|
||||
type combined struct {
|
||||
UserID *int64 `json:"user_id" form:"user_id"`
|
||||
UserKey *string `json:"user_key" form:"user_key"`
|
||||
Title *string `json:"title" form:"title"`
|
||||
Content *string `json:"content" form:"content"`
|
||||
Priority *int `json:"priority" form:"priority"`
|
||||
UserMessageID *string `json:"msg_id" form:"msg_id"`
|
||||
SendTimestamp *float64 `json:"timestamp" form:"timestamp"`
|
||||
}
|
||||
|
||||
var f combined
|
||||
var q combined
|
||||
ctx, errResp := h.app.StartRequest(g, nil, &q, nil, &f)
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
data := dataext.ObjectMerge(f, q)
|
||||
|
||||
newid, err := h.database.ConvertCompatID(ctx, langext.Coalesce(data.UserID, -1), "userid")
|
||||
if err != nil {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to query userid<old>", err)
|
||||
}
|
||||
if newid == nil {
|
||||
return ginresp.SendAPIError(g, 400, apierr.USER_NOT_FOUND, hl.USER_ID, "User not found (compat)", nil)
|
||||
}
|
||||
|
||||
return h.sendMessageInternal(g, ctx, langext.Ptr(models.UserID(*newid)), data.UserKey, nil, nil, data.Title, data.Content, data.Priority, data.UserMessageID, data.SendTimestamp, nil)
|
||||
}
|
||||
|
||||
// Register swaggerdoc
|
||||
//
|
||||
// @Summary Register a new account
|
||||
@@ -121,10 +173,15 @@ func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(0, "Failed to create client in db")
|
||||
}
|
||||
|
||||
oldid, err := h.database.CreateCompatID(ctx, "userid", user.UserID.String())
|
||||
if err != nil {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to create userid<old>", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "New user registered",
|
||||
UserID: user.UserID.IntID(),
|
||||
UserID: oldid,
|
||||
UserKey: user.AdminKey,
|
||||
QuotaUsed: user.QuotaUsedToday(),
|
||||
QuotaMax: user.QuotaPerDay(),
|
||||
@@ -184,7 +241,15 @@ func (h CompatHandler) Info(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(102, "Missing parameter [[user_key]]")
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*data.UserID))
|
||||
useridCompNew, err := h.database.ConvertCompatID(ctx, *data.UserID, "userid")
|
||||
if err != nil {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to query userid<old>", err)
|
||||
}
|
||||
if useridCompNew == nil {
|
||||
return ginresp.SendAPIError(g, 400, apierr.USER_NOT_FOUND, hl.USER_ID, "User not found (compat)", nil)
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*useridCompNew))
|
||||
if err == sql.ErrNoRows {
|
||||
return ginresp.CompatAPIError(201, "User not found")
|
||||
}
|
||||
@@ -206,7 +271,7 @@ func (h CompatHandler) Info(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "ok",
|
||||
UserID: user.UserID.IntID(),
|
||||
UserID: *data.UserID,
|
||||
UserKey: user.AdminKey,
|
||||
QuotaUsed: user.QuotaUsedToday(),
|
||||
QuotaMax: user.QuotaPerDay(),
|
||||
@@ -269,7 +334,15 @@ func (h CompatHandler) Ack(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(103, "Missing parameter [[scn_msg_id]]")
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*data.UserID))
|
||||
useridCompNew, err := h.database.ConvertCompatID(ctx, *data.UserID, "userid")
|
||||
if err != nil {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to query userid<old>", err)
|
||||
}
|
||||
if useridCompNew == nil {
|
||||
return ginresp.SendAPIError(g, 400, apierr.USER_NOT_FOUND, hl.USER_ID, "User not found (compat)", nil)
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*useridCompNew))
|
||||
if err == sql.ErrNoRows {
|
||||
return ginresp.CompatAPIError(201, "User not found")
|
||||
}
|
||||
@@ -336,7 +409,15 @@ func (h CompatHandler) Requery(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(102, "Missing parameter [[user_key]]")
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*data.UserID))
|
||||
useridCompNew, err := h.database.ConvertCompatID(ctx, *data.UserID, "userid")
|
||||
if err != nil {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to query userid<old>", err)
|
||||
}
|
||||
if useridCompNew == nil {
|
||||
return ginresp.SendAPIError(g, 400, apierr.USER_NOT_FOUND, hl.USER_ID, "User not found (compat)", nil)
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*useridCompNew))
|
||||
if err == sql.ErrNoRows {
|
||||
return ginresp.CompatAPIError(201, "User not found")
|
||||
}
|
||||
@@ -409,7 +490,15 @@ func (h CompatHandler) Update(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(102, "Missing parameter [[user_key]]")
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*data.UserID))
|
||||
useridCompNew, err := h.database.ConvertCompatID(ctx, *data.UserID, "userid")
|
||||
if err != nil {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to query userid<old>", err)
|
||||
}
|
||||
if useridCompNew == nil {
|
||||
return ginresp.SendAPIError(g, 400, apierr.USER_NOT_FOUND, hl.USER_ID, "User not found (compat)", nil)
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*useridCompNew))
|
||||
if err == sql.ErrNoRows {
|
||||
return ginresp.CompatAPIError(201, "User not found")
|
||||
}
|
||||
@@ -461,7 +550,7 @@ func (h CompatHandler) Update(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "user updated",
|
||||
UserID: user.UserID.IntID(),
|
||||
UserID: *data.UserID,
|
||||
UserKey: user.AdminKey,
|
||||
QuotaUsed: user.QuotaUsedToday(),
|
||||
QuotaMax: user.QuotaPerDay(),
|
||||
@@ -521,7 +610,15 @@ func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(103, "Missing parameter [[scn_msg_id]]")
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*data.UserID))
|
||||
useridCompNew, err := h.database.ConvertCompatID(ctx, *data.UserID, "userid")
|
||||
if err != nil {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to query userid<old>", err)
|
||||
}
|
||||
if useridCompNew == nil {
|
||||
return ginresp.SendAPIError(g, 400, apierr.USER_NOT_FOUND, hl.USER_ID, "User not found (compat)", nil)
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*useridCompNew))
|
||||
if err == sql.ErrNoRows {
|
||||
return ginresp.CompatAPIError(201, "User not found")
|
||||
}
|
||||
@@ -533,7 +630,15 @@ func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(204, "Authentification failed")
|
||||
}
|
||||
|
||||
msg, err := h.database.GetMessage(ctx, models.SCNMessageID(*data.MessageID), false)
|
||||
messageCompNew, err := h.database.ConvertCompatID(ctx, *data.MessageID, "messageid")
|
||||
if err != nil {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to query messagid<old>", err)
|
||||
}
|
||||
if messageCompNew == nil {
|
||||
return ginresp.CompatAPIError(301, "Message not found")
|
||||
}
|
||||
|
||||
msg, err := h.database.GetMessage(ctx, models.MessageID(*messageCompNew), false)
|
||||
if err == sql.ErrNoRows {
|
||||
return ginresp.CompatAPIError(301, "Message not found")
|
||||
}
|
||||
@@ -551,7 +656,7 @@ func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse {
|
||||
Priority: msg.Priority,
|
||||
Timestamp: msg.Timestamp().Unix(),
|
||||
UserMessageID: msg.UserMessageID,
|
||||
SCNMessageID: msg.SCNMessageID.IntID(),
|
||||
SCNMessageID: *data.MessageID,
|
||||
},
|
||||
}))
|
||||
}
|
||||
@@ -617,7 +722,15 @@ func (h CompatHandler) Upgrade(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(104, "Missing parameter [[pro_token]]")
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*data.UserID))
|
||||
useridCompNew, err := h.database.ConvertCompatID(ctx, *data.UserID, "userid")
|
||||
if err != nil {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to query userid<old>", err)
|
||||
}
|
||||
if useridCompNew == nil {
|
||||
return ginresp.SendAPIError(g, 400, apierr.USER_NOT_FOUND, hl.USER_ID, "User not found (compat)", nil)
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, models.UserID(*useridCompNew))
|
||||
if err == sql.ErrNoRows {
|
||||
return ginresp.CompatAPIError(201, "User not found")
|
||||
}
|
||||
@@ -662,7 +775,7 @@ func (h CompatHandler) Upgrade(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "user updated",
|
||||
UserID: user.UserID.IntID(),
|
||||
UserID: *data.UserID,
|
||||
QuotaUsed: user.QuotaUsedToday(),
|
||||
QuotaMax: user.QuotaPerDay(),
|
||||
IsPro: user.IsPro,
|
||||
|
@@ -31,48 +31,6 @@ func NewMessageHandler(app *logic.Application) MessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// SendMessageCompat swaggerdoc
|
||||
//
|
||||
// @Deprecated
|
||||
//
|
||||
// @Summary Send a new message (compatibility)
|
||||
// @Description All parameter can be set via query-parameter or form-data body. Only UserID, UserKey and Title are required
|
||||
// @Tags External
|
||||
//
|
||||
// @Param query_data query handler.SendMessageCompat.combined false " "
|
||||
// @Param form_data formData handler.SendMessageCompat.combined false " "
|
||||
//
|
||||
// @Success 200 {object} handler.sendMessageInternal.response
|
||||
// @Failure 400 {object} ginresp.apiError
|
||||
// @Failure 401 {object} ginresp.apiError
|
||||
// @Failure 403 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /send.php [POST]
|
||||
func (h MessageHandler) SendMessageCompat(g *gin.Context) ginresp.HTTPResponse {
|
||||
type combined struct {
|
||||
UserID *models.UserID `json:"user_id" form:"user_id"`
|
||||
UserKey *string `json:"user_key" form:"user_key"`
|
||||
Title *string `json:"title" form:"title"`
|
||||
Content *string `json:"content" form:"content"`
|
||||
Priority *int `json:"priority" form:"priority"`
|
||||
UserMessageID *string `json:"msg_id" form:"msg_id"`
|
||||
SendTimestamp *float64 `json:"timestamp" form:"timestamp"`
|
||||
}
|
||||
|
||||
var f combined
|
||||
var q combined
|
||||
ctx, errResp := h.app.StartRequest(g, nil, &q, nil, &f)
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
data := dataext.ObjectMerge(f, q)
|
||||
|
||||
return h.sendMessageInternal(g, ctx, data.UserID, data.UserKey, nil, nil, data.Title, data.Content, data.Priority, data.UserMessageID, data.SendTimestamp, nil)
|
||||
}
|
||||
|
||||
// SendMessage swaggerdoc
|
||||
//
|
||||
// @Summary Send a new message
|
||||
@@ -123,16 +81,16 @@ func (h MessageHandler) SendMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
func (h MessageHandler) sendMessageInternal(g *gin.Context, ctx *logic.AppContext, UserID *models.UserID, UserKey *string, Channel *string, ChanKey *string, Title *string, Content *string, Priority *int, UserMessageID *string, SendTimestamp *float64, SenderName *string) ginresp.HTTPResponse {
|
||||
type response struct {
|
||||
Success bool `json:"success"`
|
||||
ErrorID apierr.APIError `json:"error"`
|
||||
ErrorHighlight int `json:"errhighlight"`
|
||||
Message string `json:"message"`
|
||||
SuppressSend bool `json:"suppress_send"`
|
||||
MessageCount int `json:"messagecount"`
|
||||
Quota int `json:"quota"`
|
||||
IsPro bool `json:"is_pro"`
|
||||
QuotaMax int `json:"quota_max"`
|
||||
SCNMessageID models.SCNMessageID `json:"scn_msg_id"`
|
||||
Success bool `json:"success"`
|
||||
ErrorID apierr.APIError `json:"error"`
|
||||
ErrorHighlight int `json:"errhighlight"`
|
||||
Message string `json:"message"`
|
||||
SuppressSend bool `json:"suppress_send"`
|
||||
MessageCount int `json:"messagecount"`
|
||||
Quota int `json:"quota"`
|
||||
IsPro bool `json:"is_pro"`
|
||||
QuotaMax int `json:"quota_max"`
|
||||
SCNMessageID models.MessageID `json:"scn_msg_id"`
|
||||
}
|
||||
|
||||
if Title != nil {
|
||||
@@ -212,7 +170,7 @@ func (h MessageHandler) sendMessageInternal(g *gin.Context, ctx *logic.AppContex
|
||||
Quota: user.QuotaUsedToday(),
|
||||
IsPro: user.IsPro,
|
||||
QuotaMax: user.QuotaPerDay(),
|
||||
SCNMessageID: msg.SCNMessageID,
|
||||
SCNMessageID: msg.MessageID,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -317,6 +275,6 @@ func (h MessageHandler) sendMessageInternal(g *gin.Context, ctx *logic.AppContex
|
||||
Quota: user.QuotaUsedToday() + 1,
|
||||
IsPro: user.IsPro,
|
||||
QuotaMax: user.QuotaPerDay(),
|
||||
SCNMessageID: msg.SCNMessageID,
|
||||
SCNMessageID: msg.MessageID,
|
||||
}))
|
||||
}
|
||||
|
Reference in New Issue
Block a user