Selaa lähdekoodia

refactor(internal/repository): 优化 AllowAndDenyIp 相关查询

- 在 GetAllowAndDenyIpsAllByHostId 函数中使用 Model 指定查询的表
- 在 GetIpCount
fusu 3 viikkoa sitten
vanhempi
sitoutus
df49a330a3
1 muutettua tiedostoa jossa 2 lisäystä ja 2 poistoa
  1. 2 2
      internal/repository/allowanddenyip.go

+ 2 - 2
internal/repository/allowanddenyip.go

@@ -61,7 +61,7 @@ func (r *allowAndDenyIpRepository) DeleteAllowAndDenyIps(ctx context.Context, id
 
 func (r *allowAndDenyIpRepository) GetAllowAndDenyIpsAllByHostId(ctx context.Context, hostId int64) ([]*model.AllowAndDenyIp, error) {
 	var res []*model.AllowAndDenyIp
-	if err := r.DB(ctx).Where("host_id = ?", hostId).Find(&res).Error; err != nil {
+	if err := r.DB(ctx).Model(&model.AllowAndDenyIp{}).Where("host_id = ?", hostId).Find(&res).Error; err != nil {
 		return nil, err
 	}
 	return res, nil
@@ -69,7 +69,7 @@ func (r *allowAndDenyIpRepository) GetAllowAndDenyIpsAllByHostId(ctx context.Con
 
 func (r *allowAndDenyIpRepository) GetIpCount(ctx context.Context,hostId int64,ip string) (int64, error) {
 	var count int64
-	if err := r.DB(ctx).Where("host_id = ?", hostId).Where("ip = ?", ip).Count(&count).Error; err != nil {
+	if err := r.DB(ctx).Model(&model.AllowAndDenyIp{}).Where("host_id = ?", hostId).Where("ip = ?", ip).Count(&count).Error; err != nil {
 		return 0, err
 	}
 	return count, nil