[render skip] set last message id on api properly

This commit is contained in:
Andre Medeiros 2022-11-05 21:25:06 -04:00
parent 5eabaebf45
commit fc449fd7cf
2 changed files with 5 additions and 2 deletions

View File

@ -177,7 +177,7 @@ func (a *api) upsertAccountsHandler(w http.ResponseWriter, r *http.Request) {
// Set account ID from Reddit
acc.AccountID = me.ID
mi, err := rac.MessageInbox(ctx)
mi, err := rac.MessageInbox(ctx, reddit.WithQuery("limit", "1"))
if err != nil {
a.errorResponse(w, r, 500, err)
return
@ -185,6 +185,7 @@ func (a *api) upsertAccountsHandler(w http.ResponseWriter, r *http.Request) {
if mi.Count > 0 {
acc.LastMessageID = mi.Children[0].FullName()
acc.CheckCount = 1
}
if err := a.accountRepo.CreateOrUpdate(ctx, &acc); err != nil {
@ -252,7 +253,7 @@ func (a *api) upsertAccountHandler(w http.ResponseWriter, r *http.Request) {
// Set account ID from Reddit
acct.AccountID = me.ID
mi, err := rac.MessageInbox(ctx)
mi, err := rac.MessageInbox(ctx, reddit.WithQuery("limit", "1"))
if err != nil {
a.errorResponse(w, r, 500, err)
return
@ -260,6 +261,7 @@ func (a *api) upsertAccountHandler(w http.ResponseWriter, r *http.Request) {
if mi.Count > 0 {
acct.LastMessageID = mi.Children[0].FullName()
acct.CheckCount = 1
}
// Associate

View File

@ -103,6 +103,7 @@ func (p *postgresAccountRepository) CreateOrUpdate(ctx context.Context, acc *dom
UPDATE SET access_token = $3,
refresh_token = $4,
token_expires_at = $5,
last_message_id = $6,
is_deleted = FALSE
RETURNING id`