Skip to content

Commit 8afab02

Browse files
committed
Revert "feat: refactor to support larger user base - integrating FE interface"
This reverts commit c3d8102.
1 parent 304d161 commit 8afab02

5 files changed

Lines changed: 5 additions & 58 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ After completing the twitter sign in step, a JSON containing your details and JW
3939
First, clone the repo and install the dependencies:
4040

4141
```bash
42-
git clone https://github.com/opensaucerers/giveawaybotapi.git
43-
cd giveawaybotapi
42+
git clone https://github.com/opensaucerers/giveawaybot.git
43+
cd giveawaybot
4444
go mod tidy
4545
```
4646

‎controller/v1/giveaway/tweet.go‎

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package giveaway
33
import (
44
"context"
55
"net/http"
6-
"strconv"
76

8-
"github.com/opensaucerers/giveawaybot/config"
97
"github.com/opensaucerers/giveawaybot/helper"
108
"github.com/opensaucerers/giveawaybot/logic/v1/giveaway"
119
"github.com/opensaucerers/giveawaybot/repository/v1/user"
@@ -35,7 +33,7 @@ func Replies(w http.ResponseWriter, r *http.Request) {
3533

3634
// Replies retrieves all replies to a giveaway
3735
func Report(w http.ResponseWriter, r *http.Request) {
38-
// get giveaway id from context
36+
// get user from context
3937
id := r.Context().Value(typing.ParamsCtxKey{}).(map[string]string)["id"]
4038
if id == "" {
4139
helper.SendJSONResponse(w, false, http.StatusBadRequest, "Invalid giveaway ID", nil)
@@ -51,34 +49,3 @@ func Report(w http.ResponseWriter, r *http.Request) {
5149
// send response
5250
helper.SendJSONResponse(w, true, http.StatusOK, "Report generated", typing.M{"report": report})
5351
}
54-
55-
// Past retrieves past giveaways
56-
func Past(w http.ResponseWriter, r *http.Request) {
57-
58-
var err error
59-
60-
var limit, offset int
61-
limit = config.DefaultPageLimit
62-
if r.URL.Query().Get("limit") != "" {
63-
if limit, err = strconv.Atoi(r.URL.Query().Get("limit")); err != nil {
64-
helper.SendJSONResponse(w, false, http.StatusBadRequest, err.Error(), nil)
65-
return
66-
}
67-
}
68-
69-
if r.URL.Query().Get("offset") != "" {
70-
if offset, err = strconv.Atoi(r.URL.Query().Get("offset")); err != nil {
71-
helper.SendJSONResponse(w, false, http.StatusBadRequest, err.Error(), nil)
72-
return
73-
}
74-
}
75-
76-
past, err := giveaway.Past(limit, offset)
77-
if err != nil {
78-
helper.SendJSONResponse(w, false, http.StatusBadRequest, err.Error(), nil)
79-
return
80-
}
81-
82-
// send response
83-
helper.SendJSONResponse(w, true, http.StatusOK, "Giveaways retrieved", typing.M{"past": past})
84-
}

‎logic/v1/giveaway/tweet.go‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/opensaucerers/giveawaybot/repository/v1/user"
1111
"github.com/opensaucerers/giveawaybot/service"
1212
"github.com/opensaucerers/giveawaybot/typing"
13-
"go.mongodb.org/mongo-driver/bson"
1413
"go.mongodb.org/mongo-driver/bson/primitive"
1514
)
1615

@@ -150,21 +149,3 @@ func Report(id string) (*giveaway.Report, error) {
150149

151150
return &report, nil
152151
}
153-
154-
// Past retrieves past giveaways
155-
func Past(limit, offset int) (giveaway.Giveaways, error) {
156-
// build giveaway
157-
ga := giveaway.Giveaways{}
158-
159-
// get past giveaways
160-
err := ga.FindGiveawaysByMatch(bson.M{
161-
"active": false,
162-
"completed": true,
163-
"rewarded": true,
164-
}, int64(limit), int64(offset))
165-
if err != nil {
166-
return nil, err
167-
}
168-
169-
return ga, nil
170-
}

‎repository/v1/giveaway/giveaway.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (g *Giveaways) FindGiveawaysByMatch(match bson.M, limit, offset int64) erro
217217
if cursor, err := database.MongoDB.Collection(config.GiveawayCollection).Find(context.Background(), match, &options.FindOptions{
218218
Limit: &limit,
219219
Skip: &offset,
220-
Sort: bson.M{"created_at": -1},
220+
// Sort: bson.M{"created_at": -1},
221221
}); err != nil {
222222
return err
223223
} else {
@@ -233,7 +233,7 @@ func (r *Replies) FindRepliesByMatch(match bson.M, limit, offset int64) error {
233233
if cursor, err := database.MongoDB.Collection(config.RepliesCollection).Find(context.Background(), match, &options.FindOptions{
234234
Limit: &limit,
235235
Skip: &offset,
236-
Sort: bson.M{"created_at": -1},
236+
// Sort: bson.M{"created_at": -1},
237237
}); err != nil {
238238
return err
239239
} else {

‎route/v1/giveaway/tweet.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ func RegisterTweetRoutes(r *mux.Router) {
1313
// making them GET methods for now while there's no UI
1414
router.Handle("/replies", middleware.AuthF(giveaway.Replies)).Methods("GET")
1515
router.Handle("/report/{id}", middleware.ParamsF(giveaway.Report)).Methods("GET")
16-
router.HandleFunc("/past", giveaway.Past).Methods("GET")
1716
}

0 commit comments

Comments
 (0)