Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit a213d87

Browse files
committed
added missing comments
1 parent 4592a14 commit a213d87

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

authentication-service/app/models/token.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package models
22

3+
// The token contains the token properties
34
type Token struct {
45
Token string `json:"token"`
56
ExpiresOn string `json:"expires_on"`

comment-service/app/http/controllers/controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
sharedModels "github.com/bstaijen/mariadb-for-microservices/shared/models"
2121
)
2222

23+
// CreateHandler creates a comment and stores it in the database
2324
func CreateHandler(connection *sql.DB, cnf config.Config) negroni.HandlerFunc {
2425
return negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
2526
commentObject := &models.CommentCreate{}
@@ -50,6 +51,7 @@ func CreateHandler(connection *sql.DB, cnf config.Config) negroni.HandlerFunc {
5051
})
5152
}
5253

54+
// ListCommentsHandler return a list of comments
5355
func ListCommentsHandler(connection *sql.DB, cnf config.Config) negroni.HandlerFunc {
5456
return negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
5557

@@ -96,6 +98,7 @@ func ListCommentsHandler(connection *sql.DB, cnf config.Config) negroni.HandlerF
9698
})
9799
}
98100

101+
// GetCommentCountHandler returns a list of counts beloning to comments.
99102
func GetCommentCountHandler(connection *sql.DB, cnf config.Config) negroni.HandlerFunc {
100103
return negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
101104
if r.Body == nil {
@@ -127,6 +130,7 @@ func GetCommentCountHandler(connection *sql.DB, cnf config.Config) negroni.Handl
127130
})
128131
}
129132

