Line data Source code
1 : // Package presenter は
2 : package presenter
3 :
4 : import "resume/internal/domain/entity"
5 :
6 : // UserResponse は API レスポンス用の DTO(camelCase)です
7 : type UserResponse struct {
8 : ID uint64 `json:"id"`
9 : UID string `json:"uid"`
10 : DisplayName *string `json:"displayName,omitempty"`
11 : Email *string `json:"email,omitempty"`
12 : PhotoURL *string `json:"photoURL,omitempty"`
13 : Disabled bool `json:"disabled"`
14 : }
15 :
16 : // FromDomainUser は domain.User を UserResponse に変換します
17 0 : func FromDomainUser(u *entity.User) UserResponse {
18 0 : return UserResponse{
19 0 : ID: u.ID,
20 0 : UID: u.UID,
21 0 : DisplayName: u.DisplayName,
22 0 : Email: u.Email,
23 0 : PhotoURL: u.PhotoURL,
24 0 : Disabled: u.Disabled,
25 0 : }
26 0 : }
27 :
28 : // FromDomainUsers は複数の domain.User を []UserResponse に変換します
29 0 : func FromDomainUsers(users []*entity.User) []UserResponse {
30 0 : res := make([]UserResponse, 0, len(users))
31 0 : for _, u := range users {
32 0 : res = append(res, FromDomainUser(u))
33 0 : }
34 0 : return res
35 : }
|