Skip to content

Commit f1bf90c

Browse files
committed
Merge remote changes before package scoreboard update
2 parents f34dbe5 + 1c839ca commit f1bf90c

File tree

10 files changed

+265
-16
lines changed

10 files changed

+265
-16
lines changed

badges/BroQi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"schemaVersion": 1,
33
"label": "Go Interview Practice",
4-
"message": "\ud83c\udf31 Beginner (1/30)",
4+
"message": "\ud83c\udf31 Beginner (2/30)",
55
"color": "97ca00",
66
"style": "for-the-badge"
77
}

badges/BroQi.svg

Lines changed: 2 additions & 2 deletions
Loading

badges/BroQi_badges.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
[![Go Interview Practice](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/RezaSi/go-interview-practice/main/badges/BroQi.json&style=for-the-badge&logo=go&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
1515

1616
### 📊 Static Badges Collection
17-
[![Challenges Solved](https://img.shields.io/badge/Go_Challenges-1%2F30-brightgreen?style=for-the-badge&logo=go&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
17+
[![Challenges Solved](https://img.shields.io/badge/Go_Challenges-2%2F30-brightgreen?style=for-the-badge&logo=go&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
1818
[![Achievement Level](https://img.shields.io/badge/Level-🌱_Beginner-97ca00?style=for-the-badge&logo=trophy&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
19-
[![Completion Rate](https://img.shields.io/badge/Completion-3.3%25-97ca00?style=for-the-badge&logo=checkmarx&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
19+
[![Completion Rate](https://img.shields.io/badge/Completion-6.7%25-97ca00?style=for-the-badge&logo=checkmarx&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
2020

2121

2222
### 🔗 Repository Link Badge
@@ -28,5 +28,5 @@
2828

2929
**👤 Username:** @BroQi
3030
**🏅 Achievement Level:** 🌱 **Beginner Developer**
31-
**📊 Classic Challenges:** 1/30 (3.3% complete)
31+
**📊 Classic Challenges:** 2/30 (6.7% complete)
3232
**🔗 Repository:** [Go Interview Practice](https://github.com/RezaSi/go-interview-practice)

badges/BroQi_compact.svg

Lines changed: 2 additions & 2 deletions
Loading

badges/cckwes.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"schemaVersion": 1,
33
"label": "Go Interview Practice",
4-
"message": "\ud83c\udf31 Beginner (1/30)",
4+
"message": "\ud83c\udf31 Beginner (2/30)",
55
"color": "97ca00",
66
"style": "for-the-badge"
77
}

badges/cckwes.svg

Lines changed: 2 additions & 2 deletions
Loading

badges/cckwes_badges.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
[![Go Interview Practice](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/RezaSi/go-interview-practice/main/badges/cckwes.json&style=for-the-badge&logo=go&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
1515

1616
### 📊 Static Badges Collection
17-
[![Challenges Solved](https://img.shields.io/badge/Go_Challenges-1%2F30-brightgreen?style=for-the-badge&logo=go&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
17+
[![Challenges Solved](https://img.shields.io/badge/Go_Challenges-2%2F30-brightgreen?style=for-the-badge&logo=go&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
1818
[![Achievement Level](https://img.shields.io/badge/Level-🌱_Beginner-97ca00?style=for-the-badge&logo=trophy&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
19-
[![Completion Rate](https://img.shields.io/badge/Completion-3.3%25-97ca00?style=for-the-badge&logo=checkmarx&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
19+
[![Completion Rate](https://img.shields.io/badge/Completion-6.7%25-97ca00?style=for-the-badge&logo=checkmarx&logoColor=white)](https://github.com/RezaSi/go-interview-practice)
2020

2121

2222
### 🔗 Repository Link Badge
@@ -28,5 +28,5 @@
2828

2929
**👤 Username:** @cckwes
3030
**🏅 Achievement Level:** 🌱 **Beginner Developer**
31-
**📊 Classic Challenges:** 1/30 (3.3% complete)
31+
**📊 Classic Challenges:** 2/30 (6.7% complete)
3232
**🔗 Repository:** [Go Interview Practice](https://github.com/RezaSi/go-interview-practice)

badges/cckwes_compact.svg

Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
// Standard U.S. coin denominations in cents
9+
denominations := []int{1, 5, 10, 25, 50}
10+
11+
// Test amounts
12+
amounts := []int{87, 42, 99, 33, 7}
13+
14+
for _, amount := range amounts {
15+
// Find minimum number of coins
16+
minCoins := MinCoins(amount, denominations)
17+
18+
// Find coin combination
19+
coinCombo := CoinCombination(amount, denominations)
20+
21+
// Print results
22+
fmt.Printf("Amount: %d cents\n", amount)
23+
fmt.Printf("Minimum coins needed: %d\n", minCoins)
24+
fmt.Printf("Coin combination: %v\n", coinCombo)
25+
fmt.Println("---------------------------")
26+
}
27+
}
28+
29+
// MinCoins returns the minimum number of coins needed to make the given amount.
30+
// If the amount cannot be made with the given denominations, return -1.
31+
func MinCoins(amount int, denominations []int) int {
32+
if amount <= 0 {
33+
return 0
34+
}
35+
var count int
36+
for i := len(denominations) - 1; i >= 0; i-- {
37+
tmpCount := amount / denominations[i]
38+
if tmpCount > 0 {
39+
count += tmpCount
40+
amount -= tmpCount * denominations[i]
41+
}
42+
if amount == 0 {
43+
break
44+
}
45+
}
46+
if count == 0 {
47+
return -1
48+
}
49+
return count
50+
}
51+
52+
// CoinCombination returns a map with the specific combination of coins that gives
53+
// the minimum number. The keys are coin denominations and values are the number of
54+
// coins used for each denomination.
55+
// If the amount cannot be made with the given denominations, return an empty map.
56+
func CoinCombination(amount int, denominations []int) map[int]int {
57+
result := make(map[int]int)
58+
if amount <= 0 {
59+
return result
60+
}
61+
for i := len(denominations) - 1; i >= 0; i-- {
62+
tmpCount := amount / denominations[i]
63+
if tmpCount > 0 {
64+
result[denominations[i]] = tmpCount
65+
amount -= tmpCount * denominations[i]
66+
}
67+
if amount == 0 {
68+
break
69+
}
70+
}
71+
return result
72+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
package main
2+
3+
import (
4+
"time"
5+
"errors"
6+
"gorm.io/gorm"
7+
"gorm.io/driver/sqlite"
8+
)
9+
10+
// User represents a user in the social media system
11+
type User struct {
12+
ID uint `gorm:"primaryKey"`
13+
Username string `gorm:"unique;not null"`
14+
Email string `gorm:"unique;not null"`
15+
Age int `gorm:"not null"`
16+
Country string `gorm:"not null"`
17+
CreatedAt time.Time
18+
Posts []Post `gorm:"foreignKey:UserID"`
19+
Likes []Like `gorm:"foreignKey:UserID"`
20+
}
21+
22+
// Post represents a social media post
23+
type Post struct {
24+
ID uint `gorm:"primaryKey"`
25+
Title string `gorm:"not null"`
26+
Content string `gorm:"type:text"`
27+
UserID uint `gorm:"not null"`
28+
User User `gorm:"foreignKey:UserID"`
29+
Category string `gorm:"not null"`
30+
ViewCount int `gorm:"default:0"`
31+
IsPublished bool `gorm:"default:true"`
32+
CreatedAt time.Time
33+
UpdatedAt time.Time
34+
Likes []Like `gorm:"foreignKey:PostID"`
35+
}
36+
37+
// Like represents a user's like on a post
38+
type Like struct {
39+
ID uint `gorm:"primaryKey"`
40+
UserID uint `gorm:"not null"`
41+
PostID uint `gorm:"not null"`
42+
User User `gorm:"foreignKey:UserID"`
43+
Post Post `gorm:"foreignKey:PostID"`
44+
CreatedAt time.Time
45+
}
46+
47+
// ConnectDB establishes a connection to the SQLite database with auto-migration
48+
func ConnectDB() (*gorm.DB, error) {
49+
// TODO: Implement database connection with auto-migration
50+
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
51+
if err != nil {
52+
return nil, err
53+
}
54+
err = db.AutoMigrate(&User{}, &Post{}, &Like{})
55+
return db, err
56+
}
57+
58+
// GetTopUsersByPostCount retrieves users with the most posts
59+
func GetTopUsersByPostCount(db *gorm.DB, limit int) ([]User, error) {
60+
// TODO: Implement top users by post count aggregation
61+
var users []User
62+
err := db.Joins("LEFT JOIN posts ON users.id = posts.user_id").
63+
Group("users.id").
64+
Order("COUNT(posts.id) DESC").
65+
Limit(limit).
66+
Find(&users).Error
67+
return users, err
68+
}
69+
70+
// GetPostsByCategoryWithUserInfo retrieves posts by category with pagination and user info
71+
func GetPostsByCategoryWithUserInfo(db *gorm.DB, category string, page, pageSize int) ([]Post, int64, error) {
72+
// TODO: Implement paginated posts retrieval with user info
73+
if page < 0 {
74+
return nil, 0, errors.New("Error")
75+
}
76+
var posts []Post
77+
var total int64
78+
query := db.Where("category = ?", category)
79+
query.Model(&Post{}).Count(&total)
80+
offset := (page - 1) * pageSize
81+
err := query.Preload("User").Offset(offset).Limit(pageSize).Find(&posts).Error
82+
return posts, total, err
83+
}
84+
85+
// GetUserEngagementStats calculates engagement statistics for a user
86+
func GetUserEngagementStats(db *gorm.DB, userID uint) (map[string]interface{}, error) {
87+
// TODO: Implement user engagement statistics
88+
stats := make(map[string]interface{})
89+
var user User
90+
if err := db.First(&user, userID).Error; err != nil {
91+
return nil, err
92+
}
93+
var postCount int64
94+
db.Model(&Post{}).Where("user_id = ?", userID).Count(&postCount)
95+
stats["total_posts"] = postCount
96+
97+
var likesReceived int64
98+
db.Model(&Like{}).Joins("JOIN posts ON likes.post_id = posts.id").
99+
Where("posts.user_id = ?", userID).Count(&likesReceived)
100+
stats["total_likes_received"] = likesReceived
101+
102+
var likesGiven int64
103+
db.Model(&Like{}).Joins("JOIN users ON likes.user_id = users.id").
104+
Where("users.id = ?", userID).Count(&likesGiven)
105+
stats["total_likes_given"] = likesGiven
106+
107+
var avgViews float64
108+
db.Model(&Post{}).Select("AVG(view_count)").Where("user_id = ?", userID).Scan(&avgViews)
109+
stats["average_views_per_post"] = avgViews
110+
111+
return stats, nil
112+
}
113+
114+
// GetPopularPostsByLikes retrieves popular posts by likes in a time period
115+
func GetPopularPostsByLikes(db *gorm.DB, days int, limit int) ([]Post, error) {
116+
// TODO: Implement popular posts by likes
117+
var posts []Post
118+
cutoffDate := time.Now().AddDate(0, 0, -days)
119+
err := db.Joins("LEFT JOIN likes ON posts.id = likes.post_id").
120+
Where("posts.created_at >= ?", cutoffDate).
121+
Group("posts.id").
122+
Order("COUNT(likes.id) DESC").
123+
Limit(limit).
124+
Find(&posts).Error
125+
return posts, err
126+
}
127+
128+
// GetCountryUserStats retrieves user statistics grouped by country
129+
func GetCountryUserStats(db *gorm.DB) ([]map[string]interface{}, error) {
130+
// TODO: Implement country-based user statistics
131+
var results []struct {
132+
Country string
133+
UserCount int64
134+
AvgAge float64
135+
}
136+
err := db.Model(&User{}).
137+
Select("country, COUNT(*) as user_count, AVG(age) as avg_age").
138+
Group("country").
139+
Scan(&results).Error
140+
var stats []map[string]interface{}
141+
for _, result := range results {
142+
stat := map[string]interface{}{
143+
"country": result.Country,
144+
"user_count": result.UserCount,
145+
"avg_age": result.AvgAge,
146+
}
147+
stats = append(stats, stat)
148+
}
149+
return stats, err
150+
}
151+
152+
// SearchPostsByContent searches posts by content using full-text search
153+
func SearchPostsByContent(db *gorm.DB, query string, limit int) ([]Post, error) {
154+
// TODO: Implement full-text search
155+
var posts []Post
156+
searchPattern := "%" + query + "%"
157+
err := db.Where("title LIKE ? OR content LIKE ?", searchPattern, searchPattern).
158+
Limit(limit).
159+
Find(&posts).Error
160+
return posts, err
161+
}
162+
163+
// GetUserRecommendations retrieves user recommendations based on similar interests
164+
func GetUserRecommendations(db *gorm.DB, userID uint, limit int) ([]User, error) {
165+
// TODO: Implement user recommendations algorithm
166+
var users []User
167+
err := db.Where("id != ? AND id IN (?)", userID,
168+
db.Model(&Like{}).
169+
Select("DISTINCT likes.user_id").
170+
Joins("JOIN posts ON likes.post_id = posts.id").
171+
Joins("JOIN posts p2 ON p2.category = posts.category").
172+
Joins("JOIN likes l2 ON l2.post_id = p2.id").
173+
Where("l2.user_id = ?", userID)).
174+
Limit(limit).
175+
Find(&users).Error
176+
return users, err
177+
}

0 commit comments

Comments
 (0)