Skip to content

Commit

Permalink
move Dir "kite_gen pack dal" to root
Browse files Browse the repository at this point in the history
  • Loading branch information
a76yyyy committed Jun 11, 2022
1 parent 8a11faf commit 44cc7cc
Show file tree
Hide file tree
Showing 45 changed files with 4,673 additions and 36 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.lh
output/
.vscode/
log/

*.log

Expand Down
4 changes: 2 additions & 2 deletions cmd/api/handlers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

"github.com/a76yyyy/tiktok/pkg/errno"

"github.com/a76yyyy/tiktok/cmd/user/kitex_gen/user"
"github.com/a76yyyy/tiktok/cmd/user/pack"
"github.com/a76yyyy/tiktok/kitex_gen/user"
"github.com/a76yyyy/tiktok/pack"

"github.com/a76yyyy/tiktok/cmd/api/rpc"

Expand Down
4 changes: 2 additions & 2 deletions cmd/api/rpc/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"time"

etcd "github.com/a76yyyy/registry-etcd"
"github.com/a76yyyy/tiktok/cmd/user/kitex_gen/user"
"github.com/a76yyyy/tiktok/cmd/user/kitex_gen/user/usersrv"
"github.com/a76yyyy/tiktok/kitex_gen/user"
"github.com/a76yyyy/tiktok/kitex_gen/user/usersrv"
"github.com/a76yyyy/tiktok/pkg/errno"
"github.com/a76yyyy/tiktok/pkg/middleware"
"github.com/a76yyyy/tiktok/pkg/ttviper"
Expand Down
6 changes: 3 additions & 3 deletions cmd/user/command/getUserByID.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package command
import (
"context"

"github.com/a76yyyy/tiktok/cmd/user/kitex_gen/user"
"github.com/a76yyyy/tiktok/kitex_gen/user"

"github.com/a76yyyy/tiktok/cmd/user/dal/db"
"github.com/a76yyyy/tiktok/cmd/user/pack"
"github.com/a76yyyy/tiktok/dal/db"
"github.com/a76yyyy/tiktok/pack"
)

type MGetUserService struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/user/command/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"github.com/a76yyyy/tiktok/pkg/errno"

"github.com/a76yyyy/tiktok/cmd/user/kitex_gen/user"
"github.com/a76yyyy/tiktok/kitex_gen/user"

"github.com/a76yyyy/tiktok/cmd/user/dal/db"
"github.com/a76yyyy/tiktok/dal/db"
)

type CheckUserService struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/user/command/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"github.com/a76yyyy/tiktok/pkg/errno"

"github.com/a76yyyy/tiktok/cmd/user/kitex_gen/user"
"github.com/a76yyyy/tiktok/kitex_gen/user"

"github.com/a76yyyy/tiktok/cmd/user/dal/db"
"github.com/a76yyyy/tiktok/dal/db"
)

type CreateUserService struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/user/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"

"github.com/a76yyyy/tiktok/cmd/user/command"
"github.com/a76yyyy/tiktok/cmd/user/kitex_gen/user"
"github.com/a76yyyy/tiktok/cmd/user/pack"
"github.com/a76yyyy/tiktok/kitex_gen/user"
"github.com/a76yyyy/tiktok/pack"
"github.com/a76yyyy/tiktok/pkg/errno"
"github.com/a76yyyy/tiktok/pkg/jwt"
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/user/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/cloudwego/kitex/pkg/klog"

etcd "github.com/a76yyyy/registry-etcd"
"github.com/a76yyyy/tiktok/cmd/user/dal"
user "github.com/a76yyyy/tiktok/cmd/user/kitex_gen/user/usersrv"
"github.com/a76yyyy/tiktok/dal"
user "github.com/a76yyyy/tiktok/kitex_gen/user/usersrv"
"github.com/a76yyyy/tiktok/pkg/dlog"
"github.com/a76yyyy/tiktok/pkg/jwt"
"github.com/a76yyyy/tiktok/pkg/middleware"
Expand Down
30 changes: 30 additions & 0 deletions dal/db/feed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package db

import (
"context"
"time"

"gorm.io/gorm"
)

type Video struct {
gorm.Model
// UpdatedAt time.Time `gorm:"column:update_time;not null;index:idx_update" `
Author User `gorm:"ForeignKey:AuthorID;AssociationForeignKey:ID"`
AuthorID int
PlayUrl string `gorm:"type:varchar(255);not null"`
CoverUrl string `gorm:"type:varchar(255)"`
FavoriteCount int `gorm:"default:0"`
CommentCount int `gorm:"default:0"`
Title string `gorm:"type:varchar(50);not null"`
}

// MGetVideoss multiple get list of videos info
func MGetVideos(ctx context.Context, latestTime int64) ([]*Video, error) {
videos := make([]*Video, 0)

if err := DB.WithContext(ctx).Limit(30).Order("update_time desc").Find(&videos, "update_time < ?", time.UnixMilli(latestTime)).Error; err != nil {
return nil, err
}
return videos, nil
}
7 changes: 2 additions & 5 deletions cmd/user/dal/db/init.go → dal/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@ import (
"fmt"

"github.com/a76yyyy/tiktok/pkg/ttviper"
"github.com/spf13/pflag"
"github.com/uptrace/opentelemetry-go-extra/otelgorm"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)

var (
DB *gorm.DB
TableName = pflag.String("mysql.tablename", "", "Mysql Table Name")
DB *gorm.DB
)

// Init init DB
func InitDB(config *ttviper.Config) {
var err error
viper := config.Viper
*TableName = viper.GetString("mysql.tablename")
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=%t&loc=%s",
viper.GetString("mysql.user"),
viper.GetString("mysql.password"),
Expand All @@ -59,7 +56,7 @@ func InitDB(config *ttviper.Config) {
panic(err)
}

if err := DB.AutoMigrate(&User{}); err != nil {
if err := DB.AutoMigrate(&User{}, &Video{}); err != nil {
panic(err)
}
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/user/dal/db/user.go → dal/db/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ type User struct {
FollowerCount int `gorm:"default:0"`
}

func (u *User) TableName() string {
return *TableName
}

// MGetUsers multiple get list of user info
func MGetUsers(ctx context.Context, userIDs []int64) ([]*User, error) {
res := make([]*User, 0)
Expand Down
2 changes: 1 addition & 1 deletion cmd/user/dal/init.go → dal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package dal

import (
db "github.com/a76yyyy/tiktok/cmd/user/dal/db"
db "github.com/a76yyyy/tiktok/dal/db"
"github.com/a76yyyy/tiktok/pkg/ttviper"
)

Expand Down
Loading

0 comments on commit 44cc7cc

Please sign in to comment.