diff --git a/modules/scylladb/models.go b/modules/scylladb/models.go index f83565d..3ffc6e6 100644 --- a/modules/scylladb/models.go +++ b/modules/scylladb/models.go @@ -69,4 +69,18 @@ var ( }, PartKey: []string{"user_first_id", "user_second_id"}, }) + + UserRelationship = table.New(table.Metadata{ + Name: "user_relationship", + Columns: []string{ + "user_first_id", + "user_second_id", + "user_first_following_state", + "user_second_following_state", + "blocked_state", + "created_at", + "updated_at", + }, + PartKey: []string{"user_first_id", "user_second_id"}, + }) ) diff --git a/modules/structs/user.go b/modules/structs/user.go index 965f649..a669095 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -67,3 +67,18 @@ type UserSignUpProcess struct { type UserSignUpProcessesResponse struct { UserSignUpProcesses []UserSignUpProcess } + +type UserRelationship struct { + UserFirstId string + UserSecondId string + UserFirstFollowingState uint8 + UserSecondFollowingState uint8 + BlockedState uint8 + CreatedAt int64 + UpdatedAt int64 +} + +// swagger:model UserRelationshipsResponse +type UserRelationshipsResponse struct { + Relationships []UserRelationship +} diff --git a/routers/api/v1/users/users.go b/routers/api/v1/users/users.go index 5a9e961..378942f 100644 --- a/routers/api/v1/users/users.go +++ b/routers/api/v1/users/users.go @@ -69,3 +69,30 @@ func GetAllUserSignUpProcesses(c *fiber.Ctx) error { return c.JSON(structs.UserSignUpProcessesResponse{UserSignUpProcesses: userSignUpProcesses}) } + +func GetAllUserRelationships(c *fiber.Ctx) error { + // swagger:operation GET /users/relationships users usersGetAllUserRelationships + // --- + // summary: List of user relationships + // consumes: + // - application/json + // produces: + // - application/json + // responses: + // '200': + // description: List of user relationships + // schema: + // "$ref": "#/definitions/UsersResponse" + // '500': + // description: Internal server error + + var userRelationships []structs.UserRelationship + + q := scylladb.Session.Query(scylladb.UserRelationship.SelectAll()) + + if err := q.SelectRelease(&userRelationships); err != nil { + logrus.Errorln("Failed to get user relationships, err:", err) + } + + return c.JSON(structs.UserRelationshipsResponse{Relationships: userRelationships}) +} diff --git a/routers/router/router.go b/routers/router/router.go index 6f95aca..ee09f66 100644 --- a/routers/router/router.go +++ b/routers/router/router.go @@ -14,6 +14,7 @@ func SetupRoutes(app *fiber.App) { us := v1.Group("/users") us.Get("/", ApiKeyValidation, users.GetAllUsers) us.Get("/signupprocesses", ApiKeyValidation, users.GetAllUserSignUpProcesses) + us.Get("/relationships", ApiKeyValidation, users.GetAllUserRelationships) wss := v1.Group("/wssessions") wss.Get("/", ApiKeyValidation, wssessions.GetAllWsSessions)