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

fix: 絵文字申請時にエラーが発生する場合状態をリセットする #110

Merged
merged 1 commit into from
Sep 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion pkg/component/emoji_request_retry_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *emojiRequestRetryComponen) Execute(s *discordgo.Session, i *discordgo.I
})

// reset
emoji.Reset()
c.emojiRepository.ResetState(emoji)
c.emojiRequestHandler.ResetState(emoji, s)
c.emojiRequestHandler.ProcessRequest(emoji, s, i.ChannelID)
}
15 changes: 0 additions & 15 deletions pkg/entity/emoji.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package entity

import (
"os"
"path/filepath"
"time"
)
Expand Down Expand Up @@ -42,20 +41,6 @@ type Emoji struct {
StartAt time.Time `json:"startAt"`
}

func (emoji *Emoji) Reset() {
emoji.IsSensitive = false
emoji.IsAccepted = false
emoji.IsRequested = false
}

func (emoji *Emoji) deleteEmoji(filePath string) error {
err := os.Remove(filePath)
if err != nil {
return err
}
return nil
}

func IsValidEmojiFile(fileName string) bool {
fileExtension := filepath.Ext(fileName)
_, exists := validExtensions[fileExtension]
Expand Down
5 changes: 5 additions & 0 deletions pkg/handler/emoji/emoji_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type EmojiHandler interface {
GetEmoji(id string) (*entity.Emoji, error)
Approve(emoji *entity.Emoji) error
Disapprove(emoji *entity.Emoji) error
ResetState(emoji *entity.Emoji) error
EmojiReconstruction() []entity.Emoji
}

Expand Down Expand Up @@ -67,3 +68,7 @@ func (h *emojiHandler) Abort(emoji entity.Emoji) {
func (h *emojiHandler) Remove(emoji entity.Emoji) {
h.emojiRepository.Remove(emoji)
}

func (h *emojiHandler) ResetState(emoji *entity.Emoji) error {
return h.emojiRepository.ResetState(emoji)
}
4 changes: 4 additions & 0 deletions pkg/handler/emoji/emoji_moderation_reaction_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func (h *emojiModerationReactionHandler) HandleEmojiModerationReaction(s *discor
if err != nil {
fmt.Printf("Error: %v\n", err)
s.ChannelMessageSend(m.ChannelID, "絵文字アップロードに失敗しました。"+err.Error())
isSensitive := emoji.IsSensitive
h.emojiRepository.ResetState(emoji)
emoji.IsRequested = true
emoji.IsSensitive = isSensitive
return
}
s.ChannelMessageSend(m.ChannelID, "## 絵文字はアップロードされました")
Expand Down
10 changes: 9 additions & 1 deletion pkg/repository/emoji_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type EmojiRepository interface {
Abort(emoji *entity.Emoji)
Remove(emoji entity.Emoji)
Save(emoji *entity.Emoji) error
ResetState(emoji *entity.Emoji) error
}

type emojiRepository struct {
Expand Down Expand Up @@ -94,7 +95,7 @@ func (h *emojiRepository) Disapprove(emoji *entity.Emoji) error {

func (h *emojiRepository) Abort(emoji *entity.Emoji) {
h.Remove(*emoji)
emoji.Reset()
h.ResetState(emoji)
emoji.IsFinish = true
}

Expand All @@ -116,3 +117,10 @@ func (h *emojiRepository) Save(emoji *entity.Emoji) error {
jsonData, _ := json.MarshalIndent(emoji, "", " ")
return os.WriteFile(h.config.SavePath+emoji.ID+".json", jsonData, 0644)
}

func (h *emojiRepository) ResetState(emoji *entity.Emoji) error {
emoji.IsSensitive = false
emoji.IsAccepted = false
emoji.IsRequested = false
return nil
}