Skip to content

Commit

Permalink
Merge pull request #32 from bitroll-team/dev
Browse files Browse the repository at this point in the history
chore(release) v0.9.0
  • Loading branch information
Woynert authored Oct 25, 2023
2 parents 1ae975d + 938eef2 commit 291f1c9
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 15 deletions.
23 changes: 9 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [0.10.0](https://github.com/bitroll-team/codefest1-users/compare/v0.9.0...v0.10.0) (2023-10-25)


### Features

* unfollow user ([84f9066](https://github.com/bitroll-team/codefest1-users/commit/84f9066c315cc685ff89aa30bf22b5abd8fff662))



# [0.9.0](https://github.com/bitroll-team/codefest1-users/compare/v0.8.0...v0.9.0) (2023-10-25)


Expand Down Expand Up @@ -34,17 +43,3 @@



# [0.5.0](https://github.com/bitroll-team/codefest1-users/compare/v0.4.1...v0.5.0) (2023-10-25)


### Bug Fixes

* cors ([d22aeb4](https://github.com/bitroll-team/codefest1-users/commit/d22aeb406b9835f61f2e5c033a45e3d8ff688125))


### Features

* register teacher ([66dbd36](https://github.com/bitroll-team/codefest1-users/commit/66dbd36a7feeecd40cf9b752a928f75767ba64a2))



23 changes: 23 additions & 0 deletions controller/friends.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,26 @@ func (ctrl *Controller) FollowUser(req model.ReqFollowUser, userId uuid.UUID) er

return nil
}

func (ctrl *Controller) UnFollowUser(req model.ReqFollowUser, userId uuid.UUID) error {

// write

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

query := `
DELETE FROM followers WHERE follower_user_uuid = $1 AND followed_user_uuid = $2
`
_, err := ctrl.DB.ExecContext(
ctx,
query,
userId,
req.OtherUserId,
)
if err != nil {
return err
}

return nil
}
18 changes: 18 additions & 0 deletions docs/bruno-users/friends/unfollow.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
meta {
name: unfollow
type: http
seq: 3
}

post {
url: {{BASE_URL}}/{{API_PATH}}/user/follow
body: json
auth: none
}

body:json {
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIyMDIzLTEwLTI1VDE3OjA2OjUyLjg0MDc1MjMyMi0wNTowMCIsIm5iZiI6IjIwMjMtMTAtMjVUMTY6NTY6NTIuODQwNzUwMDk0LTA1OjAwIiwidXNlcmlkIjoiMGVhNWRiNTAtYWJlYS00YzNiLTg0NDQtZGMxZTg5MjFkMWU2In0.I2P5NfVd9EYQwjHk45BfyHO7iI5tL2lshL8p6wKVXCg",
"otheruserid" : "0818f7a7-e8df-44c3-a981-52dd6150f2ab"
}
}
33 changes: 33 additions & 0 deletions router/friends.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,36 @@ func (r *Router) FollowUser(ctx *gin.Context) {

ctx.JSON(http.StatusOK, gin.H{"msg": "Following user"})
}

func (r *Router) UnFollowUser(ctx *gin.Context) {
// validate

var req model.ReqFollowUser
if err := ctx.BindJSON(&req); err != nil {
log.Println(err)
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.MsgBadRequest())
return
}
if err := r.validator.Struct(req); err != nil {
ctx.JSON(http.StatusBadRequest, model.MsgValidationErr(err.Error()))
return
}

// validate access token

err, claims := ValidateToken(req.Token, []byte(config.Cfg.Secret))
if err != nil {
log.Println(err)
ctx.AbortWithStatusJSON(http.StatusUnauthorized,
gin.H{"message": "Invalid access token"})
return
}
userId := claims.UserID

if err := r.ctrl.UnFollowUser(req, userId); err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.MsgIntServerErr())
return
}

ctx.JSON(http.StatusOK, gin.H{"msg": "User unfollowed"})
}
1 change: 1 addition & 0 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func SetupRouter(ctrl *controller.Controller) Router {
user.POST("/register_teacher", r.RegisterTeacher)
user.POST("/search", r.SearchUser)
user.POST("/follow", r.FollowUser)
user.POST("/unfollow", r.UnFollowUser)

sess := base.Group("/session")
sess.POST("/login", r.Login)
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.9.0"
"version": "0.10.0"
}

0 comments on commit 291f1c9

Please sign in to comment.