Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a39b31

Browse files
authored
feat: Ability to request single models.File by id from api (#1740)
1 parentb3aea59 commit6a39b31

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎pkg/api/files.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,31 @@ func (i FilesResource) WebService() *restful.WebService {
5555
ws.Route(ws.POST("/unmatch").To(i.unmatchFile).
5656
Metadata(restfulspec.KeyOpenAPITags,tags))
5757

58+
ws.Route(ws.GET("/file/{file-id}").To(i.getFile).
59+
Param(ws.PathParameter("file-id","File ID").DataType("int")).
60+
Metadata(restfulspec.KeyOpenAPITags,tags).
61+
Writes(models.File{}))
62+
5863
ws.Route(ws.DELETE("/file/{file-id}").To(i.removeFile).
5964
Metadata(restfulspec.KeyOpenAPITags,tags))
6065

6166
returnws
6267
}
6368

69+
func (iFilesResource)getFile(req*restful.Request,resp*restful.Response) {
70+
varfile models.File
71+
72+
id,err:=strconv.Atoi(req.PathParameter("file-id"))
73+
iferr!=nil {
74+
log.Error(err)
75+
return
76+
}
77+
78+
_=file.GetIfExistByPK(uint(id))
79+
80+
resp.WriteHeaderAndEntity(http.StatusOK,file)
81+
}
82+
6483
func (iFilesResource)listFiles(req*restful.Request,resp*restful.Response) {
6584
db,_:=models.GetDB()
6685
deferdb.Close()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp