@@ -38,68 +38,54 @@ func (s *Search) SearchDeployments(c *gin.Context) {
3838 ctx := c .Request .Context ()
3939
4040 var (
41- statuses = c .DefaultQuery ("statuses" , "" )
42- owned = c .DefaultQuery ("owned" , "true" )
43- from = c .DefaultQuery ("from" , time .Now ().Add (- activeDuration ).Format (time .RFC3339 ))
44- to = c .DefaultQuery ("to" , time .Now ().Format (time .RFC3339 ))
45- page = c .DefaultQuery ("page" , "1" )
46- perPage = c .DefaultQuery ("per_page" , "30" )
47- )
48-
49- var (
50- ss = make ([]deployment.Status , 0 )
51- o bool
52- f time.Time
53- t time.Time
54- p int
55- pp int
56- err error
41+ statuses = []deployment.Status {}
42+ owned bool
43+ productionOnly bool
44+ from , to time.Time
45+ page , perPage int
46+ err error
5747 )
5848
5949 // Validate query parameters.
60- for _ , st := range strings .Split (statuses , "," ) {
61- if st != "" {
62- ss = append (ss , deployment .Status (st ))
50+ for _ , s := range strings .Split (c . DefaultQuery ( " statuses" , "" ) , "," ) {
51+ if s != "" {
52+ statuses = append (statuses , deployment .Status (s ))
6353 }
6454 }
6555
66- if o , err = strconv .ParseBool (owned ); err != nil {
67- gb .ResponseWithError (
68- c ,
69- e .NewErrorWithMessage (e .ErrorCodeParameterInvalid , "The owned must be boolean." , err ),
70- )
56+ if owned , err = strconv .ParseBool (c .DefaultQuery ("owned" , "true" )); err != nil {
57+ gb .ResponseWithError (c , e .NewErrorWithMessage (e .ErrorCodeParameterInvalid , "The owned must be boolean." , err ))
58+ return
59+ }
60+
61+ if productionOnly , err = strconv .ParseBool (c .DefaultQuery ("production_only" , "false" )); err != nil {
62+ gb .ResponseWithError (c , e .NewErrorWithMessage (e .ErrorCodeParameterInvalid , "The production must be boolean." , err ))
7163 return
7264 }
7365
74- if f , err = time .Parse (time .RFC3339 , from ); err != nil {
66+ if from , err = time .Parse (time .RFC3339 , c . DefaultQuery ( " from" , time . Now (). Add ( - activeDuration ). Format ( time . RFC3339 )) ); err != nil {
7567 gb .ResponseWithError (
7668 c ,
7769 e .NewErrorWithMessage (e .ErrorCodeParameterInvalid , "Invalid format of \" from\" parameter, RFC3339 format only." , err ),
7870 )
7971 return
8072 }
8173
82- if t , err = time .Parse (time .RFC3339 , to ); err != nil {
74+ if to , err = time .Parse (time .RFC3339 , c . DefaultQuery ( "to" , time . Now (). Format ( time . RFC3339 )) ); err != nil {
8375 gb .ResponseWithError (
8476 c ,
8577 e .NewErrorWithMessage (e .ErrorCodeParameterInvalid , "Invalid format of \" to\" parameter, RFC3339 format only." , err ),
8678 )
8779 return
8880 }
8981
90- if p , err = strconv .Atoi (page ); err != nil {
91- gb .ResponseWithError (
92- c ,
93- e .NewErrorWithMessage (e .ErrorCodeParameterInvalid , "Invalid format of \" page\" parameter." , err ),
94- )
82+ if page , err = strconv .Atoi (c .DefaultQuery ("page" , "1" )); err != nil {
83+ gb .ResponseWithError (c , e .NewErrorWithMessage (e .ErrorCodeParameterInvalid , "The page must be number." , err ))
9584 return
9685 }
9786
98- if pp , err = strconv .Atoi (perPage ); err != nil {
99- gb .ResponseWithError (
100- c ,
101- e .NewErrorWithMessage (e .ErrorCodeParameterInvalid , "Invalid format of \" per_page\" parameter." , err ),
102- )
87+ if perPage , err = strconv .Atoi (c .DefaultQuery ("per_page" , "1" )); err != nil {
88+ gb .ResponseWithError (c , e .NewErrorWithMessage (e .ErrorCodeParameterInvalid , "The per_page must be number." , err ))
10389 return
10490 }
10591
@@ -112,11 +98,12 @@ func (s *Search) SearchDeployments(c *gin.Context) {
11298 u := v .(* ent.User )
11399
114100 if ds , err = s .i .SearchDeploymentsOfUser (ctx , u , & i.SearchDeploymentsOfUserOptions {
115- ListOptions : i.ListOptions {Page : p , PerPage : pp },
116- Statuses : ss ,
117- Owned : o ,
118- From : f ,
119- To : t ,
101+ ListOptions : i.ListOptions {Page : page , PerPage : perPage },
102+ Statuses : statuses ,
103+ Owned : owned ,
104+ ProductionOnly : productionOnly ,
105+ From : from ,
106+ To : to ,
120107 }); err != nil {
121108 s .log .Check (gb .GetZapLogLevel (err ), "Failed to search deployments." ).Write (zap .Error (err ))
122109 gb .ResponseWithError (c , err )
0 commit comments