Skip to content

Commit

Permalink
Replace PublicUserType with models.PublicUser type (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlacey authored Oct 5, 2024
1 parent 7688638 commit bfe976b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 37 deletions.
2 changes: 1 addition & 1 deletion backend/handlers/markets/listmarkets.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ListMarketsResponse struct {

type MarketOverview struct {
Market marketpublicresponse.PublicResponseMarket `json:"market"`
Creator usersHandlers.PublicUserType `json:"creator"`
Creator models.PublicUser `json:"creator"`
LastProbability float64 `json:"lastProbability"`
NumUsers int `json:"numUsers"`
TotalVolume int64 `json:"totalVolume"`
Expand Down
6 changes: 1 addition & 5 deletions backend/handlers/markets/marketdetailshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// MarketDetailResponse defines the structure for the market detail response
type MarketDetailHandlerResponse struct {
Market marketpublicresponse.PublicResponseMarket `json:"market"`
Creator usersHandlers.PublicUserType `json:"creator"`
Creator models.PublicUser `json:"creator"`
ProbabilityChanges []wpam.ProbabilityChange `json:"probabilityChanges"`
NumUsers int `json:"numUsers"`
TotalVolume int64 `json:"totalVolume"`
Expand Down Expand Up @@ -55,10 +55,6 @@ func MarketDetailsHandler(w http.ResponseWriter, r *http.Request) {

// find the number of users on the market
numUsers := models.GetNumMarketUsers(bets)
if err != nil {
http.Error(w, "Error retrieving number of users.", http.StatusInternalServerError)
return
}

// market volume is equivalent to the sum of all bets
marketVolume := marketmath.GetMarketVolume(bets)
Expand Down
34 changes: 3 additions & 31 deletions backend/handlers/users/publicuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@ import (
"gorm.io/gorm"
)

// PublicUserType is a struct for user data that is safe to send to the client for Profiles
type PublicUserType struct {
Username string `json:"username"`
DisplayName string `json:"displayname" gorm:"unique;not null"`
UserType string `json:"usertype"`
InitialAccountBalance int64 `json:"initialAccountBalance"`
AccountBalance int64 `json:"accountBalance"`
PersonalEmoji string `json:"personalEmoji,omitempty"`
Description string `json:"description,omitempty"`
PersonalLink1 string `json:"personalink1,omitempty"`
PersonalLink2 string `json:"personalink2,omitempty"`
PersonalLink3 string `json:"personalink3,omitempty"`
PersonalLink4 string `json:"personalink4,omitempty"`
}

func GetPublicUserResponse(w http.ResponseWriter, r *http.Request) {
// Extract the username from the URL
vars := mux.Vars(r)
Expand All @@ -38,23 +23,10 @@ func GetPublicUserResponse(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(response)
}

// Function to get the Info From the Database
func GetPublicUserInfo(db *gorm.DB, username string) PublicUserType {

// Function to get the users public info From the Database
func GetPublicUserInfo(db *gorm.DB, username string) models.PublicUser {
var user models.User
db.Where("username = ?", username).First(&user)

return PublicUserType{
Username: user.Username,
DisplayName: user.DisplayName,
UserType: user.UserType,
InitialAccountBalance: user.InitialAccountBalance,
AccountBalance: user.AccountBalance,
PersonalEmoji: user.PersonalEmoji,
Description: user.Description,
PersonalLink1: user.PersonalLink1,
PersonalLink2: user.PersonalLink2,
PersonalLink3: user.PersonalLink3,
PersonalLink4: user.PersonalLink4,
}
return user.PublicUser
}

0 comments on commit bfe976b

Please sign in to comment.