Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/controllers/api/user_emojis_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Api::UserEmojisController < ApplicationController
before_action :authenticate_user!

def create
@user_emoji = current_user.user_emojis.new(user_emoji_params)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot You can only create an emoji if you have enough "emoji slots" left.

You get more after leveling up.

Level 3: 1 additional slots granted
Level 4: 2 additional slots granted
Level 5: 2 additional slots granted

(some kind of gentle curve like this, maxing out at level 30 perhaps)

You must also have the DJ role.

if @user_emoji.save
render json: @user_emoji, status: :created
else
render json: { errors: @user_emoji.errors }, status: :unprocessable_entity
end
end

private

def user_emoji_params
ActiveModelSerializers::Deserialization.jsonapi_parse(params, only: [
:name, :image
])
end
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class User < ActiveRecord::Base
has_many :posts
has_many :notifications
has_many :trophy_awards
has_many :user_emojis

# has_attached_file :image, styles: { :thumb => "150x150#", :medium => "250x250#" },
# path: ":attachment/:style/:basename.:extension"
Expand Down
4 changes: 4 additions & 0 deletions app/models/user_emoji.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class UserEmoji < ApplicationRecord
belongs_to :user
has_one_attached :image
end
9 changes: 9 additions & 0 deletions app/serializers/user_emoji_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class UserEmojiSerializer < ActiveModel::Serializer
attributes :id, :name, :image_url

def image_url
if object.image.attached?
Rails.application.routes.url_helpers.rails_blob_url(object.image, only_path: true)
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
resources :labels, only: [:create, :index, :show]

resources :treasure_chests, only: [:create]
resources :user_emojis, only: [:create]
end

resources :patreon_webhooks, only: [:create]
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20250712232636_create_user_emojis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateUserEmojis < ActiveRecord::Migration[7.0]
def change
create_table :user_emojis do |t|
t.references :user, null: false, index: true
t.string :name, null: false

t.timestamps
end
end
end
Loading