-
Notifications
You must be signed in to change notification settings - Fork 88
Budget endpoint #398
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
Merged
+704
−65
Merged
Budget endpoint #398
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
08b4a91
Remove notes from schema
TyHil 964f63a
Add Budget route
TyHil 7d10cde
Merge branch 'budget-parse' of https://github.com/UTDNebula/nebula-ap…
TyHil 295889d
Merge branch 'develop' into budget-parse
mikehquan19 c50d7fc
Merge branch 'develop' into budget-parse
mikehquan19 d4a578e
404 on no budget found
TyHil ef23eae
Add route to server
TyHil 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package controllers | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
|
|
||
| "go.mongodb.org/mongo-driver/bson" | ||
| "go.mongodb.org/mongo-driver/mongo" | ||
|
|
||
| "github.com/UTDNebula/nebula-api/api/configs" | ||
|
|
||
| "github.com/UTDNebula/nebula-api/api/schema" | ||
| ) | ||
|
|
||
| var budgetCollection *mongo.Collection = configs.GetCollection("budgets") | ||
|
|
||
| // @Id Budget | ||
| // @Router /budget/{year} [get] | ||
| // @Tags Other | ||
| // @Description "Returns discal year Budget based on the input year" | ||
| // @Produce json | ||
| // @Param year path string true "year to retrieve budget for" | ||
| // @Success 200 {object} schema.APIResponse[schema.Budget] "Single budget from the given fiscal year" | ||
| // @Failure 500 {object} schema.APIResponse[string] "A string describing the error" | ||
| func Budget(c *gin.Context) { | ||
| ctx, cancel := context.WithTimeout(c.Request.Context(), 10*time.Second) | ||
| defer cancel() | ||
|
|
||
| year := c.Param("year") | ||
|
|
||
| var budget schema.Budget | ||
|
|
||
| // Find budget given date | ||
| err := budgetCollection.FindOne(ctx, bson.M{"_id": year}).Decode(&budget) | ||
| if err != nil { | ||
| if errors.Is(err, mongo.ErrNoDocuments) { | ||
| budget.Id = year | ||
| budget.OperatingBudget = &schema.OperatingBudget{} | ||
| budget.AnnualFinancialReport = &schema.AnnualFinancialReport{} | ||
| } else { | ||
| respondWithInternalError(c, err) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| respond(c, http.StatusOK, "success", budget) | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.