Skip to content

Commit

Permalink
Get community works
Browse files Browse the repository at this point in the history
  • Loading branch information
OmegaTymbJIep committed Jun 29, 2024
1 parent e692513 commit f5ae210
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/service/api/handlers/get_community.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ func GetCommunity(w http.ResponseWriter, r *http.Request) {
return
}

communitiesList, err := Core(r).GetCommunitiesList()
if err != nil {
community, err := Core(r).GetCommunityById(req.CommunityID)
switch {
case community == nil:
ape.RenderErr(w, problems.NotFound())
Log(r).WithError(err).
Debug("Community not found")
return
case err != nil:
Log(r).WithError(err).
Error("Failed get community")
Error("Failed tp get community")
ape.RenderErr(w, problems.InternalError())
return
}

ape.Render(w, responses.NewCommunitiesList(communitiesList))
ape.Render(w, responses.NewGetCommunity(community))
}
14 changes: 14 additions & 0 deletions internal/service/core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ func (c *Core) GetCommunitiesList() ([]data.Community, error) {
return communities, nil
}

func (c *Core) GetCommunityById(communityId uuid.UUID) (*data.Community, error) {
community, err := c.db.New().CommunitiesQ().WhereID(communityId).Get()
if err != nil {
c.log.WithError(err).Error("Failed to get community by ID")
return nil, err
}

if community == nil {
return nil, nil
}

return community, nil
}

func (c *Core) CreateCommunity(
collectionName string,
collectionSymbol string,
Expand Down

0 comments on commit f5ae210

Please sign in to comment.