-
Notifications
You must be signed in to change notification settings - Fork 31
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
Calculate expires_at For Order Adding One Month #1870
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,22 @@ func (r *Order) GetTimeBounds(ctx context.Context, dbi sqlx.QueryerContext, id u | |
return result, nil | ||
} | ||
|
||
// GetExpiresAtP1M returns expires_at that is last_paid_at (or now()) plus 1 month. | ||
func (r *Order) GetExpiresAtP1M(ctx context.Context, dbi sqlx.QueryerContext, id uuid.UUID) (time.Time, error) { | ||
const q = `SELECT (SELECT COALESCE(last_paid_at, now()) AS last_paid_at) + interval '1 month' AS expires_at FROM orders WHERE id = $1` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use the (max) value in the order item list for valid_for_iso instead of having a per interval function to make it more generic?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please have a look at #1874. A note on calculation – unless I am wrong, type casting has to happen before we |
||
|
||
var result time.Time | ||
if err := sqlx.GetContext(ctx, dbi, &result, q, id); err != nil { | ||
if errors.Is(err, sql.ErrNoRows) { | ||
return time.Time{}, model.ErrOrderNotFound | ||
} | ||
|
||
return time.Time{}, err | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
// SetExpiresAt sets expires_at. | ||
func (r *Order) SetExpiresAt(ctx context.Context, dbi sqlx.ExecerContext, id uuid.UUID, when time.Time) error { | ||
const q = `UPDATE orders SET updated_at = CURRENT_TIMESTAMP, expires_at = $2 WHERE id = $1` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep it generic
GetTimeBounds
see next comment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at #1874. A note on naming: since the method no longer returns bounds, strictly speaking, the old name no longer makes sense. It returns a ready-to-use value for
expires_at
, and the name in the new PR reflects that –GetExpiresAtAfterISOPeriod
.