Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
col3name committed Jun 15, 2021
1 parent 426bb3c commit 6175868
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
13 changes: 9 additions & 4 deletions internal/videoserver/infrastructure/mysql/videoRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,17 @@ func (r *VideoRepository) Find(videoId string) (*model.Video, error) {
SUM(IF(isLike = 1, 1, 0)) AS video_likes
FROM video_like
WHERE id_video = ?`
row = r.connector.GetDb().QueryRow(q, videoId)
rows, err := r.connector.GetDb().Query(q, videoId)
if err != nil {
return nil, err
}
defer rows.Close()
var countLikes sql.NullInt64
var countDisLikes sql.NullInt64
err = row.Scan(
&countDisLikes,
&countLikes)

video.CountLikes = int(countLikes.Int64)
video.CountDisLikes = int(countDisLikes.Int64)
return &video, err
Expand Down Expand Up @@ -282,9 +287,9 @@ func (r *VideoRepository) Like(like model.Like) (model.Action, error) {
rows, err := r.connector.GetDb().Query(query, like.IdVideo, like.OwnerId)

if err == nil {
defer rows.Close()
var isLike bool
if rows.Next() {
defer rows.Close()
err = rows.Scan(&isLike)
if err != nil {
return 0, domain.ErrInternal
Expand All @@ -307,15 +312,15 @@ func (r *VideoRepository) Like(like model.Like) (model.Action, error) {
}
}
}

}
query = `INSERT INTO video_like (id_video, owner_id, isLike)
VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE isLike=?;`
_, err = r.connector.GetDb().Query(query, like.IdVideo, like.OwnerId, like.IsLike, like.IsLike)
rows, err = r.connector.GetDb().Query(query, like.IdVideo, like.OwnerId, like.IsLike, like.IsLike)
if err != nil {
return 0, domain.ErrFailedAddLike
}
defer rows.Close()
if like.IsLike {
return model.AddLike, nil
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func Router(connector db.Connector, messageBrokerAddress string, authServerAddre
subRouter.HandleFunc("/videos/{videoId}/add-quality", videoController.AddQuality()).Methods(http.MethodPut, http.MethodOptions)
subRouter.HandleFunc("/videos/{videoId}", videoController.DeleteVideo()).Methods(http.MethodDelete, http.MethodOptions)
subRouter.HandleFunc("/videos/{videoId}/increment", videoController.IncrementViews()).Methods(http.MethodPost, http.MethodOptions)
subRouter.HandleFunc("/videos-liked", middleware.AllowCors(middleware.AuthMiddleware(videoController.FindUserLikedVideo(), authServerAddress))).Methods(http.MethodGet, http.MethodOptions)
subRouter.HandleFunc("/videos/{videoId}/like/{isLike:[0-1]}", middleware.AllowCors(middleware.AuthMiddleware(videoController.LikeVideo(), authServerAddress))).Methods(http.MethodPost, http.MethodOptions)
subRouter.HandleFunc("/videos-liked", middleware.AuthMiddleware(videoController.FindUserLikedVideo(), authServerAddress)).Methods(http.MethodGet, http.MethodOptions)
subRouter.HandleFunc("/videos/{videoId}/like/{isLike:[0-1]}", middleware.AuthMiddleware(videoController.LikeVideo(), authServerAddress)).Methods(http.MethodPost, http.MethodOptions)

var imgServer = http.FileServer(http.Dir("C:\\Users\\mikha\\go\\src\\videohost\\bin\\videoserver\\content"))
router.PathPrefix("/content/").Handler(http.StripPrefix("/content/", imgServer))
Expand Down
3 changes: 1 addition & 2 deletions profile.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@echo
@echo off
curl -sK -v http://localhost:%1/debug/pprof/profile/%2 > %3.out
go tool pprof %2.out
go tool pprof %3.out

0 comments on commit 6175868

Please sign in to comment.