Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(client): Reduce SQL boilerplate code #1758

Merged
merged 21 commits into from
Mar 14, 2020
Prev Previous commit
Next Next commit
u
  • Loading branch information
aeneasr committed Mar 14, 2020
commit 98ca497a3883dbed66c75f950bd0bb89d76ecb87
4 changes: 2 additions & 2 deletions consent/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func (h *Handler) AcceptConsentRequest(w http.ResponseWriter, r *http.Request, p

p.Challenge = challenge
p.RequestedAt = cr.RequestedAt
p.HandledAt = time.Now().UTC()
p.HandledAt = sqlxx.NullTime(time.Now().UTC())

hr, err := h.r.ConsentManager().HandleConsentRequest(r.Context(), challenge, &p)
if err != nil {
Expand Down Expand Up @@ -639,7 +639,7 @@ func (h *Handler) RejectConsentRequest(w http.ResponseWriter, r *http.Request, p
Error: &p,
Challenge: challenge,
RequestedAt: hr.RequestedAt,
HandledAt: time.Now().UTC(),
HandledAt: sqlxx.NullTime(time.Now().UTC()),
})
if err != nil {
h.r.Writer().WriteError(w, r, errors.WithStack(err))
Expand Down
2 changes: 1 addition & 1 deletion consent/manager_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (m *SQLManager) resolveHandledConsentRequests(ctx context.Context, requests
result = append(result, *v.postSQL(r))
}

if len(requests) == 0 {
if len(result) == 0 {
return nil, errors.WithStack(ErrNoPreviousConsentFound)
}

Expand Down
6 changes: 3 additions & 3 deletions consent/manager_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func MockConsentRequest(key string, remember bool, rememberFor int, hasError boo
GrantedScope: []string{"scopea" + key, "scopeb" + key},
GrantedAudience: []string{"auda" + key, "audb" + key},
Error: err,
HandledAt: time.Now().UTC(),
HandledAt: sqlxx.NullTime(time.Now().UTC()),
// WasUsed: true,
}

Expand Down Expand Up @@ -193,7 +193,7 @@ func SaneMockHandleConsentRequest(t *testing.T, m Manager, c *ConsentRequest, au
GrantedAudience: []string{"auda", "audb"},
Error: rde,
WasUsed: false,
HandledAt: time.Now().UTC().Add(-time.Minute),
HandledAt: sqlxx.NullTime(time.Now().UTC().Add(-time.Minute)),
}

_, err := m.HandleConsentRequest(context.Background(), c.Challenge, h)
Expand Down Expand Up @@ -425,7 +425,7 @@ func ManagerTests(m Manager, clientManager client.Manager, fositeManager x.Fosit

got1, err = m.HandleConsentRequest(context.TODO(), "challenge"+tc.key, h)
require.NoError(t, err)
require.Equal(t, time.Now().UTC().Round(time.Minute), h.HandledAt.Round(time.Minute))
require.Equal(t, time.Now().UTC().Round(time.Minute), time.Time(h.HandledAt).Round(time.Minute))
compareConsentRequest(t, c, got1)

_, err = m.HandleConsentRequest(context.TODO(), "challenge"+tc.key, h)
Expand Down
4 changes: 2 additions & 2 deletions consent/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ type HandledConsentRequest struct {
RememberFor int `json:"remember_for" db:"remember_for"`

// HandledAt contains the timestamp the consent request was handled.
HandledAt time.Time `json:"handled_at" db:"handled_at"`
HandledAt sqlxx.NullTime `json:"handled_at" db:"handled_at"`

ConsentRequest *ConsentRequest `json:"-" db:"-"`
Error *RequestDeniedError `json:"-" db:"error"`
Expand Down Expand Up @@ -199,7 +199,7 @@ type PreviousConsentSession struct {
RememberFor int `json:"remember_for" db:"remember_for"`

// HandledAt contains the timestamp the consent request was handled.
HandledAt time.Time `json:"handled_at" db:"handled_at"`
HandledAt sqlxx.NullTime `json:"handled_at" db:"handled_at"`

ConsentRequest *ConsentRequest `json:"consent_request" db:"-"`
Error *RequestDeniedError `json:"-" db:"error"`
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/ory/hydra

go 1.14

replace github.com/ory/x => ../x

require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fsnotify/fsnotify v1.4.9 // indirect
Expand Down Expand Up @@ -59,6 +61,7 @@ require (
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
golang.org/x/tools v0.0.0-20200313205530-4303120df7d8
gopkg.in/gorp.v1 v1.7.2 // indirect
gopkg.in/ini.v1 v1.54.0 // indirect
gopkg.in/square/go-jose.v2 v2.4.1
)
2 changes: 1 addition & 1 deletion oauth2/fosite_store_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func mockRequestForeignKey(t *testing.T, id string, x InternalRegistry, createCl
ConsentRequest: cr, Session: new(consent.ConsentRequestSessionData), AuthenticatedAt: sqlxx.NullTime(time.Now()),
Challenge: id,
RequestedAt: time.Now(),
HandledAt: time.Now(),
HandledAt: sqlxx.NullTime(time.Now()),
})
require.NoError(t, err)
}
Expand Down