-
Notifications
You must be signed in to change notification settings - Fork 1
openapiでhandler自動生成 #918
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
base: develop
Are you sure you want to change the base?
openapiでhandler自動生成 #918
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package handler | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/NUTFes/FinanSu/api/generated" | ||
"github.com/NUTFes/FinanSu/api/internals/domain" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// Index | ||
func (h *Handler) GetActivities(c echo.Context) error { | ||
activities, err := h.activityUseCase.GetActivity(c.Request().Context()) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activities) | ||
} | ||
|
||
// Show | ||
func (h *Handler) GetActivitiesId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
activity, err := h.activityUseCase.GetActivityByID(c.Request().Context(), idStr) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activity) | ||
} | ||
|
||
// Create | ||
func (h *Handler) PostActivities(c echo.Context) error { | ||
activities := new(domain.Activity) | ||
if err := c.Bind(activities); err != nil { | ||
fmt.Println("err") | ||
return err | ||
} | ||
latastActivity, err := h.activityUseCase.CreateActivity(c.Request().Context(), strconv.Itoa(int(activities.UserID)), strconv.FormatBool(activities.IsDone), strconv.Itoa(int(activities.SponsorID)), activities.Feature, strconv.Itoa(int(activities.Expense)), activities.Remark, strconv.Itoa(int(activities.Design)), activities.Url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. タイポ |
||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, latastActivity) | ||
} | ||
|
||
// Update | ||
func (h *Handler) PutActivitiesId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
activities := new(domain.Activity) | ||
if err := c.Bind(activities); err != nil { | ||
fmt.Println("err") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これ要らない |
||
return err | ||
} | ||
updatedActivity, err := h.activityUseCase.UpdateActivity(c.Request().Context(), idStr, strconv.Itoa(int(activities.UserID)), strconv.FormatBool(activities.IsDone), strconv.Itoa(int(activities.SponsorID)), activities.Feature, strconv.Itoa(int(activities.Expense)), activities.Remark, strconv.Itoa(int(activities.Design)), activities.Url) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, updatedActivity) | ||
} | ||
|
||
// Destroy | ||
func (h *Handler) DeleteActivitiesId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
err := h.activityUseCase.DestroyActivity(c.Request().Context(), idStr) | ||
if err != nil { | ||
return err | ||
} | ||
return c.String(http.StatusOK, "Destroy Activity") | ||
} | ||
|
||
// For admin view | ||
func (h *Handler) GetActivitiesDetails(c echo.Context) error { | ||
activities, err := h.activityUseCase.GetActivityDetail(c.Request().Context()) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activities) | ||
} | ||
|
||
// 年度で指定されたactivitiesとsponsor,sponsorStyle,userの一覧を取得 | ||
func (h *Handler) GetActivitiesDetailsYear(c echo.Context, year int) error { | ||
yearStr := strconv.Itoa(year) | ||
activities, err := h.activityUseCase.GetActivityDetailsByPeriod(c.Request().Context(), yearStr) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activities) | ||
} | ||
|
||
func (h *Handler) GetActivitiesFilteredDetails(c echo.Context, params generated.GetActivitiesFilteredDetailsParams) error { | ||
isDone := string(*params.IsDone) | ||
sponsorStyleIDs := []string{} | ||
for _, id := range *params.SponsorStyleId { | ||
sponsorStyleIDs = append(sponsorStyleIDs, strconv.Itoa(int(id))) | ||
} | ||
keyword := *params.Keyword | ||
activities, err := h.activityUseCase.GetFilteredActivityDetail(c.Request().Context(), isDone, sponsorStyleIDs, keyword) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activities) | ||
} | ||
|
||
func (h *Handler) GetActivitiesFilteredDetailsYear(c echo.Context, year string, params generated.GetActivitiesFilteredDetailsYearParams) error { | ||
isDone := string(*params.IsDone) | ||
sponsorStyleIDs := []string{} | ||
for _, id := range *params.SponsorStyleId { | ||
sponsorStyleIDs = append(sponsorStyleIDs, strconv.Itoa(int(id))) | ||
} | ||
keyword := *params.Keyword | ||
activities, err := h.activityUseCase.GetFilteredActivityDetailByPeriod(c.Request().Context(), isDone, sponsorStyleIDs, year, keyword) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activities) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/NUTFes/FinanSu/api/internals/domain" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// router.GET(baseURL+"/activity_informations", wrapper.GetActivityInformations) | ||
func (h *Handler) GetActivityInformations(c echo.Context) error { | ||
activityInformations, err := h.activityInformationUseCase.GetActivityInformation(c.Request().Context()) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activityInformations) | ||
} | ||
|
||
// router.POST(baseURL+"/activity_informations", wrapper.PostActivityInformations) | ||
func (h *Handler) PostActivityInformations(c echo.Context) error { | ||
activityInformation := new(domain.ActivityInformation) | ||
if err := c.Bind(activityInformation); err != nil { | ||
return err | ||
} | ||
|
||
latastActivityInformation, err := h.activityInformationUseCase.CreateActivityInformation(c.Request().Context(), | ||
strconv.Itoa(int(activityInformation.ActivityId)), | ||
activityInformation.BucketName, | ||
activityInformation.FileName, | ||
activityInformation.FileType, | ||
strconv.Itoa(int(activityInformation.DesignProgress)), | ||
activityInformation.FileInformation, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, latastActivityInformation) | ||
} | ||
|
||
// router.DELETE(baseURL+"/activity_informations/:id", wrapper.DeleteActivityInformationsId) | ||
func (h *Handler) DeleteActivityInformationsId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
err := h.activityInformationUseCase.DestroyActivityInformation(c.Request().Context(), idStr) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, "Destroy ActivityInformations") | ||
} | ||
|
||
// router.GET(baseURL+"/activity_informations/:id", wrapper.GetActivityInformationsId) | ||
func (h *Handler) GetActivityInformationsId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
activityInformation, err := h.activityInformationUseCase.GetActivityInformationByID(c.Request().Context(), idStr) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activityInformation) | ||
} | ||
|
||
// router.PUT(baseURL+"/activity_informations/:id", wrapper.PutActivityInformationsId) | ||
func (h *Handler) PutActivityInformationsId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
activityInformation := new(domain.ActivityInformation) | ||
if err := c.Bind(activityInformation); err != nil { | ||
return err | ||
} | ||
updatedActivity, err := h.activityInformationUseCase.UpdateActivityInformation(c.Request().Context(), | ||
idStr, | ||
strconv.Itoa(int(activityInformation.ActivityId)), | ||
activityInformation.BucketName, | ||
activityInformation.FileName, | ||
activityInformation.FileType, | ||
strconv.Itoa(int(activityInformation.DesignProgress)), | ||
activityInformation.FileInformation) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, updatedActivity) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/NUTFes/FinanSu/api/internals/domain" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// router.GET(baseURL+"/activity_styles", wrapper.GetActivityStyles) | ||
func (h *Handler) GetActivityStyles(c echo.Context) error { | ||
activityStyles, err := h.activityStyleUseCase.GetActivityStyle(c.Request().Context()) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activityStyles) | ||
} | ||
|
||
// router.POST(baseURL+"/activity_styles", wrapper.PostActivityStyles) | ||
func (h *Handler) PostActivityStyles(c echo.Context) error { | ||
activityStyle := new(domain.ActivityStyle) | ||
if err := c.Bind(activityStyle); err != nil { | ||
return err | ||
} | ||
|
||
latastActivityStyle, err := h.activityStyleUseCase.CreateActivityStyle(c.Request().Context(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. タイポ |
||
strconv.Itoa(int(activityStyle.ActivityID)), | ||
strconv.Itoa(int(activityStyle.SponsoStyleID)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SponsorStyleID |
||
) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, latastActivityStyle) | ||
} | ||
|
||
// router.DELETE(baseURL+"/activity_styles/:id", wrapper.DeleteActivityStylesId) | ||
func (h *Handler) DeleteActivityStylesId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
err := h.activityStyleUseCase.DestroyActivityStyle(c.Request().Context(), idStr) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, "Destroy ActivityStyles") | ||
} | ||
|
||
// router.GET(baseURL+"/activity_styles/:id", wrapper.GetActivityStylesId) | ||
func (h *Handler) GetActivityStylesId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
activityStyle, err := h.activityStyleUseCase.GetActivityStyleByID(c.Request().Context(), idStr) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, activityStyle) | ||
} | ||
|
||
// router.PUT(baseURL+"/activity_styles/:id", wrapper.PutActivityStylesId) | ||
func (h *Handler) PutActivityStylesId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
activityStyle := new(domain.ActivityStyle) | ||
if err := c.Bind(activityStyle); err != nil { | ||
return err | ||
} | ||
|
||
updatedActivityStyle, err := h.activityStyleUseCase.UpdateActivityStyle(c.Request().Context(), idStr, | ||
strconv.Itoa(int(activityStyle.ActivityID)), | ||
strconv.Itoa(int(activityStyle.SponsoStyleID)), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, updatedActivityStyle) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/NUTFes/FinanSu/api/generated" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// router.GET(baseURL+"/bureaus", wrapper.GetBureaus) | ||
func (h *Handler) GetBureaus(c echo.Context) error { | ||
bureaus, err := h.bureauUseCase.GetBureaus(c.Request().Context()) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, bureaus) | ||
} | ||
|
||
// router.POST(baseURL+"/bureaus", wrapper.PostBureaus) | ||
func (h *Handler) PostBureaus(c echo.Context, params generated.PostBureausParams) error { | ||
name := params.Name | ||
latastBureau, err := h.bureauUseCase.CreateBureau(c.Request().Context(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. latestBureau |
||
name, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, latastBureau) | ||
} | ||
|
||
// router.DELETE(baseURL+"/bureaus/:id", wrapper.DeleteBureausId) | ||
func (h *Handler) DeleteBureausId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
err := h.bureauUseCase.DestroyBureau(c.Request().Context(), idStr) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, "Destroy Bureau") | ||
} | ||
|
||
// router.GET(baseURL+"/bureaus/:id", wrapper.GetBureausId) | ||
func (h *Handler) GetBureausId(c echo.Context, id int) error { | ||
idStr := strconv.Itoa(id) | ||
bureau, err := h.bureauUseCase.GetBureauByID(c.Request().Context(), idStr) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, bureau) | ||
} | ||
|
||
// router.PUT(baseURL+"/bureaus/:id", wrapper.PutBureausId) | ||
func (h *Handler) PutBureausId(c echo.Context, id int, params generated.PutBureausIdParams) error { | ||
idStr := strconv.Itoa(id) | ||
name := *params.Name | ||
updatedBureau, err := h.bureauUseCase.UpdateBureau(c.Request().Context(), idStr, name) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, updatedBureau) | ||
} |
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.
これいらない。