class Post < ApplicationRecord
belongs_to :author, class_name: 'User'
has_many :comments, dependent: :destroy
scope :published, -> { where.not(published_at: nil).where('published_at <= ?', Time.current) }
scope :draft, -> { where(published_at: nil) }
:concurrency: 10
:queues:
- [critical, 4]
- [default, 2]
- [low, 1]
Rails.application.configure do
config.after_initialize do
Bullet.enable = true
Bullet.alert = false
Bullet.bullet_logger = true
Bullet.console = true
module CursorPagination
extend ActiveSupport::Concern
private
def paginate_with_cursor(scope, per_page: 20)
module ApiErrorHandler
extend ActiveSupport::Concern
included do
rescue_from StandardError, with: :handle_standard_error
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
class Rack::Attack
Rack::Attack.cache.store = ActiveSupport::Cache::RedisCacheStore.new(url: ENV['REDIS_URL'])
safelist('allow-localhost') do |req|
req.ip == '127.0.0.1' || req.ip == '::1'
end
class JwtService
ACCESS_TOKEN_LIFETIME = 15.minutes
REFRESH_TOKEN_LIFETIME = 7.days
SECRET = Rails.application.credentials.jwt_secret
def self.encode_access_token(user_id)
Rails.application.routes.draw do
namespace :api do
namespace :v1 do
resources :users, only: [:index, :show, :create, :update]
resources :posts do
resources :comments, only: [:index, :create]
package middleware
import (
"log"
"net/http"
"runtime/debug"
package dbutil
import (
"context"
"github.com/jackc/pgconn"
package cleanup
import "errors"
func CloseAll(closers ...func() error) error {
var errs []error
package middleware
import "net/http"
type StatusRecorder struct {
http.ResponseWriter