Skip to content

Commit

Permalink
chore: developer cleanup (hay-kot#300)
Browse files Browse the repository at this point in the history
* new PR tasks

* add homebox to know words

* formatting

* bump deps

* generate db models

* ts errors

* drop id

* fix accessor

* drop unused time field

* change CI

* add expected error

* add type check

* resolve serveral type errors

* hoise in CI
  • Loading branch information
hay-kot authored Feb 18, 2023
1 parent 88f9ff9 commit bd321af
Show file tree
Hide file tree
Showing 142 changed files with 817 additions and 1,200 deletions.
32 changes: 27 additions & 5 deletions .github/workflows/partial-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@ on:
workflow_call:

jobs:
Frontend:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: pnpm/[email protected]
with:
version: 6.0.2

- name: Install dependencies
run: pnpm install --shamefully-hoist
working-directory: frontend

- name: Run Lint
run: pnpm run lint:ci
working-directory: frontend

- name: Run Typecheck
run: pnpm run typecheck
working-directory: frontend

integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -34,9 +60,5 @@ jobs:
run: pnpm install
working-directory: frontend

- name: Run linter 👀
run: pnpm lint
working-directory: "frontend"

- name: Run Integration Tests
run: task test:ci
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"README.md": "LICENSE, SECURITY.md"
},
"cSpell.words": [
"debughandlers"
"debughandlers",
"Homebox"
],
// use ESLint to format code on save
"editor.formatOnSave": false,
Expand Down
19 changes: 19 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ tasks:
cmds:
- cd frontend && pnpm dev

ui:fix:
desc: Runs prettier and eslint on the frontend
cmds:
- cd frontend && pnpm run lint:fix

ui:check:
desc: Runs type checking
cmds:
- cd frontend && pnpm run typecheck

test:ci:
desc: Runs end-to-end test on a live server (only for use in CI)
cmds:
Expand All @@ -116,3 +126,12 @@ tasks:
- sleep 5
- cd frontend && pnpm run test:ci
silent: true

pr:
desc: Runs all tasks required for a PR
cmds:
- task: generate
- task: go:all
- task: ui:check
- task: ui:fix
- task: test:ci
1 change: 0 additions & 1 deletion backend/app/api/handlers/v1/v1_ctrl_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func (ctrl *V1Controller) HandleAssetGet() server.HandlerFunc {
return server.Respond(w, http.StatusBadRequest, "Invalid page size")
}
}


