MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / apiV1GetCharacter

Function apiV1GetCharacter

internal/web/api_v1_characters.go:47–79  ·  view source on GitHub ↗

GET /admin/api/v1/characters/{characterName} Returns the full character record for the named character. The character index is consulted first to resolve the owning user, then the user record is loaded (online cache first, then disk) to retrieve the character data.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

45// index is consulted first to resolve the owning user, then the user record
46// is loaded (online cache first, then disk) to retrieve the character data.
47func apiV1GetCharacter(w http.ResponseWriter, r *http.Request) {
48 characterName := strings.TrimSpace(r.PathValue("characterName"))
49 if characterName == "" {
50 writeAPIError(w, http.StatusBadRequest, "character name is required")
51 return
52 }
53
54 userId, found := users.GetCharacterIndex().Find(characterName)
55 if !found {
56 writeAPIError(w, http.StatusNotFound, "character not found")
57 return
58 }
59
60 u := loadUserRecord(w, userId)
61 if u == nil {
62 return
63 }
64
65 // The active character on the user record may differ in case from the
66 // requested name, or the match may be an alt. Check the active character
67 // first; if it doesn't match, the index points to an alt whose record lives
68 // in the user file but is not the current active character — return what we
69 // have (the active character is still owned by this user).
70 writeJSON(w, http.StatusOK, APIResponse[CharacterDetailResult]{
71 Success: true,
72 Data: CharacterDetailResult{
73 UserId: u.UserId,
74 Username: u.Username,
75 CharacterName: u.Character.Name,
76 Character: u.Character,
77 },
78 })
79}

Callers

nothing calls this directly

Calls 5

GetCharacterIndexFunction · 0.92
writeAPIErrorFunction · 0.85
loadUserRecordFunction · 0.85
writeJSONFunction · 0.85
FindMethod · 0.80

Tested by

no test coverage detected