Skip to content

Commit

Permalink
refactor(json-handlers): reduce code duplication
Browse files Browse the repository at this point in the history
- use functions for json marshalling, request validation and errors
- this should reduce duplication and make it easier to offer multiple
  response types (e.g. html or json) in the future
  • Loading branch information
hpr1999 committed Aug 8, 2024
1 parent cecf578 commit 8635e26
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 334 deletions.
16 changes: 16 additions & 0 deletions data_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,27 @@ func (p *passwordRegistrationRequest) Validate() error {
return validatePassword(p.Password)
}

func (p *passwordLoginRequest) Validate() error {
return nil
}

type passwordLoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}

func (p *noneLoginRequest) Validate() error {
return nil
}

type noneLoginRequest struct {
Username string `json:"username"`
}

func (p *nfcLoginRequest) Validate() error {
return nil
}

type nfcLoginRequest struct {
Token string `json:"token"`
}
Expand Down Expand Up @@ -144,6 +156,10 @@ func (r *addAuthMethodRequest) Validate() error {
return errors.New("invalid method")
}

func (r *changeCreditRequest) Validate() error {
return nil
}

type changeCreditRequest struct {
Diff int `json:"diff"`
}
Expand Down
Loading

0 comments on commit 8635e26

Please sign in to comment.