diff --git a/api/test/location_test.go b/api/test/location_test.go index 7136e46..7a5794e 100644 --- a/api/test/location_test.go +++ b/api/test/location_test.go @@ -157,7 +157,7 @@ func randomLocation() db.Location { TotalVisited: sql.NullInt32{Valid: true, Int32: int32(util.RandomInt(0, 32))}, Thumbnail: sql.NullString{Valid: false, String: ""}, RegencyID: 1305, - IsDeleted: sql.NullBool{Valid: true, Bool: false}, + IsDeleted: false, CreatedAt: sql.NullTime{Valid: true, Time: time.Now()}, UpdatedAt: sql.NullTime{Valid: true, Time: time.Now()}, ApprovedBy: sql.NullInt32{Valid: true, Int32: 1}, diff --git a/db/migrations/000007_create_user_follow_table.down.sql b/db/migrations/000007_create_user_follow_table.down.sql new file mode 100644 index 0000000..f442229 --- /dev/null +++ b/db/migrations/000007_create_user_follow_table.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS user_follow; \ No newline at end of file diff --git a/db/migrations/000007_create_user_follow_table.up.sql b/db/migrations/000007_create_user_follow_table.up.sql new file mode 100644 index 0000000..66db639 --- /dev/null +++ b/db/migrations/000007_create_user_follow_table.up.sql @@ -0,0 +1,7 @@ +CREATE TABLE user_follow( + id serial primary key not null, + follower_id integer references "users"("id") not null, + followee_id integer references "users"("id") not null, + created_at timestamp default (now()) not null, + updated_at timestamp default (now()) not null +) \ No newline at end of file diff --git a/db/mock/store.go b/db/mock/store.go index cb5df5a..1800a99 100644 --- a/db/mock/store.go +++ b/db/mock/store.go @@ -35,6 +35,20 @@ func (m *MockStore) EXPECT() *MockStoreMockRecorder { return m.recorder } +// AddFollowUser mocks base method. +func (m *MockStore) AddFollowUser(arg0 context.Context, arg1 db.AddFollowUserParams) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddFollowUser", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// AddFollowUser indicates an expected call of AddFollowUser. +func (mr *MockStoreMockRecorder) AddFollowUser(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddFollowUser", reflect.TypeOf((*MockStore)(nil).AddFollowUser), arg0, arg1) +} + // CheckIfReviewExists mocks base method. func (m *MockStore) CheckIfReviewExists(arg0 context.Context, arg1 db.CheckIfReviewExistsParams) (int64, error) { m.ctrl.T.Helper() @@ -334,6 +348,20 @@ func (mr *MockStoreMockRecorder) GetUserReviewByLocation(arg0, arg1 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserReviewByLocation", reflect.TypeOf((*MockStore)(nil).GetUserReviewByLocation), arg0, arg1) } +// RemoveFollowUser mocks base method. +func (m *MockStore) RemoveFollowUser(arg0 context.Context, arg1 db.RemoveFollowUserParams) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveFollowUser", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// RemoveFollowUser indicates an expected call of RemoveFollowUser. +func (mr *MockStoreMockRecorder) RemoveFollowUser(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveFollowUser", reflect.TypeOf((*MockStore)(nil).RemoveFollowUser), arg0, arg1) +} + // UpdatePassword mocks base method. func (m *MockStore) UpdatePassword(arg0 context.Context, arg1 db.UpdatePasswordParams) error { m.ctrl.T.Helper() diff --git a/db/queries/follow.sql b/db/queries/follow.sql new file mode 100644 index 0000000..5eaf124 --- /dev/null +++ b/db/queries/follow.sql @@ -0,0 +1,10 @@ +-- name: AddFollowUser :exec +INSERT INTO user_follow ( + follower_id, + followee_id +) VALUES($1, $2); + +-- name: RemoveFollowUser :exec +DELETE FROM +user_follow +WHERE follower_id = $1 AND followee_id = $2; \ No newline at end of file diff --git a/db/sqlc/follow.sql.go b/db/sqlc/follow.sql.go new file mode 100644 index 0000000..11cd982 --- /dev/null +++ b/db/sqlc/follow.sql.go @@ -0,0 +1,43 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.20.0 +// source: follow.sql + +package db + +import ( + "context" +) + +const addFollowUser = `-- name: AddFollowUser :exec +INSERT INTO user_follow ( + follower_id, + followee_id +) VALUES($1, $2) +` + +type AddFollowUserParams struct { + FollowerID int32 `json:"follower_id"` + FolloweeID int32 `json:"followee_id"` +} + +func (q *Queries) AddFollowUser(ctx context.Context, arg AddFollowUserParams) error { + _, err := q.db.ExecContext(ctx, addFollowUser, arg.FollowerID, arg.FolloweeID) + return err +} + +const removeFollowUser = `-- name: RemoveFollowUser :exec +DELETE FROM +user_follow +WHERE follower_id = $1 AND followee_id = $2 +` + +type RemoveFollowUserParams struct { + FollowerID int32 `json:"follower_id"` + FolloweeID int32 `json:"followee_id"` +} + +func (q *Queries) RemoveFollowUser(ctx context.Context, arg RemoveFollowUserParams) error { + _, err := q.db.ExecContext(ctx, removeFollowUser, arg.FollowerID, arg.FolloweeID) + return err +} diff --git a/db/sqlc/models.go b/db/sqlc/models.go index 488ee4d..0f15740 100644 --- a/db/sqlc/models.go +++ b/db/sqlc/models.go @@ -190,7 +190,7 @@ type Location struct { TotalVisited sql.NullInt32 `json:"total_visited"` Thumbnail sql.NullString `json:"thumbnail"` RegencyID int16 `json:"regency_id"` - IsDeleted sql.NullBool `json:"is_deleted"` + IsDeleted bool `json:"is_deleted"` CreatedAt sql.NullTime `json:"created_at"` UpdatedAt sql.NullTime `json:"updated_at"` ApprovedBy sql.NullInt32 `json:"approved_by"` @@ -282,6 +282,14 @@ type UserActivity struct { UpdatedAt time.Time `json:"updated_at"` } +type UserFollow struct { + ID int32 `json:"id"` + FollowerID int32 `json:"follower_id"` + FolloweeID int32 `json:"followee_id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + type UserReport struct { ID int32 `json:"id"` Message string `json:"message"` diff --git a/db/sqlc/querier.go b/db/sqlc/querier.go index e6a258d..3729763 100644 --- a/db/sqlc/querier.go +++ b/db/sqlc/querier.go @@ -9,6 +9,7 @@ import ( ) type Querier interface { + AddFollowUser(ctx context.Context, arg AddFollowUserParams) error CheckIfReviewExists(ctx context.Context, arg CheckIfReviewExistsParams) (int64, error) CreateSession(ctx context.Context, arg CreateSessionParams) (UserSession, error) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) @@ -21,6 +22,7 @@ type Querier interface { GetLocationTag(ctx context.Context, targetID int32) ([]string, error) GetSession(ctx context.Context, id int32) (UserSession, error) GetUserReviewByLocation(ctx context.Context, arg GetUserReviewByLocationParams) (GetUserReviewByLocationRow, error) + RemoveFollowUser(ctx context.Context, arg RemoveFollowUserParams) error UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error) }