diff --git a/README.md b/README.md
index c07b325..9c73b23 100644
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@ well as store the Discord user.
---
- POST
/:id/daily
Claim a daily reward for a Discord user by id
+ POST
/daily/:id
Claim a daily reward for a Discord user by id
##### Request Parameters
@@ -102,6 +102,31 @@ Discord API. No token is required for this endpoint.
Discord users. NOTE: The pagination uses zero-based indexing.
---
+
+ GET
/member/:id
Get the stats of a Discord member
+
+##### Request Parameters
+
+- `id` the Discord id of the user whose stats should be retrieved
+
+##### Response Body (JSON)
+
+ ``` go
+ type DiscordMemberResponse struct {
+ DiscordID string `json:"discord_id"`
+ Name string `json:"name"`
+ Nick string `json:"nick"`
+ XP float64 `json:"xp"`
+ LastDailyAt string `json:"last_daily_at"`
+ Level int `json:"level"`
+ Streak int `json:"streak"`
+ }
+ ```
+
+##### Method (on Client)
+`Member(id string) (*DiscordMemberResponse, error)` Member is used to get the stats for a specific Discord user.
+---
+
## Environment Variables
- `port` - The port to listen on
diff --git a/cmd/app/main.go b/cmd/app/main.go
index 9c941da..77c9f19 100644
--- a/cmd/app/main.go
+++ b/cmd/app/main.go
@@ -39,6 +39,7 @@ ________________________________________________
discord.Use(authService.DiscordAuthMiddleware())
discord.POST("/verify", discordController.Verify)
discord.PATCH("/daily/:id", discordController.Daily)
+ discord.GET("/member/:id", discordController.Member)
discord.GET("/leaderboard/:page", discordController.Leaderboard)
discord.POST("/bot-login", discordController.BotLogin)
diff --git a/internal/app/controller/discord_controller.go b/internal/app/controller/discord_controller.go
index 2c40096..efe851e 100644
--- a/internal/app/controller/discord_controller.go
+++ b/internal/app/controller/discord_controller.go
@@ -12,6 +12,7 @@ import (
type DiscordController interface {
Verify(c echo.Context) error
Daily(c echo.Context) error
+ Member(c echo.Context) error
BotLogin(c echo.Context) error
Leaderboard(c echo.Context) error
}
@@ -26,6 +27,21 @@ func NewDiscordController(db *surreal_wrap.DB, config *conf.Config) DiscordContr
}
}
+func (c discordController) Member(ctx echo.Context) error {
+ errCh := c.service.InjectErrorChan()
+
+ id := ctx.Param("id")
+
+ memberCh := c.service.GetMember(id)
+
+ select {
+ case err := <-errCh:
+ return err
+ case member := <-memberCh:
+ return ctx.JSON(http.StatusOK, member)
+ }
+}
+
func (c discordController) Verify(ctx echo.Context) error {
cancel := c.service.InjectContext(ctx.Request().Context())
errCh := c.service.InjectErrorChan()
diff --git a/pkg/api/actions.go b/pkg/api/actions.go
index 7b30430..d0ec08a 100644
--- a/pkg/api/actions.go
+++ b/pkg/api/actions.go
@@ -47,3 +47,13 @@ func (c *Client) Leaderboard(page string) (*DiscordLeaderboardResponse, error) {
return do[DiscordLeaderboardResponse](req)
}
+
+// Member is used to get the stats for a specific Discord user.
+func (c *Client) Member(id string) (*DiscordMemberResponse, error) {
+ req, err := c.newJsonRequest(http.MethodGet, "/discord/member/"+id, nil)
+ if err != nil {
+ return nil, err
+ }
+
+ return do[DiscordMemberResponse](req)
+}
diff --git a/test/discord_signup.http b/test/discord_signup.http
index b01aebf..cedc4ca 100644
--- a/test/discord_signup.http
+++ b/test/discord_signup.http
@@ -25,3 +25,9 @@ Content-Type: application/json
GET http://localhost:8080/discord/leaderboard/0
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjb3JlIiwic3ViIjoiYm90IiwiYXVkIjpbImJvdCJdLCJpYXQiOjE3MDQxNTgyOTd9.1p1Y1tAky8QOQhKe4GmLtwj0imWyS5qNM5D-fX-dGAk
+
+### Test getting user info
+GET http://localhost:8080/discord/member/672835870080106509
+Content-Type: application/json
+Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjb3JlIiwic3ViIjoiYm90IiwiYXVkIjpbImJvdCJdLCJpYXQiOjE3MDQxNTgyOTd9.1p1Y1tAky8QOQhKe4GmLtwj0imWyS5qNM5D-fX-dGAk
+