Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some bugs in renew router and test code #3

Merged
merged 4 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ endif
all: build

build:
@echo "Building MaintianMan ..."
@echo "Building MaintainMan ..."
@$(GO) env -w CGO_ENABLED="1"
@$(GO) build \
-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
-o $(TARGET) $(PWD)/main.go

test:
@echo "Testing MaintianMan ..."
@echo "Testing MaintainMan ..."
@$(GO) env -w CGO_ENABLED="1"
@$(GO) test \
-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
Expand Down
11 changes: 9 additions & 2 deletions controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"maintainman/model"
"maintainman/service"
"maintainman/util"
"time"

"github.com/kataras/iris/v12"
)
Expand Down Expand Up @@ -143,8 +144,8 @@ func WxUserLogin(ctx iris.Context) {
// @Failure 500 {object} model.ApiJson{data=[]string}
// @Router /v1/renew [post]
func UserRenew(ctx iris.Context) {
id := ctx.Values().GetUintDefault("user_id", 0)
auth := util.NilOrPtrCast[model.AuthInfo](ctx.Values().Get("auth"))
id := util.NilOrBaseValue(auth, func(v *model.AuthInfo) uint { return v.User }, 0)
response := service.UserRenew(id, ctx.Request().RemoteAddr, auth)
ctx.Values().Set("response", response)
}
Expand All @@ -170,7 +171,13 @@ func UserRegister(ctx iris.Context) {
ctx.Values().Set("response", model.ErrorInvalidData(err))
return
}
auth := util.NilOrPtrCast[model.AuthInfo](ctx.Values().Get("auth"))
//auth := util.NilOrPtrCast[model.AuthInfo](ctx.Values().Get("auth"))
//TODO:修改判断空指针逻辑
auth := &model.AuthInfo{
IP: ctx.Request().RemoteAddr,
User: uint(time.Now().Unix()),
}

response := service.RegisterUser(aul, auth)
ctx.Values().Set("response", response)
}
Expand Down
1 change: 0 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestRegisterAndLoginRouter(t *testing.T) {
}
}

//FIXME: record not found [0.334ms] [rows:0] SELECT * FROM `users` WHERE `users`.`id` = 0 AND `users`.`deleted_at` IS NULL ORDER BY `users`.`id` LIMIT 1
func TestUserReNewRouter(t *testing.T) {
app := newApp()
e := httptest.New(t, app)
Expand Down