-
Notifications
You must be signed in to change notification settings - Fork 1
managers: added managers entity && chore #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bogdanserdinov
wants to merge
15
commits into
develop
Choose a base branch
from
bs/managers-for-clubs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
11d9e44
added manager entity + db + endpoint
bogdanserdinov 25bdec1
deleted output avatars
bogdanserdinov 33b4655
bugs fixed
bogdanserdinov d6f5c87
comment deleted
bogdanserdinov 715c905
linter remarks fixed
bogdanserdinov 5b4c047
conflicts resolved
bogdanserdinov 8e6be5f
list by user id refactored
bogdanserdinov 4baec94
file goimported
bogdanserdinov 245c498
chore fixed, added blocker to add/delete squad card
bogdanserdinov e48dc3f
added close chore method + output images deleted
bogdanserdinov 51213b1
linter remarks fixed
bogdanserdinov f0b6105
ownership statuses fixed
bogdanserdinov 9d3bf35
conflicts resolved
bogdanserdinov c08167b
added block to add card for owner
bogdanserdinov 8838ab4
deleted user id input from html template
bogdanserdinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,80 @@ | ||
| // Copyright (C) 2021 Creditor Corp. Group. | ||
| // See LICENSE for copying information. | ||
|
|
||
| package controllers | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/http" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/gorilla/mux" | ||
| "github.com/zeebo/errs" | ||
|
|
||
| "ultimatedivision/internal/logger" | ||
| "ultimatedivision/managers" | ||
| ) | ||
|
|
||
| var ( | ||
| // ErrManagers is an internal error type for managers controller. | ||
| ErrManagers = errs.Class("managers controller error") | ||
| ) | ||
|
|
||
| // Managers is a mvc controller that handles all managers related views. | ||
| type Managers struct { | ||
| log logger.Logger | ||
|
|
||
| managers *managers.Service | ||
| } | ||
|
|
||
| // NewManagers is a constructor for managers controller. | ||
| func NewManagers(log logger.Logger, managers *managers.Service) *Managers { | ||
| managersController := &Managers{ | ||
| log: log, | ||
| managers: managers, | ||
| } | ||
|
|
||
| return managersController | ||
| } | ||
|
|
||
| // Create is ann endpoint that creates manager for club. | ||
| func (controller *Managers) Create(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("Content-Type", "application/json") | ||
| ctx := r.Context() | ||
| params := mux.Vars(r) | ||
|
|
||
| clubID, err := uuid.Parse(params["clubId"]) | ||
| if err != nil { | ||
| controller.serveError(w, http.StatusBadRequest, ErrManagers.Wrap(err)) | ||
| return | ||
| } | ||
|
|
||
| var manager managers.Manager | ||
|
|
||
| if err = json.NewDecoder(r.Body).Decode(&manager); err != nil { | ||
| controller.serveError(w, http.StatusBadRequest, ErrManagers.Wrap(err)) | ||
| return | ||
| } | ||
|
|
||
| err = controller.managers.Create(ctx, manager.EndedAt, manager.UserID, clubID) | ||
| if err != nil { | ||
| controller.log.Error("could not create manager", ErrManagers.Wrap(err)) | ||
| controller.serveError(w, http.StatusInternalServerError, ErrManagers.Wrap(err)) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // serveError replies to the request with specific code and error message. | ||
| func (controller *Managers) serveError(w http.ResponseWriter, status int, err error) { | ||
| w.WriteHeader(status) | ||
|
|
||
| var response struct { | ||
| Error string `json:"error"` | ||
| } | ||
|
|
||
| response.Error = err.Error() | ||
|
|
||
| if err = json.NewEncoder(w).Encode(response); err != nil { | ||
| controller.log.Error("failed to write json error response", ErrManagers.Wrap(err)) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe one db method needs to be done for this?