-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: add get discord message logs api #755
Open
nnhuyhoang
wants to merge
8
commits into
develop
Choose a base branch
from
feat/add-get-discord-message-logs-api
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c4fc704
feat: add get discord message logs api
nnhuyhoang 1576bc1
feat: add get discord message logs api
nnhuyhoang b6fdccd
feat: add get discord message logs api
nnhuyhoang ee45f85
feat: add get discord message logs api
nnhuyhoang ec17de8
feat: add get discord message logs api
nnhuyhoang dc910f2
feat: add get discord message logs api
nnhuyhoang 0a066f5
feat: add get discord message logs api
nnhuyhoang 3c29625
feat: add get discord message logs api
nnhuyhoang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -776,3 +776,51 @@ func (h *handler) SweepOgifEvent(c *gin.Context) { | |
|
||
c.JSON(http.StatusOK, view.CreateResponse[any](nil, nil, nil, nil, "events swept successfully")) | ||
} | ||
|
||
// ListChannelMessageLogs godoc | ||
// @Summary Get list of messages in channel and its thread | ||
// @Description Get list of messages in channel and its thread | ||
// @id ListChannelMessageLogs | ||
// @Tags Discord | ||
// @Accept json | ||
// @Produce json | ||
// @Param discord_channel_id path string true "Channel Discord ID" | ||
// @Param startDate query string true "Start Date" | ||
// @Param endDate query string true "End Date" | ||
// @Success 200 {object} ListDiscordTextMessageLog | ||
// @Failure 400 {object} ErrorResponse | ||
// @Failure 404 {object} ErrorResponse | ||
// @Failure 500 {object} ErrorResponse | ||
// @Router /discords/channels/{discord_channel_id}/message-logs [get] | ||
func (h *handler) ListChannelMessageLogs(c *gin.Context) { | ||
var input = request.GetChannelMessagesInput{ | ||
DiscordChannelID: c.Param("discord_channel_id"), | ||
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. @nnhuyhoang will this allow client call any discord_channel_id, if yes, gonna reject this for now please follow up with me about this approach, need to validate/whitelist some channels only |
||
} | ||
|
||
if err := c.ShouldBindQuery(&input); err != nil { | ||
c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, input, "bind query failed")) | ||
return | ||
} | ||
|
||
if err := input.Validate(); err != nil { | ||
c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, input, "")) | ||
return | ||
} | ||
|
||
startDate := input.GetStartDate() | ||
endDate := input.GetEndDate() | ||
|
||
// maximum 1 month messages | ||
oneMonth := time.Hour * 24 * 365 | ||
if endDate.Sub(*startDate) > oneMonth { | ||
newEndDate := startDate.Add(oneMonth) | ||
endDate = &newEndDate | ||
} | ||
|
||
messages, err := h.controller.Discord.ListDiscordChannelMessageLogs(c, input.DiscordChannelID, startDate, endDate) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, view.CreateResponse[any](nil, nil, err, nil, "")) | ||
return | ||
} | ||
c.JSON(http.StatusOK, view.CreateResponse(view.ToListDiscordTextMessageLog(messages), nil, nil, nil, "")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package view | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/dwarvesf/fortress-api/pkg/model" | ||
) | ||
|
||
type DiscordTextMessageLog struct { | ||
ID string `json:"id"` | ||
Content string `json:"content"` | ||
AuthorName string `json:"author_name"` | ||
AuthorID string `json:"author_id"` | ||
ChannelID string `json:"channel_id"` | ||
GuildID string `json:"guild_id"` | ||
Timestamp time.Time `json:"timestamp"` | ||
} | ||
|
||
type ListDiscordTextMessageLog struct { | ||
Data []DiscordTextMessageLog `json:"data"` | ||
} // @name ListDiscordTextMessageLog | ||
|
||
func ToDiscordTextMessageLog(message model.DiscordTextMessageLog) DiscordTextMessageLog { | ||
return DiscordTextMessageLog{ | ||
ID: message.ID, | ||
Content: message.Content, | ||
AuthorName: message.AuthorName, | ||
AuthorID: message.AuthorID, | ||
ChannelID: message.ChannelID, | ||
GuildID: message.GuildID, | ||
Timestamp: message.Timestamp, | ||
} | ||
} | ||
|
||
func ToListDiscordTextMessageLog(messages []model.DiscordTextMessageLog) []DiscordTextMessageLog { | ||
var results = make([]DiscordTextMessageLog, 0, len(messages)) | ||
|
||
for _, message := range messages { | ||
results = append(results, ToDiscordTextMessageLog(message)) | ||
} | ||
|
||
return results | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@namnhce @nnhuyhoang
this seems like a potential OOM, since on prod we only have 100MB-ish memory, make sure we dont OOM here
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.
will test on dev with the same amount of messages, if cannot handle them , find another way