Skip to content

Commit

Permalink
Merge pull request #660 from NUTFes/feat/kubosaka/652-years-update
Browse files Browse the repository at this point in the history
購入申請の年度更新
  • Loading branch information
Kubosaka authored Dec 10, 2023
2 parents 73a513c + 347d605 commit 7307a06
Show file tree
Hide file tree
Showing 24 changed files with 1,146 additions and 36 deletions.
116 changes: 116 additions & 0 deletions api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,26 @@ const docTemplate = `{
}
},
},
"/purchaseorders/details/{year}": {
"get": {
tags: ["purchase_order"],
"description": "年度で指定されたpurchase_orderに紐づくuserとpurchase_itemを取得",
"parameters": [
{
"name": "year",
"in": "path",
"description": "year",
"required": true,
"type": "integer"
}
],
"responses": {
"200": {
"description": "IDで指定されたpurchase_orderに紐づくuserとpurchase_itemを取得",
}
}
},
},
"/purchasereports": {
"get": {
tags: ["purchase_report"],
Expand Down Expand Up @@ -1991,6 +2011,80 @@ const docTemplate = `{
},
},
},
"/years/periods": {
"get": {
tags: ["year_periods"],
"description": "年度一覧の取得",
"responses": {
"200": {
"description": "year_periodsの一覧を取得",
}
}
},
"post": {
tags: ["year_periods"],
"description": "year_periodsの作成",
responses: {
"200": {
"description": "作成されたyear_periodsが返ってくる",
}
},
"parameters": [
{
"in": "body",
"name": "year_periods",
"schema":{
"$ref": "#/definitions/year_periods"
},
},
],
},
},
"/years/periods/{id}": {
"put": {
tags: ["year_periods"],
"description": "year_periodsの更新",
responses: {
"200": {
"description": "更新されたyear_periodsが返ってくる",
}
},
"parameters": [
{
"name": "id",
"in": "path",
"description": "id",
"required": true,
"type": "integer"
},
{
"in": "body",
"name": "year_periods",
"schema":{
"$ref": "#/definitions/year_periods"
},
},
],
},
"delete": {
tags: ["year_periods"],
"description": "IDを指定してyear_periodsの削除",
"parameters": [
{
"name": "id",
"in": "path",
"description": "id",
"required": true,
"type": "integer"
}
],
responses: {
"200": {
"description": "year_periodsの削除完了",
},
},
},
},
},
"definitions":{
"activity":{
Expand Down Expand Up @@ -2150,6 +2244,28 @@ const docTemplate = `{
"purchaseOrderID"
},
},
"year_periods":{
"properties":{
"year":{
"type": "int",
"example": 2024,
},
"startedAt":{
"type": "string",
"example": "0000-00-00T00:00:00Z",
},
"endedAt":{
"type": "string",
"example": "0000-00-00T00:00:00Z",
},
},
"required":{
"year",
"startedAt",
"endedAt"
},
},
},
}`

Expand Down
10 changes: 10 additions & 0 deletions api/externals/controller/purhcase_order_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type PurchaseOrderController interface {
DestroyPurchaseOrder(echo.Context) error
IndexOrderDetail(echo.Context) error
ShowOrderDetail(echo.Context) error
IndexOrderDetailByYear(echo.Context) error
}

func NewPurchaseOrderController(u usecase.PurchaseOrderUseCase) PurchaseOrderController {
Expand Down Expand Up @@ -99,3 +100,12 @@ func (p *purchaseOrderController) ShowOrderDetail(c echo.Context) error {
}
return c.JSON(http.StatusOK, orderDetail)
}

func (p *purchaseOrderController) IndexOrderDetailByYear(c echo.Context) error {
year := c.Param("year")
orderDetails, err := p.u.GetPurchaseOrderDetailsByYear(c.Request().Context(), year)
if err != nil {
return err
}
return c.JSON(http.StatusOK, orderDetails)
}
57 changes: 56 additions & 1 deletion api/externals/controller/year_controller.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package controller

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

"github.com/NUTFes/FinanSu/api/internals/domain"
"github.com/NUTFes/FinanSu/api/internals/usecase"
"github.com/labstack/echo/v4"
"net/http"
)

type yearController struct {
u usecase.YearUseCase
}

const Layout = "2006-01-02 15:04:05"

type YearController interface {
IndexYear(echo.Context) error
ShowYear(echo.Context) error
CreateYear(echo.Context) error
UpdateYear(echo.Context) error
DestroyYear(echo.Context) error
IndexYearPeriods(echo.Context) error
CreateYearPeriod(echo.Context) error
UpdateYearPeriod(echo.Context) error
DestroyYearPeriod(echo.Context) error
}

func NewYearController(u usecase.YearUseCase) YearController {
Expand Down Expand Up @@ -71,3 +81,48 @@ func (y *yearController) DestroyYear(c echo.Context) error {
}
return c.String(http.StatusOK, "Destroy Year")
}

func (y *yearController) IndexYearPeriods(c echo.Context) error {
years, err := y.u.GetYearPeriods(c.Request().Context())
if err != nil {
return err
}
return c.JSON(http.StatusOK, years)
}

func (y *yearController) CreateYearPeriod(c echo.Context) error {
yearPeriod := new(domain.YearPeriod)
if err := c.Bind(yearPeriod); err != nil {
fmt.Println("err")
return err
}
latestYearPeriod, err := y.u.CreateYearPeriod(c.Request().Context(), strconv.Itoa(yearPeriod.Year), yearPeriod.StartedAt.Format(Layout), yearPeriod.EndedAt.Format(Layout))
if err != nil {
return err
}
return c.JSON(http.StatusCreated, latestYearPeriod)
}

func (y *yearController) UpdateYearPeriod(c echo.Context) error {
id := c.Param("id")
print(id)
yearPeriod := new(domain.YearPeriod)
if err := c.Bind(yearPeriod); err != nil {
fmt.Println("err")
return err
}
updateYearPeriod, err := y.u.UpdateYearPeriod(c.Request().Context(), id , strconv.Itoa(yearPeriod.Year), yearPeriod.StartedAt.Format(Layout), yearPeriod.EndedAt.Format(Layout))
if err != nil {
return err
}
return c.JSON(http.StatusCreated, updateYearPeriod)
}

func (y *yearController) DestroyYearPeriod(c echo.Context) error {
id := c.Param("id")
err := y.u.DestroyYearPeriod(c.Request().Context(), id)
if err != nil {
return err
}
return c.String(http.StatusOK, "Destroy Year Records")
}
40 changes: 40 additions & 0 deletions api/externals/repository/purchase_order_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type PurchaseOrderRepository interface {
FindNewRecord(context.Context) (*sql.Row, error)
DeleteItems(context.Context, string) error
DeleteReport(context.Context, string) error
AllUserInfoByYear(context.Context, string) (*sql.Rows, error)
}

func NewPurchaseOrderRepository(c db.Client, ac abstract.Crud) PurchaseOrderRepository {
Expand Down Expand Up @@ -160,3 +161,42 @@ func (por *purchaseOrderRepository) DeleteReport(
query := `DELETE FROM purchase_reports WHERE purchase_order_id =` + id
return por.crud.UpdateDB(c, query)
}

func (p *purchaseOrderRepository) AllUserInfoByYear(c context.Context, year string) (*sql.Rows, error) {
query := `
SELECT
purchase_orders.id,
purchase_orders.deadline,
purchase_orders.user_id,
purchase_orders.expense_id,
purchase_orders.finance_check,
purchase_orders.created_at,
purchase_orders.updated_at,
users.id,
users.name,
users.bureau_id,
users.role_id,
users.created_at,
users.updated_at
FROM
purchase_orders
INNER JOIN
users
ON
purchase_orders.user_id = users.id
INNER JOIN
year_periods
ON
purchase_orders.created_at > year_periods.started_at
AND
purchase_orders.created_at < year_periods.ended_at
INNER JOIN
years
ON
year_periods.year_id = years.id
WHERE
years.year = ` + year +
" ORDER BY purchase_orders.id"
return p.crud.Read(c, query)
}

Loading

0 comments on commit 7307a06

Please sign in to comment.