Skip to content
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

requestsにlimit, offsetをつける #764

Open
H1rono opened this issue Jun 21, 2024 · 1 comment · May be fixed by #806
Open

requestsにlimit, offsetをつける #764

H1rono opened this issue Jun 21, 2024 · 1 comment · May be fixed by #806
Assignees
Labels
enhancement New feature or request v2 About Jomon version2

Comments

@H1rono
Copy link
Member

H1rono commented Jun 21, 2024

#711 (comment)
#762 の大体コピペでおk

@H1rono H1rono added enhancement New feature or request v2 About Jomon version2 labels Jun 21, 2024
@H1rono
Copy link
Member Author

H1rono commented Jun 21, 2024

Jomon/docs/swagger.yaml

Lines 141 to 164 in 444568f

get:
operationId: getRequests
description: 依頼一覧を取得する。
tags:
- Requests
parameters:
- $ref: "#/components/parameters/sortRequestQuery"
- $ref: "#/components/parameters/statusQuery"
- $ref: "#/components/parameters/targetQuery"
- $ref: "#/components/parameters/sinceQuery"
- $ref: "#/components/parameters/untilQuery"
- $ref: "#/components/parameters/tagQuery"
- $ref: "#/components/parameters/groupQuery"
responses:
"200":
description: 取得できた場合。該当するものがなくても空配列を返す。
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Request"
"400":
$ref: "#/components/responses/400"

Jomon/router/request.go

Lines 115 to 237 in 444568f

func (h Handlers) GetRequests(c echo.Context) error {
ctx := c.Request().Context()
var sort *string
if s := c.QueryParam("sort"); s != "" {
sort = &s
}
var status Status
var ss *string
if s := c.QueryParam("status"); s != "" {
status = Status(s)
if !status.Valid() {
return echo.NewHTTPError(http.StatusBadRequest, "invalid status")
}
}
if s := status.String(); s != "" {
ss = &s
}
var target *uuid.UUID
if c.QueryParam("target") != "" {
t, err := uuid.Parse(c.QueryParam("target"))
if err != nil {
h.Logger.Info("could not parse query parameter `target` as UUID", zap.Error(err))
return echo.NewHTTPError(http.StatusBadRequest, err)
}
target = &t
}
var since *time.Time
if c.QueryParam("since") != "" {
s, err := service.StrToDate(c.QueryParam("since"))
if err != nil {
h.Logger.Info("could not parse query parameter `since` as time.Time", zap.Error(err))
return echo.NewHTTPError(http.StatusBadRequest, err)
}
since = &s
}
var until *time.Time
if c.QueryParam("until") != "" {
u, err := service.StrToDate(c.QueryParam("until"))
if err != nil {
h.Logger.Info("could not parse query parameter `until` as time.Time", zap.Error(err))
return echo.NewHTTPError(http.StatusBadRequest, err)
}
until = &u
}
var tag *string
if c.QueryParam("tag") != "" {
t := c.QueryParam("tag")
tag = &t
}
var group *string
if c.QueryParam("group") != "" {
g := c.QueryParam("group")
group = &g
}
query := model.RequestQuery{
Sort: sort,
Target: target,
Status: ss,
Since: since,
Until: until,
Tag: tag,
Group: group,
}
modelrequests, err := h.Repository.GetRequests(ctx, query)
if err != nil {
h.Logger.Error("failed to get requests from repository", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
tags := []*TagOverview{}
requests := []*RequestResponse{}
for _, request := range modelrequests {
for _, tag := range request.Tags {
tags = append(tags, &TagOverview{
ID: tag.ID,
Name: tag.Name,
CreatedAt: tag.CreatedAt,
UpdatedAt: tag.UpdatedAt,
})
}
restargets := []*TargetOverview{}
for _, target := range request.Targets {
restargets = append(restargets, &TargetOverview{
ID: target.ID,
Target: target.Target,
Amount: target.Amount,
PaidAt: target.PaidAt,
CreatedAt: target.CreatedAt,
})
}
var resgroup *GroupOverview
if request.Group != nil {
resgroup = &GroupOverview{
ID: request.Group.ID,
Name: request.Group.Name,
Description: request.Group.Description,
Budget: request.Group.Budget,
CreatedAt: request.Group.CreatedAt,
UpdatedAt: request.Group.UpdatedAt,
}
}
res := &RequestResponse{
ID: request.ID,
Status: request.Status,
CreatedAt: request.CreatedAt,
UpdatedAt: request.UpdatedAt,
CreatedBy: request.CreatedBy,
Title: request.Title,
Content: request.Content,
Targets: restargets,
Tags: tags,
Group: resgroup,
Comments: []*CommentDetail{},
}
requests = append(requests, res)
}
return c.JSON(http.StatusOK, requests)
}

@reiroop reiroop linked a pull request Nov 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v2 About Jomon version2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants