11package server
22
33import (
4+ "encoding/base64"
45 "errors"
56 "net/http"
67
78 "rocket-backend/internal/custom_error"
9+ "rocket-backend/internal/types"
810 "github.com/gin-gonic/gin"
911 "github.com/google/uuid"
1012)
@@ -32,12 +34,26 @@ func (s *Server) GetFriendsRankedHandler(c *gin.Context) {
3234 return
3335 }
3436
35- if len (friends ) == 0 {
36- c .JSON (http .StatusOK , []interface {}{})
37- return
37+ var friendsWithImages []types.UserWithImageDTO
38+ for _ , user := range friends {
39+ userImage , err := s .db .GetUserImage (user .ID )
40+ var imageName , imageData string
41+ if err == nil && userImage != nil {
42+ imageName = userImage .Name
43+ imageData = base64 .StdEncoding .EncodeToString (userImage .Data )
44+ }
45+ friendsWithImages = append (friendsWithImages , types.UserWithImageDTO {
46+ ID : user .ID ,
47+ Username : user .Username ,
48+ Email : user .Email ,
49+ RocketPoints : user .RocketPoints ,
50+ ImageName : imageName ,
51+ ImageData : imageData ,
52+ Steps : 0 ,
53+ })
3854 }
3955
40- c .JSON (http .StatusOK , friends )
56+ c .JSON (http .StatusOK , friendsWithImages )
4157}
4258
4359func (s * Server ) GetUserRankingHandler (c * gin.Context ) {
@@ -51,5 +67,25 @@ func (s *Server) GetUserRankingHandler(c *gin.Context) {
5167 return
5268 }
5369
54- c .JSON (http .StatusOK , ranking )
70+ var usersWithImages []types.UserWithImageDTO
71+ for _ , user := range ranking {
72+ userImage , err := s .db .GetUserImage (user .ID )
73+ var imageName , imageData string
74+ if err == nil && userImage != nil {
75+ imageName = userImage .Name
76+ imageData = base64 .StdEncoding .EncodeToString (userImage .Data )
77+ }
78+
79+ usersWithImages = append (usersWithImages , types.UserWithImageDTO {
80+ ID : user .ID ,
81+ Username : user .Username ,
82+ Email : user .Email ,
83+ RocketPoints : user .RocketPoints ,
84+ ImageName : imageName ,
85+ ImageData : imageData ,
86+ Steps : 0 , // no steps needed for ranking
87+ })
88+ }
89+
90+ c .JSON (http .StatusOK , usersWithImages )
5591}
0 commit comments