Skip to content

Commit

Permalink
Merge pull request #27 from STUD-IT-team/clearance_club
Browse files Browse the repository at this point in the history
Clearance club
  • Loading branch information
pai0id authored Sep 6, 2024
2 parents ad2729a + bf1c888 commit f73c26a
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 3 deletions.
75 changes: 75 additions & 0 deletions internal/app/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,78 @@ func (s *ClubService) GetClearancePost(ctx context.Context, resp *responses.Chec
}
return &responses.GetClearance{Access: false, Comment: "only admins"}, nil
}

func (s *ClubService) GetClearanceUpdate(ctx context.Context, req *responses.CheckResponse, clubID int) (*responses.GetClearance, error) {
if req.IsAdmin {
return &responses.GetClearance{Access: true, Comment: ""}, nil
} else {
clubOrgs, err := s.storage.GetClubOrgs(ctx, clubID)
if err != nil {
return &responses.GetClearance{Access: false, Comment: "error"}, fmt.Errorf("can't storage.GetClubOrgs: %w", err)
}
for _, org := range clubOrgs {
if org.ID == req.MemberID {
return &responses.GetClearance{Access: true, Comment: ""}, nil
}
}
}
return &responses.GetClearance{Access: false, Comment: "only admins or club orgs"}, nil
}

func (s *ClubService) GetClearanceDelete(ctx context.Context, resp *responses.CheckResponse) (*responses.GetClearance, error) {
if resp.IsAdmin {
return &responses.GetClearance{Access: true, Comment: ""}, nil
}
return &responses.GetClearance{Access: false, Comment: "only admins"}, nil
}

func (s *ClubService) GetClearanceMediaPost(ctx context.Context, req *responses.CheckResponse, clubID int) (*responses.GetClearance, error) {
if req.IsAdmin {
return &responses.GetClearance{Access: true, Comment: ""}, nil
} else {
clubOrgs, err := s.storage.GetClubOrgs(ctx, clubID)
if err != nil {
return &responses.GetClearance{Access: false, Comment: "error"}, fmt.Errorf("can't storage.GetClubOrgs: %w", err)
}
for _, org := range clubOrgs {
if org.ID == req.MemberID {
return &responses.GetClearance{Access: true, Comment: ""}, nil
}
}
}
return &responses.GetClearance{Access: false, Comment: "only admins or club orgs"}, nil
}

func (s *ClubService) GetClearanceMediaUpdate(ctx context.Context, req *responses.CheckResponse, clubID int) (*responses.GetClearance, error) {
if req.IsAdmin {
return &responses.GetClearance{Access: true, Comment: ""}, nil
} else {
clubOrgs, err := s.storage.GetClubOrgs(ctx, clubID)
if err != nil {
return &responses.GetClearance{Access: false, Comment: "error"}, fmt.Errorf("can't storage.GetClubOrgs: %w", err)
}
for _, org := range clubOrgs {
if org.ID == req.MemberID {
return &responses.GetClearance{Access: true, Comment: ""}, nil
}
}
}
return &responses.GetClearance{Access: false, Comment: "only admins or club orgs"}, nil
}

func (s *ClubService) GetClearanceMediaDelete(ctx context.Context, req *responses.CheckResponse, clubID int) (*responses.GetClearance, error) {
if req.IsAdmin {
return &responses.GetClearance{Access: true, Comment: ""}, nil
} else {
clubOrgs, err := s.storage.GetClubOrgs(ctx, clubID)
if err != nil {
return &responses.GetClearance{Access: false, Comment: "error"}, fmt.Errorf("can't storage.GetClubOrgs: %w", err)
}
for _, org := range clubOrgs {
if org.ID == req.MemberID {
return &responses.GetClearance{Access: true, Comment: ""}, nil
}
}
}
return &responses.GetClearance{Access: false, Comment: "only admins or club orgs"}, nil
}
28 changes: 28 additions & 0 deletions internal/domain/requests/get-clearance-club-update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package requests

import (
"fmt"
"net/http"
"strconv"

"github.com/go-chi/chi"
)

type GetClearanceClubUpdate struct {
ClubID int `json:"club_id"`
}

func (p *GetClearanceClubUpdate) Bind(req *http.Request) error {
id, err := strconv.Atoi(chi.URLParam(req, "club_id"))
if err != nil {
return fmt.Errorf("can't Atoi id on DeleteMember.Bind: %w", err)
}

p.ClubID = id

return p.validate()
}

func (p *GetClearanceClubUpdate) validate() error {
return nil
}
Loading

0 comments on commit f73c26a

Please sign in to comment.