-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from decert-me/feature/statistics
Feature 用户标签显示
- Loading branch information
Showing
10 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dao | ||
|
||
import ( | ||
"backend-go/internal/app/model" | ||
) | ||
|
||
func (d *Dao) IsAdmin(address string) (is bool, err error) { | ||
var count int64 | ||
if err = d.db.Model(&model.AdminUser{}).Where("address = ?", address).Count(&count).Error; err != nil { | ||
return false, err | ||
} | ||
if count == 0 { | ||
return false, nil | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dao | ||
|
||
import "backend-go/internal/app/model" | ||
|
||
func (d *Dao) GetUserTags(userID uint) (tags []string, err error) { | ||
err = d.db.Model(&model.UsersTag{}).Select("tag.name"). | ||
Joins("join tag on users_tag.tag_id = tag.id"). | ||
Where("users_tag.user_id = ?", userID). | ||
Find(&tags).Error | ||
return | ||
} | ||
|
||
func (d *Dao) GetUserNameTagsByAddress(address string) (nickname, name string, tags []string, err error) { | ||
var user model.Users | ||
err = d.db.Model(&model.Users{}). | ||
Where("address = ?", address). | ||
First(&user).Error | ||
if err != nil { | ||
return | ||
} | ||
if user.Name != nil { | ||
name = *user.Name | ||
} | ||
if user.NickName != nil { | ||
nickname = *user.NickName | ||
} | ||
err = d.db.Model(&model.UsersTag{}).Select("tag.name"). | ||
Joins("join tag on users_tag.tag_id = tag.id"). | ||
Where("users_tag.user_id = ?", user.ID). | ||
Find(&tags).Error | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
type Tag struct { | ||
ID uint `gorm:"primarykey" json:"id"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
Name string `gorm:"column:name;unique;type:varchar(100);comment:标签名" json:"name"` | ||
} | ||
|
||
func (Tag) TableName() string { | ||
return "tag" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package model | ||
|
||
type UsersTag struct { | ||
ID uint `gorm:"primarykey" json:"id"` // 主键ID | ||
UserID uint `gorm:"column:user_id;comment:用户ID;index:user_id_tag_id,unique" json:"userID"` // 用户ID | ||
TagID uint `gorm:"column:tag_id;comment:标签ID;index:user_id_tag_id,unique" json:"tagID"` // 标签ID | ||
} | ||
|
||
func (UsersTag) TableName() string { | ||
return "users_tag" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters