-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code-shooting init
- Loading branch information
Showing
569 changed files
with
60,800 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# CodeShooting | ||
|
||
代码打靶是一项高效的代码能力提升活动,可以带动打靶人员 Code Review 能力和编码能力的腾飞。代码打靶主要包括规范、内容和工具,规范实例化是代码缺陷规范,内容实例化是靶子和靶场,工具实例化是打靶服务。 | ||
|
||
经过一年多的探索,代码打靶已在中兴通讯多个研究院规模化推广了起来,获得了软件开发人员的一致认可,成为了公司编码文化建设的引擎。CodeShooting 是中兴通讯开源的一款打靶服务,可以让代码打靶活动自动化。打靶人员通过 Web 进行打靶,通过个人看板获得快速反馈,既可以明显感知近期的进步,又可以轻松拿到针对弱项的学习资料,从而进入了高效的正反馈循环。 | ||
|
||
|
||
## Features | ||
|
||
- 靶场打靶 | ||
- 自由练习打靶 | ||
- DSL打靶 | ||
- 文档打靶 | ||
- 阅卷 | ||
- 打靶结果查看 | ||
- 靶场管理 | ||
- 靶子管理 | ||
- 规范管理 | ||
- 个人中心 | ||
- 组织看板 | ||
- 个人看板 | ||
- 用户管理 | ||
- 分权分域 | ||
- 备份恢复 | ||
- 靶标建设(to do) | ||
- 日常评审(to do) | ||
- 智能学习(to do) | ||
|
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,2 @@ | ||
data/ | ||
.vscode/ |
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,23 @@ | ||
COM := codeshooting | ||
|
||
.PHONY: clean | ||
clean: | ||
@rm -rf bin | ||
@echo Clean done! | ||
|
||
.PHONY: build | ||
build: BUILD_ENTRY = main.go | ||
build: clean | ||
@rm -rf bin | ||
@echo Building... | ||
@mkdir -p bin/app | ||
@GOOS=linux GOARCH=$(ARCH) CGO_ENABLED=0 go build -o=bin/app/$(COM) -ldflags '-w -s' $(BUILD_ENTRY) | ||
@echo Build done! | ||
|
||
.PHONY: docker-build | ||
docker-build: build | ||
@cp docker/Dockerfile bin \ | ||
&& cp docker/entrypoint.sh bin/app \ | ||
&& cp -r conf bin/app \ | ||
&& cd bin && chmod -R 755 app \ | ||
&& DOCKER_BUILDKIT=1 docker build -t $(COM)-backend:$(VERSION) . |
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 @@ | ||
package assembler |
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,33 @@ | ||
package privilegeapp | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"code-shooting/infra/logger" | ||
|
||
"code-shooting/domain/privilege" | ||
"code-shooting/infra/privilegecfg" | ||
"code-shooting/infra/repository" | ||
) | ||
|
||
func LoadPrivilegeCfg(privilegeBasePath string) error { | ||
var privilegesFilePath = filepath.Join(privilegeBasePath, "privileges.json") | ||
var rolePrivilegeMapFilePath = filepath.Join(privilegeBasePath, "role-privilege-map.json") | ||
var userRoleMapFilePath = filepath.Join(privilegeBasePath, "user-role-map.json") | ||
res := privilege.LoadPrivileges( | ||
privilegesFilePath, rolePrivilegeMapFilePath, userRoleMapFilePath, | ||
privilegecfg.PrivilegeCfgParse(privilegecfg.PrivilegeCfgParseRead), | ||
privilegecfg.RolePrivilegeCfgParse(privilegecfg.RolePrivilegeCfgParseRead), | ||
privilegecfg.StaffRoleCfgParse(privilegecfg.StaffRoleCfgParseRead), | ||
repository.PivilegeRoleRepo, | ||
repository.PivilegeStaffRepo, | ||
) | ||
logger.Infof("====LoadPrivilegeCfg %v", res) | ||
return res | ||
} | ||
|
||
func GetStaffPrivileges(id string) []string { | ||
return privilege.GetStaffPrivileges(id, | ||
repository.PivilegeRoleRepo, | ||
repository.PivilegeStaffRepo) | ||
} |
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,108 @@ | ||
package ecsvc | ||
|
||
import ( | ||
"encoding/csv" | ||
"io" | ||
"reflect" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"code-shooting/domain/entity/ec" | ||
"code-shooting/domain/entity/spec" | ||
ecsvc "code-shooting/domain/service/ec" | ||
"code-shooting/infra/errcode" | ||
"code-shooting/interface/dto" | ||
) | ||
|
||
type ECService struct { | ||
} | ||
|
||
func GetECService() *ECService { | ||
return &ECService{} | ||
} | ||
|
||
type ECImportInfo struct { | ||
Institute string `json:"institute"` | ||
Center string `json:"center"` | ||
UserId string `json:"userId"` | ||
} | ||
|
||
func (s *ECService) ImportFromCsv(ei *ECImportInfo, cr *csv.Reader) error { | ||
if err := s.readTitle(cr); err != nil { | ||
return err | ||
} | ||
return s.readRecords(ei, cr) | ||
} | ||
|
||
func (s *ECService) readTitle(cr *csv.Reader) error { | ||
title, err := cr.Read() | ||
if err != nil { | ||
return err | ||
} | ||
if !reflect.DeepEqual(title, []string{"EC号", "部门", "团队"}) { | ||
return errors.WithMessage(errcode.ErrParamError, "invalid ec records title") | ||
} | ||
return nil | ||
} | ||
|
||
func (s *ECService) readRecords(ei *ECImportInfo, cr *csv.Reader) error { | ||
for { | ||
record, err := cr.Read() | ||
if err != nil { | ||
if err == io.EOF { | ||
break | ||
} | ||
return errors.WithMessagef(errcode.ErrParamError, "invalid ec record: %v", err) | ||
} | ||
if err := s.importEC(ei, record); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (s *ECService) importEC(ei *ECImportInfo, record []string) error { | ||
return ecsvc.GetECService().AddEC(ec.NewEC(record[0], ec.Organization{ | ||
Institute: ei.Institute, | ||
Center: ei.Center, | ||
Department: record[1], | ||
Team: record[2], | ||
}, ei.UserId)) | ||
} | ||
|
||
type TimeFilter struct { | ||
SinceTime time.Time | ||
UntilTime time.Time | ||
} | ||
|
||
func (s *ECService) QueryECs(org *ec.Organization, tr *TimeFilter) ([]dto.EC, error) { | ||
as := spec.NewAndSpec(spec.Institute.Equal(org.Institute), spec.Center.Equal(org.Center)) | ||
as.AddIf(org.Department != "", spec.Department.Equal(org.Department)) | ||
as.AddIf(org.Team != "", spec.Department.Equal(org.Team)) | ||
as.AddIf(!tr.SinceTime.IsZero(), spec.ImportTime.Since(tr.SinceTime)) | ||
as.AddIf(!tr.UntilTime.IsZero(), spec.ImportTime.Until(tr.UntilTime)) | ||
ecs, err := ec.GetECRepo().Find(as) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.toDto(ecs), nil | ||
} | ||
|
||
func (s *ECService) toDto(ecs []*ec.EC) []dto.EC { | ||
decs := make([]dto.EC, 0, len(ecs)) | ||
for _, e := range ecs { | ||
decs = append(decs, dto.EC{ | ||
Id: e.Id, | ||
Organization: e.Organization, | ||
Importer: e.Importer, | ||
ImportTime: e.ImportTime.Format(time.RFC3339), | ||
ConvertedToTarget: e.ConvertedToTarget, | ||
}) | ||
} | ||
return decs | ||
} | ||
|
||
func (s *ECService) DeleteEC(id, userId string) error { | ||
return ec.GetECRepo().Remove(id, userId) | ||
} |
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,104 @@ | ||
package userservice | ||
|
||
import ( | ||
"code-shooting/app/privilegeapp" | ||
"code-shooting/domain/entity" | ||
"code-shooting/domain/service/user" | ||
"code-shooting/infra/common" | ||
"code-shooting/infra/errcode" | ||
"code-shooting/infra/handler" | ||
"code-shooting/interface/dto" | ||
"fmt" | ||
) | ||
|
||
type GetInfo struct { | ||
} | ||
|
||
func NewGetInfoService() *GetInfo { | ||
return &GetInfo{} | ||
} | ||
func (g *GetInfo) GetUserInfoAndUpdate(request *entity.UserEntity) *common.Response { | ||
userInfo, err := user.NewUserDomainService().QueryUser(request) | ||
if err != nil { | ||
if errcode.SameCause(err, errcode.ErrRecordNotFound) { | ||
return hanldUser(request, "", func(userE *entity.UserEntity) error { | ||
return user.NewUserDomainService().AddUser(userE) | ||
}) | ||
} | ||
return handler.Failure(err.Error()) | ||
} else { | ||
userInfo.Id = request.Id | ||
updateUserWhenDiffProj(userInfo, userInfo.Department) | ||
} | ||
userInfo.Privileges = privilegeapp.GetStaffPrivileges(request.Id) | ||
return handler.SuccessGet(userInfo) | ||
} | ||
|
||
func (g *GetInfo) GetPerson(id string) (*dto.Person, error) { | ||
res := g.GetUserInfo(&entity.UserEntity{Id: id}) | ||
if res.Result == handler.SUCCESS { | ||
user := ((*res).Detail).(*entity.UserEntity) | ||
personObj := dto.NewPerson(user) | ||
return &personObj, nil | ||
} | ||
return nil, fmt.Errorf("%s cant find user", id) | ||
} | ||
|
||
func (g *GetInfo) RefreshPersonMessage(id string) (*dto.Person, error) { | ||
userInfo, err := g.GetPerson(id) | ||
if err != nil { | ||
return nil, fmt.Errorf("%s cant find user", id) | ||
} | ||
res, err := getStaffFieldMessage(id) | ||
if err != nil { | ||
return nil, fmt.Errorf("%s cant find user", id) | ||
} | ||
userInfo.TeamName = res.TeamName | ||
userInfo.Department = res.Department | ||
userInfo.CenterName = res.CenterName | ||
userInfo.Institute = res.Institute | ||
return userInfo, nil | ||
} | ||
|
||
func (g *GetInfo) GetUserInfo(request *entity.UserEntity) *common.Response { | ||
userInfo, err := user.NewUserDomainService().QueryUser(request) | ||
if err != nil { | ||
if errcode.SameCause(err, errcode.ErrRecordNotFound) { | ||
return hanldUser(request, "", func(userE *entity.UserEntity) error { | ||
return user.NewUserDomainService().AddUser(userE) | ||
}) | ||
} | ||
return handler.Failure(err.Error()) | ||
} | ||
userInfo.Privileges = privilegeapp.GetStaffPrivileges(request.Id) | ||
return handler.SuccessGet(userInfo) | ||
} | ||
func updateUserWhenDiffProj(oldU *entity.UserEntity, projName string) { | ||
hanldUser(oldU, projName, func(userE *entity.UserEntity) error { | ||
return user.NewUserDomainService().ModifyUser(userE) | ||
}) | ||
} | ||
|
||
type hanlduserInDb func(user *entity.UserEntity) error | ||
|
||
func hanldUser(userInfo *entity.UserEntity, projName string, hanld hanlduserInDb) *common.Response { | ||
if len(projName) == 0 { | ||
var err error | ||
userInfo, err = getStaffFieldMessage(userInfo.Id) | ||
if err != nil { | ||
return handler.Failure(err.Error()) | ||
} | ||
err1 := hanld(userInfo) | ||
if err1 != nil { | ||
return handler.Failure(err1.Error()) | ||
} | ||
} | ||
userInfo.Privileges = privilegeapp.GetStaffPrivileges(userInfo.Id) | ||
return handler.SuccessCreated(userInfo) | ||
} | ||
|
||
func getStaffFieldMessage(id string) (*entity.UserEntity, error) { | ||
var person entity.UserEntity | ||
|
||
return &person, nil | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/app/service/login/verify-app/verify_app_service.go
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,20 @@ | ||
package verifyservice | ||
|
||
import ( | ||
"code-shooting/domain/entity" | ||
"code-shooting/infra/common" | ||
"code-shooting/infra/errcode" | ||
"code-shooting/infra/handler" | ||
) | ||
|
||
type VerifySrv struct { | ||
} | ||
|
||
func NewVerifyService() *VerifySrv { | ||
return &VerifySrv{} | ||
} | ||
|
||
func (v *VerifySrv) VerifyUser(codeEntity *entity.QrCodeEntity) *common.Response { | ||
|
||
return handler.FailureNotFound(errcode.ErrRecordNotFound.Error()) | ||
} |
Oops, something went wrong.