19cc7a778c
- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`. - Added new API server implementations for objectstory, player, and shop services. - Introduced configuration files for new APIs in `etc/*.yaml`. - Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`. - Removed unused user update handler and user API files. - Added utility functions for context management and HTTP header parsing. - Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
46 lines
994 B
Go
46 lines
994 B
Go
package logic
|
|
|
|
import (
|
|
"sort"
|
|
"strconv"
|
|
"time"
|
|
|
|
"juwan-backend/app/community/rpc/pb"
|
|
)
|
|
|
|
func nowUnix(in int64) int64 {
|
|
if in > 0 {
|
|
return in
|
|
}
|
|
return time.Now().Unix()
|
|
}
|
|
|
|
func postLikeKey(postID, userID int64) string {
|
|
return strconv.FormatInt(postID, 10) + ":" + strconv.FormatInt(userID, 10)
|
|
}
|
|
|
|
func commentLikeKey(commentID, userID int64) string {
|
|
return strconv.FormatInt(commentID, 10) + ":" + strconv.FormatInt(userID, 10)
|
|
}
|
|
|
|
func sortPostsDesc(posts []*pb.Posts) {
|
|
sort.Slice(posts, func(i, j int) bool {
|
|
if posts[i].Pinned != posts[j].Pinned {
|
|
return posts[i].Pinned
|
|
}
|
|
if posts[i].CreatedAt == posts[j].CreatedAt {
|
|
return posts[i].Id > posts[j].Id
|
|
}
|
|
return posts[i].CreatedAt > posts[j].CreatedAt
|
|
})
|
|
}
|
|
|
|
func sortCommentsAsc(comments []*pb.Comments) {
|
|
sort.Slice(comments, func(i, j int) bool {
|
|
if comments[i].CreatedAt == comments[j].CreatedAt {
|
|
return comments[i].Id < comments[j].Id
|
|
}
|
|
return comments[i].CreatedAt < comments[j].CreatedAt
|
|
})
|
|
}
|