Skip to content

Commit

Permalink
不必要な構造体を削除
Browse files Browse the repository at this point in the history
  • Loading branch information
ramdos0207 committed Oct 26, 2024
1 parent a6d152c commit bdabc5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 40 deletions.
37 changes: 0 additions & 37 deletions router/v3/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/traPtitech/traQ/model"
"github.com/traPtitech/traQ/service/rbac/permission"
"github.com/traPtitech/traQ/utils/optional"

"github.com/gofrs/uuid"
Expand Down Expand Up @@ -624,39 +623,3 @@ func formatStampPalettes(cfs []*model.StampPalette) []*StampPalette {
sort.Slice(res, func(i, j int) bool { return res[i].ID.String() < res[j].ID.String() })
return res
}

type UserInfo struct {
ID uuid.UUID `json:"id"`
Bio string `json:"bio"`
Groups []uuid.UUID `json:"groups"`
Tags []UserTag `json:"tags"`
UpdatedAt time.Time `json:"updatedAt"`
LastOnline optional.Of[time.Time] `json:"lastOnline"`
TwitterID string `json:"twitterId"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
IconFileID uuid.UUID `json:"iconFileId"`
Bot bool `json:"bot"`
State int `json:"state"`
Permissions []permission.Permission `json:"permissions"`
HomeChannel optional.Of[uuid.UUID] `json:"homeChannel"`
}

func FormatUserInfo(ui model.UserInfo, tags []model.UserTag, groups []uuid.UUID, permissions []permission.Permission) *UserInfo {
return &UserInfo{
ID: ui.GetID(),
Bio: ui.GetBio(),
Groups: groups,
Tags: formatUserTags(tags),
UpdatedAt: ui.GetUpdatedAt(),
LastOnline: ui.GetLastOnline(),
TwitterID: ui.GetTwitterID(),
Name: ui.GetName(),
DisplayName: ui.GetResponseDisplayName(),
IconFileID: ui.GetIconFileID(),
Bot: ui.IsBot(),
State: ui.GetState().Int(),
Permissions: permissions,
HomeChannel: ui.GetHomeChannel(),
}
}
20 changes: 17 additions & 3 deletions router/v3/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"sort"
"time"

"github.com/samber/lo"

vd "github.com/go-ozzo/ozzo-validation/v4"
"github.com/gofrs/uuid"
"github.com/golang-jwt/jwt/v5"
"github.com/labstack/echo/v4"
"github.com/samber/lo"
"github.com/skip2/go-qrcode"

"github.com/traPtitech/traQ/model"
Expand Down Expand Up @@ -101,7 +100,22 @@ func (h *Handlers) GetMe(c echo.Context) error {
if err != nil {
return herror.InternalServerError(err)
}
return extension.ServeJSONWithETag(c, FormatUserInfo(me, tags, groups, h.RBAC.GetGrantedPermissions(me.GetRole())))
return extension.ServeJSONWithETag(c, echo.Map{
"id": me.GetID(),
"bio": me.GetBio(),
"groups": groups,
"tags": formatUserTags(tags),
"updatedAt": me.GetUpdatedAt(),
"lastOnline": me.GetLastOnline(),
"twitterId": me.GetTwitterID(),
"name": me.GetName(),
"displayName": me.GetResponseDisplayName(),
"iconFileId": me.GetIconFileID(),
"bot": me.IsBot(),
"state": me.GetState().Int(),
"permissions": h.RBAC.GetGrantedPermissions(me.GetRole()),
"homeChannel": me.GetHomeChannel(),
})
}

type userAccessScopes struct{}
Expand Down

0 comments on commit bdabc5a

Please sign in to comment.