github.com/k0marov/go-socnet@v0.0.0-20220715154813-90d07867c782/features/profiles/delivery/http/responses/responses.go (about) 1 package responses 2 3 import ( 4 "github.com/k0marov/go-socnet/core/helpers" 5 "github.com/k0marov/go-socnet/features/profiles/domain/entities" 6 ) 7 8 type AvatarURLResponse struct { 9 AvatarURL string `json:"avatar_url,omitempty"` 10 } 11 12 type ProfileResponse struct { 13 Id string `json:"id"` 14 Username string `json:"username"` 15 About string `json:"about"` 16 AvatarURL string `json:"avatar_url,omitempty"` 17 Follows int `json:"follows"` 18 Followers int `json:"followers"` 19 IsMine bool `json:"is_mine"` 20 IsFollowed bool `json:"is_followed"` 21 } 22 23 type ProfilesResponse struct { 24 Profiles []ProfileResponse `json:"profiles"` 25 } 26 27 func NewProfileResponse(profile entities.ContextedProfile) ProfileResponse { 28 return ProfileResponse{ 29 Id: profile.Id, 30 Username: profile.Username, 31 About: profile.About, 32 AvatarURL: profile.AvatarURL, 33 Follows: profile.Follows, 34 Followers: profile.Followers, 35 IsMine: profile.IsMine, 36 IsFollowed: profile.IsLiked, 37 } 38 } 39 40 func NewProfilesResponse(profiles []entities.ContextedProfile) ProfilesResponse { 41 return ProfilesResponse{ 42 Profiles: helpers.MapForEach(profiles, NewProfileResponse), 43 } 44 }