Skip to content

Commit 3cbd886

Browse files
author
Your Name
committed
fix
1 parent a118046 commit 3cbd886

14 files changed

Lines changed: 337 additions & 68 deletions

File tree

data/seed-ci.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/seed.iblseed

2 KB
Binary file not shown.

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"popplio/routes/reminders"
3131
"popplio/routes/reviews"
3232
"popplio/routes/servers"
33+
"popplio/routes/shop"
3334
"popplio/routes/staff"
3435
"popplio/routes/tasks"
3536
"popplio/routes/teams"
@@ -167,6 +168,7 @@ func main() {
167168
reminders.Router{},
168169
reviews.Router{},
169170
servers.Router{},
171+
shop.Router{},
170172
staff.Router{},
171173
tasks.Router{},
172174
teams.Router{},

routes/list/endpoints/get_changelog/route.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

routes/list/router.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package list
33
import (
44
"popplio/routes/list/endpoints/current_status"
55
"popplio/routes/list/endpoints/get_cache_servers"
6-
"popplio/routes/list/endpoints/get_changelog"
76
"popplio/routes/list/endpoints/get_list_stats"
87
"popplio/routes/list/endpoints/get_list_team"
98
"popplio/routes/list/endpoints/get_partners"
@@ -90,14 +89,6 @@ func (b Router) Routes(r *chi.Mux) {
9089
Handler: current_status.Route,
9190
}.Route(r)
9291

93-
uapi.Route{
94-
Pattern: "/list/changelog",
95-
OpId: "get_changelog",
96-
Method: uapi.GET,
97-
Docs: get_changelog.Docs,
98-
Handler: get_changelog.Route,
99-
}.Route(r)
100-
10192
uapi.Route{
10293
Pattern: "/list/cache-servers",
10394
OpId: "get_cache_servers",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package get_public_coupons
2+
3+
import (
4+
"net/http"
5+
"popplio/db"
6+
"popplio/state"
7+
"popplio/types"
8+
"strings"
9+
10+
docs "github.com/infinitybotlist/eureka/doclib"
11+
"github.com/infinitybotlist/eureka/uapi"
12+
"github.com/jackc/pgx/v5"
13+
"go.uber.org/zap"
14+
)
15+
16+
var (
17+
// Shop coupons
18+
shopCouponsColsArr = db.GetCols(types.ShopCoupon{})
19+
shopCouponsCols = strings.Join(shopCouponsColsArr, ",")
20+
)
21+
22+
func Docs() *docs.Doc {
23+
return &docs.Doc{
24+
Summary: "Get Shop Coupons",
25+
Description: "Gets the publicly viewable shop coupons on the list",
26+
Resp: types.ItemList[types.ShopCoupon]{},
27+
}
28+
}
29+
30+
func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
31+
rows, err := state.Pool.Query(d.Context, "SELECT "+shopCouponsCols+" FROM shop_coupons WHERE public = true ORDER BY created_at DESC")
32+
33+
if err != nil {
34+
state.Logger.Error("Failed to fetch shop coupons list [db fetch]", zap.Error(err))
35+
return uapi.DefaultResponse(http.StatusInternalServerError)
36+
}
37+
38+
defer rows.Close()
39+
40+
coupons, err := pgx.CollectRows(rows, pgx.RowToStructByName[types.ShopCoupon])
41+
42+
if err != nil {
43+
state.Logger.Error("Failed to fetch shop coupons list [db fetch]", zap.Error(err))
44+
return uapi.DefaultResponse(http.StatusInternalServerError)
45+
}
46+
47+
return uapi.HttpResponse{
48+
Status: http.StatusOK,
49+
Json: types.ItemList[types.ShopCoupon]{
50+
Items: coupons,
51+
},
52+
}
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package get_shop_item_benefits
2+
3+
import (
4+
"net/http"
5+
"popplio/db"
6+
"popplio/state"
7+
"popplio/types"
8+
"strings"
9+
10+
docs "github.com/infinitybotlist/eureka/doclib"
11+
"github.com/infinitybotlist/eureka/uapi"
12+
"github.com/jackc/pgx/v5"
13+
"go.uber.org/zap"
14+
)
15+
16+
var (
17+
// Shop item benefits
18+
shopItemBenefitsColsArr = db.GetCols(types.ShopItemBenefit{})
19+
shopItemBenefitsCols = strings.Join(shopItemBenefitsColsArr, ",")
20+
)
21+
22+
func Docs() *docs.Doc {
23+
return &docs.Doc{
24+
Summary: "Get Shop Items",
25+
Description: "Gets the publicly viewable shop items on the list",
26+
Resp: types.ItemList[types.ShopItemBenefit]{},
27+
}
28+
}
29+
30+
func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
31+
rows, err := state.Pool.Query(d.Context, "SELECT "+shopItemBenefitsCols+" FROM shop_item_benefits ORDER BY created_at DESC")
32+
33+
if err != nil {
34+
state.Logger.Error("Failed to fetch shop item benefits list [db fetch]", zap.Error(err))
35+
return uapi.DefaultResponse(http.StatusInternalServerError)
36+
}
37+
38+
defer rows.Close()
39+
40+
items, err := pgx.CollectRows(rows, pgx.RowToStructByName[types.ShopItemBenefit])
41+
42+
if err != nil {
43+
state.Logger.Error("Failed to fetch shop item benefits list [db fetch]", zap.Error(err))
44+
return uapi.DefaultResponse(http.StatusInternalServerError)
45+
}
46+
47+
return uapi.HttpResponse{
48+
Status: http.StatusOK,
49+
Json: types.ItemList[types.ShopItemBenefit]{
50+
Items: items,
51+
},
52+
}
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package get_shop_items
2+
3+
import (
4+
"net/http"
5+
"popplio/db"
6+
"popplio/state"
7+
"popplio/types"
8+
"strings"
9+
10+
docs "github.com/infinitybotlist/eureka/doclib"
11+
"github.com/infinitybotlist/eureka/uapi"
12+
"github.com/jackc/pgx/v5"
13+
"go.uber.org/zap"
14+
)
15+
16+
var (
17+
// Shop items
18+
shopItemsColsArr = db.GetCols(types.ShopItem{})
19+
shopItemsCols = strings.Join(shopItemsColsArr, ",")
20+
)
21+
22+
func Docs() *docs.Doc {
23+
return &docs.Doc{
24+
Summary: "Get Shop Items",
25+
Description: "Gets the publicly viewable shop items on the list",
26+
Resp: types.ItemList[types.ShopItem]{},
27+
}
28+
}
29+
30+
func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
31+
rows, err := state.Pool.Query(d.Context, "SELECT "+shopItemsCols+" FROM shop_items ORDER BY created_at DESC")
32+
33+
if err != nil {
34+
state.Logger.Error("Failed to fetch shop items list [db fetch]", zap.Error(err))
35+
return uapi.DefaultResponse(http.StatusInternalServerError)
36+
}
37+
38+
defer rows.Close()
39+
40+
items, err := pgx.CollectRows(rows, pgx.RowToStructByName[types.ShopItem])
41+
42+
if err != nil {
43+
state.Logger.Error("Failed to fetch shop items list [db fetch]", zap.Error(err))
44+
return uapi.DefaultResponse(http.StatusInternalServerError)
45+
}
46+
47+
return uapi.HttpResponse{
48+
Status: http.StatusOK,
49+
Json: types.ItemList[types.ShopItem]{
50+
Items: items,
51+
},
52+
}
53+
}

routes/shop/router.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package shop
2+
3+
import (
4+
"popplio/routes/shop/endpoints/get_public_coupons"
5+
"popplio/routes/shop/endpoints/get_shop_item_benefits"
6+
"popplio/routes/shop/endpoints/get_shop_items"
7+
8+
"github.com/go-chi/chi/v5"
9+
"github.com/infinitybotlist/eureka/uapi"
10+
)
11+
12+
const tagName = "Shop"
13+
14+
type Router struct{}
15+
16+
func (b Router) Tag() (string, string) {
17+
return tagName, "These API endpoints are related to the IBL shop."
18+
}
19+
20+
func (b Router) Routes(r *chi.Mux) {
21+
uapi.Route{
22+
Pattern: "/shop/public-coupons",
23+
OpId: "get_public_coupons",
24+
Method: uapi.GET,
25+
Docs: get_public_coupons.Docs,
26+
Handler: get_public_coupons.Route,
27+
}.Route(r)
28+
29+
uapi.Route{
30+
Pattern: "/shop/items",
31+
OpId: "get_shop_items",
32+
Method: uapi.GET,
33+
Docs: get_shop_items.Docs,
34+
Handler: get_shop_items.Route,
35+
}.Route(r)
36+
37+
uapi.Route{
38+
Pattern: "/shop/item-benefits",
39+
OpId: "get_shop_item_benefits",
40+
Method: uapi.GET,
41+
Docs: get_shop_item_benefits.Docs,
42+
Handler: get_shop_item_benefits.Route,
43+
}.Route(r)
44+
}

routes/votes/endpoints/get_all_votes/route.go renamed to routes/votes/endpoints/get_all_user_votes/route.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package get_all_votes
1+
package get_all_user_votes
22

33
import (
44
"net/http"
@@ -26,7 +26,7 @@ var (
2626

2727
func Docs() *docs.Doc {
2828
return &docs.Doc{
29-
Summary: "Get All Votes",
29+
Summary: "Get All User Votes",
3030
Description: "Gets all votes (paginated by 10) of a user on an entity. This endpoint is currently public as the same data can be found through #vote-logs in discord. Note that for compatibility, a trailing 's' is removed",
3131
Resp: types.PagedResult[[]types.EntityVote]{},
3232
RespName: "PagedResultUserVote",

0 commit comments

Comments
 (0)