mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -06:00
Fix upsert + add empty routes and function
This commit is contained in:
parent
c1566a36c4
commit
c7de8cb4e4
|
|
@ -19,7 +19,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const accountDataSchema = `
|
const accountDataSchema = `
|
||||||
-- Stores data about accounts profiles.
|
-- Stores data about accounts data.
|
||||||
CREATE TABLE IF NOT EXISTS account_data (
|
CREATE TABLE IF NOT EXISTS account_data (
|
||||||
-- The Matrix user ID localpart for this account
|
-- The Matrix user ID localpart for this account
|
||||||
localpart TEXT NOT NULL,
|
localpart TEXT NOT NULL,
|
||||||
|
|
@ -28,18 +28,15 @@ CREATE TABLE IF NOT EXISTS account_data (
|
||||||
-- The account data type
|
-- The account data type
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
-- The account data content
|
-- The account data content
|
||||||
content TEXT NOT NULL
|
content TEXT NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY(localpart, room_id, type)
|
PRIMARY KEY(localpart, room_id, type)
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Create index we can reference in the upsert request
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS ac_user_room_type ON account_data(localpart, room_id, type);
|
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertAccountDataSQL = `
|
const insertAccountDataSQL = `
|
||||||
INSERT INTO account_data(localpart, room_id, type, content) VALUES($1, $2, $3, $4)
|
INSERT INTO account_data(localpart, room_id, type, content) VALUES($1, $2, $3, $4)
|
||||||
ON CONFLICT (ac_user_room_type) DO UPDATE SET content = EXCLUDED.content
|
ON CONFLICT (localpart, room_id, type) DO UPDATE SET content = EXCLUDED.content
|
||||||
`
|
`
|
||||||
|
|
||||||
const selectAccountDataByLocalPartSQL = "" +
|
const selectAccountDataByLocalPartSQL = "" +
|
||||||
|
|
@ -54,7 +51,7 @@ type accountDataStatements struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *accountDataStatements) prepare(db *sql.DB) (err error) {
|
func (s *accountDataStatements) prepare(db *sql.DB) (err error) {
|
||||||
_, err = db.Exec(accountsSchema)
|
_, err = db.Exec(accountDataSchema)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2017 Vector Creations Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package readers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
|
||||||
|
"github.com/matrix-org/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SaveAccountData(
|
||||||
|
req *http.Request, accountDB *accounts.Database, userID string, roomID string,
|
||||||
|
) util.JSONResponse {
|
||||||
|
|
||||||
|
localpart, server, err := gomatrixserverlib.SplitID('@', userID)
|
||||||
|
}
|
||||||
|
|
@ -275,7 +275,14 @@ func Setup(
|
||||||
|
|
||||||
r0mux.Handle("/user/{userID}/account_data/{type}",
|
r0mux.Handle("/user/{userID}/account_data/{type}",
|
||||||
common.MakeAPI("user_account_data", func(req *http.Request) util.JSONResponse {
|
common.MakeAPI("user_account_data", func(req *http.Request) util.JSONResponse {
|
||||||
// TODO: Set and get the account_data
|
// TODO: Set the account_data
|
||||||
|
return util.JSONResponse{Code: 200, JSON: struct{}{}}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
||||||
|
common.MakeAPI("user_account_data", func(req *http.Request) util.JSONResponse {
|
||||||
|
// TODO: Set the account_data
|
||||||
return util.JSONResponse{Code: 200, JSON: struct{}{}}
|
return util.JSONResponse{Code: 200, JSON: struct{}{}}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue