3 files changed,
6 insertions(+),
26 deletions(-)
Author:
Smirnov Olexandr
ss2316544@gmail.com
Committed by:
GitHub
noreply@github.com
Committed at:
2025-06-30 18:29:48 +0300
Parent:
450a6a9
M
e2e/apiv1_notes_test.go
··· 139 139 e.Equal(dbNote.ReadAt.IsZero(), false) 140 140 } 141 141 142 -type apiv1NoteGetRequest struct { 143 - Password string `json:"password"` 144 -} 145 - 146 142 func (e *AppTestSuite) TestNoteV1_GetWithPassword() { 147 143 content := e.uuid() 148 144 passwd := e.uuid() ··· 161 157 162 158 httpResp = e.httpRequest( 163 159 http.MethodGet, 164 - "/api/v1/note/"+bodyCreated.Slug, 165 - e.jsonify(apiv1NoteGetRequest{ 166 - Password: passwd, 167 - }), 160 + "/api/v1/note/"+bodyCreated.Slug+"?password="+passwd, 161 + nil, 168 162 ) 169 163 e.Equal(httpResp.Code, http.StatusOK) 170 164 ··· 215 209 216 210 httpResp = e.httpRequest( 217 211 http.MethodGet, 218 - "/api/v1/note/"+bodyCreated.Slug, 219 - e.jsonify(apiv1NoteGetRequest{ 220 - Password: e.uuid(), 221 - }), 212 + "/api/v1/note/"+bodyCreated.Slug+"?password="+e.uuid(), 213 + nil, 222 214 ) 223 215 e.Equal(httpResp.Code, http.StatusNotFound) 224 216 }
M
internal/transport/http/apiv1/note.go
··· 1 1 package apiv1 2 2 3 3 import ( 4 - "errors" 5 - "io" 6 4 "net/http" 7 5 "time" 8 6 ··· 49 47 c.JSON(http.StatusCreated, createNoteResponse{slug}) 50 48 } 51 49 52 -type getNoteBySlugRequest struct { 53 - Password string `json:"password"` 54 -} 55 - 56 50 type getNoteBySlugResponse struct { 57 51 Content string `json:"content"` 58 52 ReadAt time.Time `json:"read_at,omitzero"` ··· 62 56 } 63 57 64 58 func (a *APIV1) getNoteBySlugHandler(c *gin.Context) { 65 - var req getNoteBySlugRequest 66 - if err := c.ShouldBindJSON(&req); err != nil && !errors.Is(err, io.EOF) { 67 - newError(c, http.StatusBadRequest, "invalid request") 68 - return 69 - } 70 - 71 59 note, err := a.notesrv.GetBySlugAndRemoveIfNeeded( 72 60 c.Request.Context(), 73 61 notesrv.GetNoteBySlugInput{ 74 62 Slug: c.Param("slug"), 75 - Password: req.Password, 63 + Password: c.Query("password"), 76 64 }, 77 65 ) 78 66 if err != nil {