tsk-35: Add API documentation (#39)

Closes #35

Reviewed-on: phoenix/textsender-api#39
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-11-13 21:45:17 +00:00
committed by phoenix
parent 0cd71c5506
commit f69d56f527
14 changed files with 2597 additions and 23 deletions
+29 -5
View File
@@ -33,6 +33,17 @@ func NewMessageHandler(str store.MessageStore) *MessageHandler {
return &MessageHandler{MessageStore: str}
}
// AddMessage godoc
// @Summary Add message
// @Description Add a message record to send a text to (requires JWT)
// @Tags messages
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param request body RequestAddMessage true "Data to add message"
// @Success 201 {object} AddMessageResponse
// @Failure 500 {object} AddMessageResponse
// @Router /message/new [post]
func (m *MessageHandler) AddMessage(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
@@ -64,6 +75,19 @@ func (m *MessageHandler) AddMessage(w http.ResponseWriter, r *http.Request) {
RespondWithJSON(w, statusCode, &resp)
}
// GetMessage godoc
// @Summary Get message
// @Description Get a message record to have a recipient to send a text to (requires JWT)
// @Tags messages
// @Accept json
// @Produce json
// @Param id path string true "Message Id"
// @Param user_id path string true "User Id"
// @Security BearerAuth
// @Success 200 {object} GetMessageResponse
// @Failure 400 {object} GetMessageResponse
// @Failure 500 {object} GetMessageResponse
// @Router /message [get]
func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
@@ -114,10 +138,10 @@ func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
}
} else if userId != uuid.Nil {
fmt.Println("Checking with User Id")
if contacts, err := c.MessageStore.GetAllMessages(ctx); err == nil {
for _, con := range contacts {
if con.UserId == userId {
resp.Data = append(resp.Data, *con)
if messages, err := c.MessageStore.GetAllMessages(ctx); err == nil {
for _, msg := range messages {
if msg.UserId == userId {
resp.Data = append(resp.Data, *msg)
}
}
@@ -126,7 +150,7 @@ func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
resp.Message = "Successful"
} else {
statusCode = http.StatusNotFound
resp.Message = "Contact not found"
resp.Message = "Message not found"
}
} else {
statusCode = http.StatusInternalServerError