|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + service "github.com/wundergraph/cosmo/plugin/generated" |
| 5 | + "google.golang.org/protobuf/types/known/wrapperspb" |
| 6 | +) |
| 7 | + |
| 8 | +// Geo represents geographic coordinates in the JSONPlaceholder API |
| 9 | +type Geo struct { |
| 10 | + Lat string `json:"lat"` |
| 11 | + Lng string `json:"lng"` |
| 12 | +} |
| 13 | + |
| 14 | +// Address represents an address in JSONPlaceholder API |
| 15 | +type Address struct { |
| 16 | + Street string `json:"street"` |
| 17 | + Suite string `json:"suite"` |
| 18 | + City string `json:"city"` |
| 19 | + Zipcode string `json:"zipcode"` |
| 20 | + Geo Geo `json:"geo"` |
| 21 | +} |
| 22 | + |
| 23 | +// Company represents a company in JSONPlaceholder API |
| 24 | +type Company struct { |
| 25 | + Name string `json:"name"` |
| 26 | + CatchPhrase string `json:"catchPhrase"` |
| 27 | + Bs string `json:"bs"` |
| 28 | +} |
| 29 | + |
| 30 | +// ExternalUser represents a user from the JSONPlaceholder API |
| 31 | +type ExternalUser struct { |
| 32 | + ID int `json:"id"` |
| 33 | + Name string `json:"name"` |
| 34 | + Username string `json:"username"` |
| 35 | + Email string `json:"email"` |
| 36 | + Phone string `json:"phone"` |
| 37 | + Website string `json:"website"` |
| 38 | + Address Address `json:"address"` |
| 39 | + Company Company `json:"company"` |
| 40 | +} |
| 41 | + |
| 42 | +// Mock posts data |
| 43 | +var mockPosts = map[string]*service.Post{ |
| 44 | + "1": {Id: "1", Title: "Getting Started with GraphQL", AuthorId: "1"}, |
| 45 | + "2": {Id: "2", Title: "Advanced Federation Patterns", AuthorId: "1"}, |
| 46 | + "3": {Id: "3", Title: "Building Scalable APIs", AuthorId: "2"}, |
| 47 | + "4": {Id: "4", Title: "TypeScript Best Practices", AuthorId: "3"}, |
| 48 | +} |
| 49 | + |
| 50 | +// Mock comments data |
| 51 | +var mockComments = map[string]*service.Comment{ |
| 52 | + "1": {Id: "1", Content: "Great post! Very helpful.", AuthorId: "2"}, |
| 53 | + "2": {Id: "2", Content: "Thanks for sharing this.", AuthorId: "3"}, |
| 54 | + "3": {Id: "3", Content: "Looking forward to more content.", AuthorId: "4"}, |
| 55 | + "4": {Id: "4", Content: "Excellent examples provided.", AuthorId: "1"}, |
| 56 | +} |
| 57 | + |
| 58 | +// Mock user data store for demonstration purposes |
| 59 | +// In a production environment, this would be replaced with a proper database |
| 60 | +var mockUsers = map[string]*service.User{ |
| 61 | + "1": { |
| 62 | + Id: "1", |
| 63 | + Name: "Alice Johnson", |
| 64 | + |
| 65 | + Role: service.UserRole_USER_ROLE_ADMIN, |
| 66 | + Permissions: []string{"read", "write"}, |
| 67 | + Tags: &service.ListOfString{List: &service.ListOfString_List{Items: []string{"admin", "user"}}}, |
| 68 | + SkillCategories: &service.ListOfListOfString{ |
| 69 | + List: &service.ListOfListOfString_List{ |
| 70 | + Items: []*service.ListOfString{ |
| 71 | + {List: &service.ListOfString_List{Items: []string{"JavaScript", "TypeScript"}}}, |
| 72 | + {List: &service.ListOfString_List{Items: []string{"React", "Vue", "Angular"}}}, |
| 73 | + {List: &service.ListOfString_List{Items: []string{"Node.js", "Express"}}}, |
| 74 | + }, |
| 75 | + }, |
| 76 | + }, |
| 77 | + RecentActivity: []*service.ActivityItem{ |
| 78 | + {Value: &service.ActivityItem_Post{Post: mockPosts["1"]}}, |
| 79 | + {Value: &service.ActivityItem_Post{Post: mockPosts["2"]}}, |
| 80 | + {Value: &service.ActivityItem_Comment{Comment: mockComments["4"]}}, |
| 81 | + }, |
| 82 | + Profile: &service.Profile{ |
| 83 | + DisplayName: &wrapperspb.StringValue{Value: "Alice J."}, |
| 84 | + Timezone: &wrapperspb.StringValue{Value: "America/New_York"}, |
| 85 | + Theme: service.Theme_THEME_DARK, |
| 86 | + }, |
| 87 | + Bio: &wrapperspb.StringValue{Value: "Full-stack developer with 5+ years of experience"}, |
| 88 | + Age: &wrapperspb.Int32Value{Value: 28}, |
| 89 | + }, |
| 90 | + "2": { |
| 91 | + Id: "2", |
| 92 | + Name: "Bob Smith", |
| 93 | + |
| 94 | + Role: service.UserRole_USER_ROLE_USER, |
| 95 | + Permissions: []string{"read"}, |
| 96 | + Tags: &service.ListOfString{List: &service.ListOfString_List{Items: []string{"user"}}}, |
| 97 | + SkillCategories: &service.ListOfListOfString{ |
| 98 | + List: &service.ListOfListOfString_List{ |
| 99 | + Items: []*service.ListOfString{ |
| 100 | + {List: &service.ListOfString_List{Items: []string{"Python", "Java"}}}, |
| 101 | + {List: &service.ListOfString_List{Items: []string{"Django", "Spring"}}}, |
| 102 | + }, |
| 103 | + }, |
| 104 | + }, |
| 105 | + RecentActivity: []*service.ActivityItem{ |
| 106 | + {Value: &service.ActivityItem_Post{Post: mockPosts["3"]}}, |
| 107 | + {Value: &service.ActivityItem_Comment{Comment: mockComments["1"]}}, |
| 108 | + }, |
| 109 | + Profile: &service.Profile{ |
| 110 | + DisplayName: &wrapperspb.StringValue{Value: "Bob"}, |
| 111 | + Timezone: &wrapperspb.StringValue{Value: "Europe/London"}, |
| 112 | + Theme: service.Theme_THEME_LIGHT, |
| 113 | + }, |
| 114 | + Bio: &wrapperspb.StringValue{Value: "Backend developer passionate about clean code"}, |
| 115 | + Age: &wrapperspb.Int32Value{Value: 32}, |
| 116 | + }, |
| 117 | + "3": { |
| 118 | + Id: "3", |
| 119 | + Name: "Charlie Brown", |
| 120 | + |
| 121 | + Role: service.UserRole_USER_ROLE_USER, |
| 122 | + Permissions: []string{"read"}, |
| 123 | + Tags: &service.ListOfString{List: &service.ListOfString_List{Items: []string{"user"}}}, |
| 124 | + SkillCategories: &service.ListOfListOfString{ |
| 125 | + List: &service.ListOfListOfString_List{ |
| 126 | + Items: []*service.ListOfString{ |
| 127 | + {List: &service.ListOfString_List{Items: []string{"Go", "Rust"}}}, |
| 128 | + {List: &service.ListOfString_List{Items: []string{"Docker", "Kubernetes"}}}, |
| 129 | + }, |
| 130 | + }, |
| 131 | + }, |
| 132 | + RecentActivity: []*service.ActivityItem{ |
| 133 | + {Value: &service.ActivityItem_Post{Post: mockPosts["4"]}}, |
| 134 | + {Value: &service.ActivityItem_Comment{Comment: mockComments["2"]}}, |
| 135 | + }, |
| 136 | + Profile: &service.Profile{ |
| 137 | + Timezone: &wrapperspb.StringValue{Value: "Asia/Tokyo"}, |
| 138 | + Theme: service.Theme_THEME_AUTO, |
| 139 | + }, |
| 140 | + Age: &wrapperspb.Int32Value{Value: 29}, |
| 141 | + }, |
| 142 | + "4": { |
| 143 | + Id: "4", |
| 144 | + Name: "Dana Lee", |
| 145 | + |
| 146 | + Role: service.UserRole_USER_ROLE_GUEST, |
| 147 | + Permissions: []string{"read"}, |
| 148 | + Tags: &service.ListOfString{List: &service.ListOfString_List{Items: []string{"guest"}}}, |
| 149 | + SkillCategories: &service.ListOfListOfString{ |
| 150 | + List: &service.ListOfListOfString_List{ |
| 151 | + Items: []*service.ListOfString{ |
| 152 | + {List: &service.ListOfString_List{Items: []string{"HTML", "CSS"}}}, |
| 153 | + }, |
| 154 | + }, |
| 155 | + }, |
| 156 | + RecentActivity: []*service.ActivityItem{ |
| 157 | + {Value: &service.ActivityItem_Comment{Comment: mockComments["3"]}}, |
| 158 | + }, |
| 159 | + Profile: &service.Profile{ |
| 160 | + DisplayName: &wrapperspb.StringValue{Value: "Dana"}, |
| 161 | + Theme: service.Theme_THEME_LIGHT, |
| 162 | + }, |
| 163 | + Bio: &wrapperspb.StringValue{Value: "Learning web development"}, |
| 164 | + Age: &wrapperspb.Int32Value{Value: 24}, |
| 165 | + }, |
| 166 | +} |
| 167 | + |
| 168 | +// User activity mappings for efficient lookup |
| 169 | +var userActivityMap = map[string][]*service.ActivityItem{ |
| 170 | + "1": { |
| 171 | + {Value: &service.ActivityItem_Post{Post: mockPosts["1"]}}, |
| 172 | + {Value: &service.ActivityItem_Post{Post: mockPosts["2"]}}, |
| 173 | + {Value: &service.ActivityItem_Comment{Comment: mockComments["4"]}}, |
| 174 | + }, |
| 175 | + "2": { |
| 176 | + {Value: &service.ActivityItem_Post{Post: mockPosts["3"]}}, |
| 177 | + {Value: &service.ActivityItem_Comment{Comment: mockComments["1"]}}, |
| 178 | + }, |
| 179 | + "3": { |
| 180 | + {Value: &service.ActivityItem_Post{Post: mockPosts["4"]}}, |
| 181 | + {Value: &service.ActivityItem_Comment{Comment: mockComments["2"]}}, |
| 182 | + }, |
| 183 | + "4": { |
| 184 | + {Value: &service.ActivityItem_Comment{Comment: mockComments["3"]}}, |
| 185 | + }, |
| 186 | +} |
0 commit comments