feat: 部署初版测试
This commit is contained in:
@@ -34,3 +34,38 @@ func (h *UserHandler) Register(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
SendSuccess(w, user)
|
||||
}
|
||||
|
||||
func (h *UserHandler) GetProfile(w http.ResponseWriter, r *http.Request) {
|
||||
// Assumes JWTAuth middleware has placed userID in context
|
||||
userID := r.Context().Value("userID").(string)
|
||||
|
||||
user, err := h.svc.GetUserByID(userID)
|
||||
if err != nil {
|
||||
SendError(w, http.StatusNotFound, 4004, "User not found")
|
||||
return
|
||||
}
|
||||
|
||||
SendSuccess(w, user)
|
||||
}
|
||||
|
||||
func (h *UserHandler) UpdatePreferences(w http.ResponseWriter, r *http.Request) {
|
||||
userID := r.Context().Value("userID").(string)
|
||||
|
||||
var body struct {
|
||||
IdentityLabel string `json:"identity_label"`
|
||||
LanguagePreference string `json:"language_preference"`
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
SendError(w, http.StatusBadRequest, 4001, "Invalid request body")
|
||||
return
|
||||
}
|
||||
|
||||
user, err := h.svc.UpdatePreferences(userID, body.IdentityLabel, body.LanguagePreference)
|
||||
if err != nil {
|
||||
SendError(w, http.StatusInternalServerError, 5001, "Failed to update preferences")
|
||||
return
|
||||
}
|
||||
|
||||
SendSuccess(w, user)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user