groupware: add getting a contact by ID + add integration tests for contacts

This commit is contained in:
Pascal Bleser
2025-11-07 16:13:39 +01:00
parent 6e5ff678ee
commit b9bce2fb70
9 changed files with 1185 additions and 13 deletions

View File

@@ -148,6 +148,32 @@ func (g *Groupware) GetContactsInAddressbook(w http.ResponseWriter, r *http.Requ
})
}
func (g *Groupware) GetContactById(w http.ResponseWriter, r *http.Request) {
g.respond(w, r, func(req Request) Response {
ok, accountId, resp := req.needContactWithAccount()
if !ok {
return resp
}
l := req.logger.With()
contactId := chi.URLParam(r, UriParamContactId)
l = l.Str(UriParamContactId, log.SafeString(contactId))
logger := log.From(l)
contactsById, sessionState, state, lang, jerr := g.jmap.GetContactCardsById(accountId, req.session, req.ctx, logger, req.language(), []string{contactId})
if jerr != nil {
return req.errorResponseFromJmap(jerr)
}
if contact, ok := contactsById[contactId]; ok {
return etagResponse(contact, sessionState, state, lang)
} else {
return notFoundResponse(sessionState)
}
})
}
func (g *Groupware) CreateContact(w http.ResponseWriter, r *http.Request) {
g.respond(w, r, func(req Request) Response {
ok, accountId, resp := req.needContactWithAccount()

View File

@@ -148,6 +148,7 @@ func (g *Groupware) Route(r chi.Router) {
r.Route("/contacts", func(r chi.Router) {
r.Post("/", g.CreateContact)
r.Delete("/{contactid}", g.DeleteContact)
r.Get("/{contactid}", g.GetContactById)
})
r.Route("/calendars", func(r chi.Router) {
r.Get("/", g.GetCalendars)