items, err := ctrl.repo.Items.QueryByAssetID(r.Context(), ctx.GID, repo.AssetID(assetId), int(page), int(pageSize))
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions backend/app/api/handlers/v1/v1_ctrl_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc {
loginForm.Password = r.PostFormValue("password")
case server.ContentJSON:
err := server.Decode(r, loginForm)

if err != nil {
log.Err(err).Msg("failed to decode login form")
}
Expand All @@ -72,7 +71,6 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc {
}

newToken, err := ctrl.svc.User.Login(r.Context(), strings.ToLower(loginForm.Username), loginForm.Password)

if err != nil {
return validate.NewRequestError(errors.New("authentication failed"), http.StatusInternalServerError)
}
Expand Down
2 changes: 0 additions & 2 deletions backend/app/api/handlers/v1/v1_ctrl_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
// @Router /v1/items [GET]
// @Security Bearer
func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc {

extractQuery := func(r *http.Request) repo.ItemQuery {
params := r.URL.Query()

Expand Down Expand Up @@ -244,7 +243,6 @@ func (ctrl *V1Controller) HandleGetAllCustomFieldValues() server.HandlerFunc {
// @Security Bearer
func (ctrl *V1Controller) HandleItemsImport() server.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {

err := r.ParseMultipartForm(ctrl.maxUploadSize << 20)
if err != nil {
log.Err(err).Msg("failed to parse multipart form")
Expand Down
1 change: 0 additions & 1 deletion backend/app/api/handlers/v1/v1_ctrl_items_attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (ctrl *V1Controller) HandleItemAttachmentCreate() server.HandlerFunc {
attachment.Type(attachmentType),
file,
)

if err != nil {
log.Err(err).Msg("failed to add attachment")
return validate.NewRequestError(err, http.StatusInternalServerError)
Expand Down
1 change: 0 additions & 1 deletion backend/app/api/handlers/v1/v1_ctrl_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func (ctrl *V1Controller) HandleLocationTreeQuery() server.HandlerFunc {
WithItems: withItems,
},
)

if err != nil {
log.Err(err).Msg("failed to get locations tree")
return validate.NewRequestError(err, http.StatusInternalServerError)
Expand Down
1 change: 0 additions & 1 deletion backend/app/api/handlers/v1/v1_ctrl_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (ctrl *V1Controller) HandleUserSelfUpdate() server.HandlerFunc {

actor := services.UseUserCtx(r.Context())
newData, err := ctrl.svc.User.UpdateSelf(r.Context(), actor.ID, updateData)

if err != nil {
return validate.NewRequestError(err, http.StatusInternalServerError)
}
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func run(cfg *config.Config) error {
// =========================================================================
// Initialize Database & Repos

err := os.MkdirAll(cfg.Storage.Data, 0755)
err := os.MkdirAll(cfg.Storage.Data, 0o755)
if err != nil {
log.Fatal().Err(err).Msg("failed to create data directory")
}
Expand Down
4 changes: 1 addition & 3 deletions backend/app/api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ type tokenHasKey struct {
key string
}

var (
hashedToken = tokenHasKey{key: "hashedToken"}
)
var hashedToken = tokenHasKey{key: "hashedToken"}

type RoleMode int

Expand Down
3 changes: 0 additions & 3 deletions backend/app/api/static/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1722,9 +1722,6 @@ const docTemplate = `{
"textValue": {
"type": "string"
},
"timeValue": {
"type": "string"
},
"type": {
"type": "string"
}
Expand Down
3 changes: 0 additions & 3 deletions backend/app/api/static/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1714,9 +1714,6 @@
"textValue": {
"type": "string"
},
"timeValue": {
"type": "string"
},
"type": {
"type": "string"
}
Expand Down
2 changes: 0 additions & 2 deletions backend/app/api/static/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ definitions:
type: integer
textValue:
type: string
timeValue:
type: string
type:
type: string
type: object
Expand Down
4 changes: 0 additions & 4 deletions backend/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb h1:mbsFtavDqGdYwdDpP50LGOOZ2hgyGoJcZeOpbgKMyu4=
ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU=
entgo.io/ent v0.11.7 h1:V+wKFh0jhAbY/FoU+PPbdMOf2Ma5vh07R/IdF+N/nFg=
entgo.io/ent v0.11.7/go.mod h1:ericBi6Q8l3wBH1wEIDfKxw7rcQEuRPyBfbIzjtxJ18=
entgo.io/ent v0.11.8 h1:M/M0QL1CYCUSdqGRXUrXhFYSDRJPsOOrr+RLEej/gyQ=
entgo.io/ent v0.11.8/go.mod h1:ericBi6Q8l3wBH1wEIDfKxw7rcQEuRPyBfbIzjtxJ18=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
Expand All @@ -11,8 +9,6 @@ github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7l
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/ardanlabs/conf/v3 v3.1.3 h1:16+Nzfc4PBd/ERtYERUFL/75eVKNyW15Y+vn3W1XZzQ=
github.com/ardanlabs/conf/v3 v3.1.3/go.mod h1:bIacyuGeZjkTdtszdbvOcuq49VhHpV3+IPZ2ewOAK4I=
github.com/ardanlabs/conf/v3 v3.1.4 h1:c0jJYbqHJcrR/uYImbGC1q7quH3DYxH49zGCT7WLJH4=
github.com/ardanlabs/conf/v3 v3.1.4/go.mod h1:bIacyuGeZjkTdtszdbvOcuq49VhHpV3+IPZ2ewOAK4I=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ func TestItemService_AddAttachment(t *testing.T) {
bts, err := os.ReadFile(storedPath)
assert.NoError(t, err)
assert.Equal(t, contents, string(bts))

}
3 changes: 0 additions & 3 deletions backend/internal/core/services/service_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func (svc *UserService) UpdateSelf(ctx context.Context, ID uuid.UUID, data repo.
// User Authentication

func (svc *UserService) createSessionToken(ctx context.Context, userId uuid.UUID) (UserAuthTokenDetail, error) {

attachmentToken := hasher.GenerateToken()
attachmentData := repo.UserAuthTokenCreate{
UserID: userId,
Expand Down Expand Up @@ -173,7 +172,6 @@ func (svc *UserService) createSessionToken(ctx context.Context, userId uuid.UUID

func (svc *UserService) Login(ctx context.Context, username, password string) (UserAuthTokenDetail, error) {
usr, err := svc.repos.Users.GetOneEmail(ctx, username)

if err != nil {
// SECURITY: Perform hash to ensure response times are the same
hasher.CheckPasswordHash("not-a-real-password", "not-a-real-password")
Expand All @@ -197,7 +195,6 @@ func (svc *UserService) RenewToken(ctx context.Context, token string) (UserAuthT
hash := hasher.HashToken(token)

dbToken, err := svc.repos.AuthTokens.GetUserFromToken(ctx, hash)

if err != nil {
return UserAuthTokenDetail{}, ErrorInvalidToken
}
Expand Down
6 changes: 0 additions & 6 deletions backend/internal/data/ent/attachment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions backend/internal/data/ent/attachment_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions backend/internal/data/ent/attachment_delete.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 9 additions & 15 deletions backend/internal/data/ent/attachment_query.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 8 additions & 20 deletions backend/internal/data/ent/attachment_update.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions backend/internal/data/ent/authroles.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bd321af

Please sign in to comment.