-
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.
- Loading branch information
1 parent
b5a28a6
commit fb4e091
Showing
7 changed files
with
110 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"gitlab.com/distributed_lab/ape" | ||
"gitlab.com/distributed_lab/ape/problems" | ||
|
||
"github.com/black-pepper-team/community-indexer/internal/service/api/requests" | ||
"github.com/black-pepper-team/community-indexer/internal/service/api/responses" | ||
) | ||
|
||
func GetRegisterStatus(w http.ResponseWriter, r *http.Request) { | ||
req, err := requests.NewGetRegister(r) | ||
if err != nil { | ||
Log(r).WithField("reason", err).Debug("Bad request") | ||
ape.RenderErr(w, problems.BadRequest(err)...) | ||
return | ||
} | ||
|
||
registryRecord, err := Core(r).GetRegister(req.RegisterID) | ||
switch { | ||
case registryRecord == nil: | ||
ape.RenderErr(w, problems.NotFound()) | ||
Log(r).WithError(err). | ||
Debug("Community not found") | ||
return | ||
case err != nil: | ||
Log(r).WithError(err). | ||
Error("Failed to get register status") | ||
ape.RenderErr(w, problems.InternalError()) | ||
return | ||
} | ||
|
||
ape.Render(w, responses.NewGetRegisterStatus(registryRecord)) | ||
} |
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,48 @@ | ||
package requests | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/go-chi/chi" | ||
validation "github.com/go-ozzo/ozzo-validation/v4" | ||
"github.com/google/uuid" | ||
) | ||
|
||
const ( | ||
registerIdPathParam = "register-id" | ||
) | ||
|
||
type getRegisterRequest struct { | ||
RegisterID string | ||
} | ||
|
||
type GetRegisterRequest struct { | ||
RegisterID uuid.UUID | ||
} | ||
|
||
func NewGetRegister(r *http.Request) (*GetRegisterRequest, error) { | ||
requestRaw := getRegisterRequest{ | ||
RegisterID: chi.URLParam(r, registerIdPathParam), | ||
} | ||
|
||
if err := requestRaw.validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return requestRaw.parse(), nil | ||
} | ||
|
||
// nolint | ||
func (r *getRegisterRequest) validate() error { | ||
return validation.Errors{ | ||
"path/{register-id}": validation.Validate( | ||
r.RegisterID, validation.Required, validation.By(MustBeValidUUID), | ||
), | ||
}.Filter() | ||
} | ||
|
||
func (r *getRegisterRequest) parse() *GetRegisterRequest { | ||
return &GetRegisterRequest{ | ||
RegisterID: uuid.MustParse(r.RegisterID), | ||
} | ||
} |
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,10 @@ | ||
package responses | ||
|
||
import "github.com/black-pepper-team/community-indexer/internal/service/core" | ||
|
||
func NewGetRegisterStatus(registerRequest *core.RegisterRequest) *RegisterRequest { | ||
return &RegisterRequest{ | ||
Id: registerRequest.Id, | ||
Status: string(registerRequest.Status), | ||
} | ||
} |
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
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