Skip to content

Commit

Permalink
准备发布 v0.1.1 版本 (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash authored Jun 12, 2024
2 parents d04dbe9 + dedbdd2 commit 9720204
Show file tree
Hide file tree
Showing 23 changed files with 787 additions and 24 deletions.
5 changes: 4 additions & 1 deletion internal/label/internal/integration/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ func (s *HandlerTestSuite) TestSystemLabels() {
before: func(t *testing.T) {
err := s.db.Create([]dao.Label{
{Id: 1, Name: "test", Uid: -1},
{Id: 2, Name: "non-system", Uid: 123}}).Error
{Id: 2, Name: "non-system", Uid: 123},
{Id: 3, Name: "test-1", Uid: -1},
}).Error
require.NoError(t, err)
},
wantCode: 200,
wantResp: test.Result[[]web.Label]{
Data: []web.Label{
{Id: 3, Name: "test-1"},
{Id: 1, Name: "test"},
},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/label/internal/repository/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (dao *LabelGORMDAO) CreateLabel(ctx context.Context, label Label) (int64, e
func (dao *LabelGORMDAO) UidLabels(ctx context.Context, uid int64) ([]Label, error) {
var res []Label
err := dao.db.WithContext(ctx).
Where("uid = ?", uid).Find(&res).Error
Where("uid = ?", uid).Order("id DESC").Find(&res).Error
return res, err
}

Expand All @@ -57,9 +57,9 @@ func NewLabelGORMDAO(db *egorm.Component) LabelDAO {
}

type Label struct {
Id int64 `gorm:"primaryKey,autoIncrement"`
Name string
Uid int64 `gorm:"index"`
Id int64 `gorm:"primaryKey,autoIncrement"`
Name string `gorm:"type:varchar(256);unique"`
Uid int64 `gorm:"index"`
Ctime int64
Utime int64
}
11 changes: 11 additions & 0 deletions internal/member/internal/integration/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,14 @@ func (s *ModuleTestSuite) TestService_ActivateMembership_Concurrent() {
})

}

func (s *ModuleTestSuite) TestService_GetMembershipInfo() {
t := s.T()

t.Run("不报错_当用户没有会员信息时", func(t *testing.T) {
uid := int64(99999999)
info, err := s.svc.GetMembershipInfo(context.Background(), uid)
require.NoError(t, err)
require.Equal(t, domain.Member{Records: []domain.MemberRecord{}}, info)
})
}
4 changes: 4 additions & 0 deletions internal/member/internal/repository/dao/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/ego-component/egorm"
"github.com/go-sql-driver/mysql"
"gorm.io/gorm"
)

var (
Expand All @@ -47,6 +48,9 @@ func NewMemberGORMDAO(db *egorm.Component) MemberDAO {
func (g *memberGROMDAO) FindMemberByUID(ctx context.Context, uid int64) (Member, error) {
var m Member
err := g.db.WithContext(ctx).First(&m, "uid", uid).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return m, nil
}
return m, err
}

Expand Down
9 changes: 8 additions & 1 deletion internal/pkg/middleware/check_membership_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *CheckMembershipMiddlewareBuilder) Build() gin.HandlerFunc {
return
}

elog.Debug("会员已过期", elog.Int64("uid", claims.Uid),
elog.Debug("未开通过会员或会员已过期", elog.Int64("uid", claims.Uid),
elog.String("ddl", time.UnixMilli(memberDDL).Format(time.DateTime)))

// 1. jwt中未找到会员截止日期
Expand All @@ -74,6 +74,13 @@ func (c *CheckMembershipMiddlewareBuilder) Build() gin.HandlerFunc {
return
}

if info.EndAt == 0 {
elog.Debug("未开通会员", elog.Int64("uid", claims.Uid),
elog.String("ddl", time.UnixMilli(info.EndAt).Format(time.DateTime)))
gctx.AbortWithStatus(http.StatusForbidden)
return
}

if info.EndAt < time.Now().UnixMilli() {
elog.Debug("会员已过期", elog.Int64("uid", claims.Uid),
elog.String("ddl", time.UnixMilli(info.EndAt).Format(time.DateTime)))
Expand Down
24 changes: 24 additions & 0 deletions internal/pkg/middleware/check_membership_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ func TestCheck(t *testing.T) {
afterFunc: func(t *testing.T, ctx *ginx.Context) {},
wantCode: 200,
},
{
name: "JWT无效会员-未开通过会员",
mock: func(ctrl *gomock.Controller) (member.Service, session.Provider) {
service := membermocks.NewMockService(ctrl)
service.EXPECT().GetMembershipInfo(gomock.Any(), int64(2795)).
Return(member.Member{}, nil)

mockSession := sessmocks.NewMockSession(ctrl)
claims := session.Claims{
Uid: 2795,
SSID: "ssid-2795",
// 模拟未开通过会员
Data: map[string]string{
"memberDDL": strconv.FormatInt(0, 10),
},
}
mockSession.EXPECT().Claims().Return(claims)
provider := sessmocks.NewMockProvider(ctrl)
provider.EXPECT().Get(gomock.Any()).Return(mockSession, nil)
return service, provider
},
afterFunc: func(t *testing.T, ctx *ginx.Context) {},
wantCode: 403,
},
{
name: "JWT会员过期-续费",
mock: func(ctrl *gomock.Controller) (member.Service, session.Provider) {
Expand Down
22 changes: 22 additions & 0 deletions internal/project/internal/domain/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Project struct {
Questions []Question
Resumes []Resume
Introductions []Introduction
Combos []Combo

// 目前来说,我们只需要两个 SN,而不是需要维持整个 SPU
// 后续如果需要 SPU 的其他字段,就重构为结构体
Expand Down Expand Up @@ -161,3 +162,24 @@ const (
func (r Role) ToUint8() uint8 {
return uint8(r)
}

// Combo 面试套路,连招
type Combo struct {
Id int64
Title string
Content string
Utime int64
Status ComboStatus
}

type ComboStatus uint8

func (s ComboStatus) ToUint8() uint8 {
return uint8(s)
}

const (
ComboStatusUnknown ComboStatus = iota
ComboStatusUnpublished
ComboStatusPublished
)
Loading

0 comments on commit 9720204

Please sign in to comment.