133+
// GetLastTenHandler returns a list of last 10 comments
130134
func GetLastTenHandler(connection *sql.DB, cnf config.Config) negroni.HandlerFunc {
131135
return negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
132136

comment-service/database/db.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func GetCommentByID(db *sql.DB, id int) (*sharedModels.CommentResponse, error) {
7474
return nil, ErrCommentNotFound
7575
}
7676

77+
// GetComments return an array of comments.
7778
func GetComments(db *sql.DB, photoID, offset, nrOfRows int) ([]*sharedModels.CommentResponse, error) {
7879
rows, err := db.Query("SELECT id, user_id, photo_id, comment, createdAt FROM comments WHERE photo_id=? ORDER BY createdAt DESC LIMIT ?, ?", photoID, offset, nrOfRows)
7980
if err != nil {
@@ -89,6 +90,7 @@ func GetComments(db *sql.DB, photoID, offset, nrOfRows int) ([]*sharedModels.Com
8990
return responses, nil
9091
}
9192

93+
// GetCommentCount returns the number of comment counts
9294
func GetCommentCount(db *sql.DB, items []*sharedModels.CommentCountRequest) ([]*sharedModels.CommentCountResponse, error) {
9395

9496
if len(items) < 1 {

vote-service/app/http/controllers/ipc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/bstaijen/mariadb-for-microservices/shared/util"
1414
)
1515

16+
// GetTopRatedHandler is the handler for the top rated timeline.
1617
func GetTopRatedHandler(connection *sql.DB) negroni.HandlerFunc {
1718
return negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
1819

@@ -32,6 +33,7 @@ func GetTopRatedHandler(connection *sql.DB) negroni.HandlerFunc {
3233
})
3334
}
3435

36+
// GetHotHandler is the handler for the hot photos timeline
3537
func GetHotHandler(connection *sql.DB) negroni.HandlerFunc {
3638
return negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
3739

@@ -51,6 +53,7 @@ func GetHotHandler(connection *sql.DB) negroni.HandlerFunc {
5153
})
5254
}
5355

56+
// HasVotedHandler is the handler for calculating whether the user has voted on a photo or not.
5457
func HasVotedHandler(connection *sql.DB) negroni.HandlerFunc {
5558
return negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
5659

@@ -78,6 +81,7 @@ func HasVotedHandler(connection *sql.DB) negroni.HandlerFunc {
7881
})
7982
}
8083

84+
// GetVoteCountHandler is the handler for calculating the number of votes on a photo
8185
func GetVoteCountHandler(connection *sql.DB) negroni.HandlerFunc {
8286
return negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
8387
type Collection struct {

vote-service/app/http/routes/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/urfave/negroni"
1212
)
1313

14+
// InitRoutes initializes the REST and IPC routes for this service.
1415
func InitRoutes(db *sql.DB, cnf config.Config) *mux.Router {
1516
router := mux.NewRouter()
1617
router = setRESTRoutes(db, cnf, router)

vote-service/database/db.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,51 +137,52 @@ func HasVoted(db *sql.DB, items []*sharedModels.HasVotedRequest) ([]*sharedModel
137137

138138
// GetTopRatedTimeline returns an array of top rated photos. The array contains a list of ID's. Offset and nrOfRows can be used for pagination.
139139
func GetTopRatedTimeline(db *sql.DB, offset int, nrOfRows int) ([]*sharedModels.TopRatedPhotoResponse, error) {
140-
rows, err := db.Query("SELECT photo_id, sum(upvote) AS total_upvote, sum(downvote) AS total_downvote, sum(upvote) - sum(downvote) as difference FROM votes GROUP BY photo_id ORDER BY difference DESC LIMIT ?, ?", offset, nrOfRows)
140+
rows, err := db.Query("SELECT photo_id as photoID, sum(upvote) AS totalUpvote, sum(downvote) AS totalDownvote, sum(upvote) - sum(downvote) as difference FROM votes GROUP BY photo_id ORDER BY difference DESC LIMIT ?, ?", offset, nrOfRows)
141141
if err != nil {
142142
return nil, err
143143
}
144144

145145
photos := make([]*sharedModels.TopRatedPhotoResponse, 0)
146146

147147
for rows.Next() {
148-
var photo_id int
149-
var total_upvote int
150-
var total_downvote int
148+
var photoID int
149+
var totalUpvote int
150+
var totalDownvote int
151151
var difference int
152152

153-
err = rows.Scan(&photo_id, &total_upvote, &total_downvote, &difference)
153+
err = rows.Scan(&photoID, &totalUpvote, &totalDownvote, &difference)
154154
if err != nil {
155155
return nil, err
156156
}
157157
photos = append(photos, &sharedModels.TopRatedPhotoResponse{
158-
PhotoID: photo_id,
158+
PhotoID: photoID,
159159
})
160160
}
161161
return photos, nil
162162
}
163163

164+
// GetHotTimeline returns an array of photos ordered by on which is most 'hot' meaning which has been voted on the most for the CURRENT_DAY
164165
func GetHotTimeline(db *sql.DB, offset int, nrOfRows int) ([]*sharedModels.TopRatedPhotoResponse, error) {
165-
rows, err := db.Query("SELECT photo_id, sum(upvote) AS total_upvote, sum(downvote) AS total_downvote, sum(upvote) - sum(downvote) AS difference FROM votes WHERE createdAt > DATE_SUB(now(), INTERVAL 1 DAY) GROUP BY photo_id ORDER BY difference DESC LIMIT ?, ?", offset, nrOfRows)
166+
rows, err := db.Query("SELECT photo_id as photoID, sum(upvote) AS totalUpvote, sum(downvote) AS totalDownvote, sum(upvote) - sum(downvote) AS difference FROM votes WHERE createdAt > DATE_SUB(now(), INTERVAL 1 DAY) GROUP BY photo_id ORDER BY difference DESC LIMIT ?, ?", offset, nrOfRows)
166167
if err != nil {
167168
return nil, err
168169
}
169170

170171
photos := make([]*sharedModels.TopRatedPhotoResponse, 0)
171172

172173
for rows.Next() {
173-
var photo_id int
174-
var total_upvote int
175-
var total_downvote int
174+
var photoID int
175+
var totalUpvote int
176+
var totalDownvote int
176177
var difference int
177178

178-
err = rows.Scan(&photo_id, &total_upvote, &total_downvote, &difference)
179+
err = rows.Scan(&photoID, &totalUpvote, &totalDownvote, &difference)
179180
if err != nil {
180181
return nil, err
181182
}
182183

183184
photos = append(photos, &sharedModels.TopRatedPhotoResponse{
184-
PhotoID: photo_id,
185+
PhotoID: photoID,
185186
})
186187
}
187188
return photos, nil

0 commit comments

Comments
 (0)