Work on following relations api and small docs
This commit is contained in:
parent
526b5c2fef
commit
f656757710
3 changed files with 217 additions and 22 deletions
|
@ -165,6 +165,7 @@ func linstromUpdateAccount(w http.ResponseWriter, r *http.Request) {
|
|||
log.Error().Err(err).Msg("Failed to marshal and write updated account")
|
||||
}
|
||||
}
|
||||
|
||||
func linstromDeleteAccount(w http.ResponseWriter, r *http.Request) {
|
||||
actorId, _ := ActorIdFromRequest(r)
|
||||
log := hlog.FromRequest(r)
|
||||
|
@ -238,9 +239,119 @@ func linstromDeleteAccount(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func linstromIsFollowingAccount(w http.ResponseWriter, r *http.Request) {}
|
||||
func linstromFollowAccount(w http.ResponseWriter, r *http.Request) {}
|
||||
func linstromUnfollowAccount(w http.ResponseWriter, r *http.Request) {}
|
||||
// Is logged in following accountId
|
||||
func linstromIsFollowingToAccount(w http.ResponseWriter, r *http.Request) {
|
||||
store := StorageFromRequest(r)
|
||||
log := hlog.FromRequest(r)
|
||||
actorId, _ := ActorIdFromRequest(r)
|
||||
targetId := AccountIdFromRequest(r)
|
||||
|
||||
relation, err := store.GetRelationBetween(actorId, targetId)
|
||||
var outData linstromRelation
|
||||
switch err {
|
||||
case nil:
|
||||
outData = linstromRelation{
|
||||
Id: relation.ID,
|
||||
CreatedAt: relation.CreatedAt,
|
||||
UpdatedAt: relation.UpdatedAt,
|
||||
FromId: relation.FromId,
|
||||
ToId: relation.ToId,
|
||||
Accepted: relation.Accepted,
|
||||
Requested: true,
|
||||
}
|
||||
case storage.ErrEntryNotFound:
|
||||
outData = linstromRelation{
|
||||
Id: relation.ID,
|
||||
CreatedAt: relation.CreatedAt,
|
||||
UpdatedAt: relation.UpdatedAt,
|
||||
FromId: relation.FromId,
|
||||
ToId: relation.ToId,
|
||||
Accepted: false,
|
||||
Requested: false,
|
||||
}
|
||||
default:
|
||||
log.Error().
|
||||
Err(err).
|
||||
Str("from-id", actorId).
|
||||
Str("to-id", targetId).
|
||||
Msg("Failed to get follow relation")
|
||||
other.HttpErr(
|
||||
w,
|
||||
HttpErrIdDbFailure,
|
||||
"Failed to get relation",
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
}
|
||||
|
||||
err = jsonapi.MarshalPayload(w, outData)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to marshal response")
|
||||
other.HttpErr(
|
||||
w,
|
||||
HttpErrIdJsonMarshalFail,
|
||||
"Failed to marshal response",
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func linstromIsFollowingFromAccount(w http.ResponseWriter, r *http.Request) {
|
||||
store := StorageFromRequest(r)
|
||||
log := hlog.FromRequest(r)
|
||||
actorId, _ := ActorIdFromRequest(r)
|
||||
targetId := AccountIdFromRequest(r)
|
||||
|
||||
relation, err := store.GetRelationBetween(targetId, actorId)
|
||||
var outData linstromRelation
|
||||
switch err {
|
||||
case nil:
|
||||
outData = linstromRelation{
|
||||
Id: relation.ID,
|
||||
CreatedAt: relation.CreatedAt,
|
||||
UpdatedAt: relation.UpdatedAt,
|
||||
FromId: relation.FromId,
|
||||
ToId: relation.ToId,
|
||||
Accepted: relation.Accepted,
|
||||
Requested: true,
|
||||
}
|
||||
case storage.ErrEntryNotFound:
|
||||
outData = linstromRelation{
|
||||
Id: relation.ID,
|
||||
CreatedAt: relation.CreatedAt,
|
||||
UpdatedAt: relation.UpdatedAt,
|
||||
FromId: relation.FromId,
|
||||
ToId: relation.ToId,
|
||||
Accepted: false,
|
||||
Requested: false,
|
||||
}
|
||||
default:
|
||||
log.Error().
|
||||
Err(err).
|
||||
Str("from-id", targetId).
|
||||
Str("to-id", actorId).
|
||||
Msg("Failed to get follow relation")
|
||||
other.HttpErr(
|
||||
w,
|
||||
HttpErrIdDbFailure,
|
||||
"Failed to get relation",
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
}
|
||||
|
||||
err = jsonapi.MarshalPayload(w, outData)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to marshal response")
|
||||
other.HttpErr(
|
||||
w,
|
||||
HttpErrIdJsonMarshalFail,
|
||||
"Failed to marshal response",
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func linstromFollowAccount(w http.ResponseWriter, r *http.Request) {}
|
||||
func linstromUnfollowAccount(w http.ResponseWriter, r *http.Request) {}
|
||||
|
||||
func linstromIsBlockingAccount(w http.ResponseWriter, r *http.Request) {}
|
||||
func linstromBlockAccount(w http.ResponseWriter, r *http.Request) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue