@@ -17,7 +17,20 @@ public static function getMany()
17
17
return [
18
18
'type ' => Type::listOf (Types::consoleImage ()),
19
19
'description ' => 'Get many console image ' ,
20
- 'resolve ' => fn () => \App \Models \ConsoleImage::all ()
20
+ 'args ' => [[
21
+ 'name ' => 'all ' ,
22
+ 'description ' => 'If true, include unpublished images ' ,
23
+ 'type ' => Type::boolean (),
24
+ 'defaultValue ' => false
25
+ ]],
26
+ 'resolve ' => function (ContainerInterface $ container , $ args ) {
27
+ return \App \Models \ConsoleImage::all ()
28
+ ->filter (fn ($ image ) => $ args ['all ' ] || $ image ['is_available ' ])
29
+ ->map (function ($ image ) use ($ container ) {
30
+ $ image ['url ' ] = $ container ->get ('services ' )['os_endpoint ' ] . $ image ['path ' ];
31
+ return $ image ;
32
+ });
33
+ }
21
34
];
22
35
}
23
36
@@ -26,18 +39,17 @@ public static function getOne()
26
39
return [
27
40
'type ' => Types::consoleImage (),
28
41
'description ' => 'Get a console image ' ,
29
- 'args ' => [
30
- [
31
- 'name ' => 'id ' ,
32
- 'description ' => 'The Id of the console image ' ,
33
- 'type ' => Type::string ()
34
- ]
35
- ],
36
- 'resolve ' => function ($ _ , $ args ) {
37
- $ item = \App \Models \ConsoleImage::query ()->find ($ args ['id ' ]);
38
- if ($ item === NULL )
42
+ 'args ' => [[
43
+ 'name ' => 'id ' ,
44
+ 'description ' => 'The Id of the console image ' ,
45
+ 'type ' => Type::string ()
46
+ ]],
47
+ 'resolve ' => function (ContainerInterface $ container , $ args ) {
48
+ $ image = \App \Models \ConsoleImage::query ()->find ($ args ['id ' ]);
49
+ $ image ['url ' ] = $ container ->get ('services ' )['os_endpoint ' ] . $ image ['path ' ];
50
+ if ($ image === NULL )
39
51
return new Exception ("Unknown console image " , 404 );
40
- return $ item ;
52
+ return $ image ;
41
53
}
42
54
];
43
55
}
@@ -52,36 +64,40 @@ public static function store()
52
64
'saved ' => ['type ' => Type::boolean ()]
53
65
]
54
66
]),
55
- 'args ' => [
56
- [
57
- 'name ' => 'image ' ,
58
- 'description ' => 'Image to store ' ,
59
- 'type ' => Type::nonNull (new InputObjectType ([
60
- 'name ' => 'ConsoleImageStoreInput ' ,
61
- 'fields ' => [
62
- 'console_version ' => ['type ' => Type::nonNull (Type::string ())],
63
- 'software_version ' => ['type ' => Type::nonNull (Type::string ())],
64
- 'description ' => ['type ' => Type::string ()]
65
- ]
66
- ]))
67
- ]
68
- ],
67
+ 'args ' => [[
68
+ 'name ' => 'image ' ,
69
+ 'description ' => 'Image to store ' ,
70
+ 'type ' => Type::nonNull (new InputObjectType ([
71
+ 'name ' => 'ConsoleImageStoreInput ' ,
72
+ 'fields ' => [
73
+ 'console_version ' => ['type ' => Type::nonNull (Type::string ())],
74
+ 'software_version ' => ['type ' => Type::nonNull (Type::string ())],
75
+ 'size ' => ['type ' => Type::nonNull (Type::int ())],
76
+ 'hash ' => ['type ' => Type::nonNull (Type::string ())],
77
+ 'is_available ' => ['type ' => Type::boolean (), 'default_value ' => false ],
78
+ 'description ' => ['type ' => Type::string ()]
79
+ ]
80
+ ]))
81
+ ]],
69
82
'resolve ' => function (ContainerInterface $ container , $ args ) {
70
83
if (!$ container ->get (Session::class)->isAdmin ())
71
84
return new Exception ("Forbidden " , 403 );
72
85
73
86
$ image = new \App \Models \ConsoleImage ();
74
87
$ image ['id ' ] = uniqid ();
75
- $ image ->setAttributesFromGraphQL ($ args ['image ' ], ['console_version ' , 'software_version ' , 'description ' ]);
88
+ $ image ->setAttributesFromGraphQL (
89
+ $ args ['image ' ],
90
+ ['console_version ' , 'software_version ' , 'description ' , 'is_available ' , 'size ' , 'hash ' ]
91
+ );
76
92
77
- $ filter = array_filter ($ container ->get ('console-versions ' ), fn ($ v ) => $ v ['id ' ] === $ image ['console_version ' ]);
93
+ $ filter = array_filter ($ container ->get ('console-versions ' ), fn ($ v ) => $ v ['id ' ] === $ image ['console_version ' ]);
78
94
if (count ($ filter ) !== 1 )
79
95
return new Exception ("Unknown console version " , 404 );
80
96
81
97
$ image ->generateExtraFields ();
82
98
if (\App \Models \ConsoleImage::query ()
83
- ->where ('version ' , '= ' , $ image ['version ' ])
84
- ->count () !== 0 )
99
+ ->where ('version ' , '= ' , $ image ['version ' ])
100
+ ->count () !== 0 )
85
101
return new Exception ("Version already exists " , 400 );
86
102
87
103
return [
@@ -97,31 +113,36 @@ public static function update()
97
113
return [
98
114
'type ' => Type::boolean (),
99
115
'description ' => 'Update a console image ' ,
100
- 'args ' => [
101
- [
102
- 'name ' => 'image ' ,
103
- 'description ' => 'Console image to update ' ,
104
- 'type ' => Type::nonNull (new InputObjectType ([
105
- 'name ' => 'ConsoleImageUpdateInput ' ,
106
- 'fields ' => [
107
- 'id ' => ['type ' => Type::nonNull (Type::id ())],
108
- 'software_version ' => ['type ' => Type::string ()],
109
- 'description ' => ['type ' => Type::string ()]
110
- ]
111
- ]))
112
- ]
113
- ],
116
+ 'args ' => [[
117
+ 'name ' => 'image ' ,
118
+ 'description ' => 'Console image to update ' ,
119
+ 'type ' => Type::nonNull (new InputObjectType ([
120
+ 'name ' => 'ConsoleImageUpdateInput ' ,
121
+ 'fields ' => [
122
+ 'id ' => ['type ' => Type::nonNull (Type::id ())],
123
+ 'software_version ' => ['type ' => Type::string ()],
124
+ 'description ' => ['type ' => Type::string ()],
125
+ 'is_available ' => ['type ' => Type::boolean ()],
126
+ 'size ' => ['type ' => Type::int ()],
127
+ 'hash ' => ['type ' => Type::string ()]
128
+ ]
129
+ ]))
130
+ ]],
114
131
'resolve ' => function (ContainerInterface $ container , $ args ) {
115
132
if (!$ container ->get (Session::class)->isAdmin ())
116
133
return new Exception ("Forbidden " , 403 );
117
134
135
+ /* @var $image \App\Models\ConsoleImage */
118
136
$ image = \App \Models \ConsoleImage::query ()
119
137
->find ($ args ['image ' ]['id ' ]);
120
138
121
139
if ($ image === NULL )
122
140
return new Exception ("Unknown console image " , 404 );
123
141
124
- $ image ->setAttributesFromGraphQL ($ args ['image ' ], ['software_version ' , 'description ' ]);
142
+ $ image = $ image ->setAttributesFromGraphQL (
143
+ $ args ['image ' ],
144
+ ['software_version ' , 'description ' , 'is_available ' , 'size ' , 'hash ' ]
145
+ );
125
146
$ image ->generateExtraFields ();
126
147
127
148
if (\App \Models \ConsoleImage::query ()
@@ -140,7 +161,7 @@ public static function destroy()
140
161
return [
141
162
'type ' => Type::boolean (),
142
163
'args ' => [
143
- 'id ' => [ 'type ' => Type::nonNull (Type::id ()) ]
164
+ 'id ' => ['type ' => Type::nonNull (Type::id ())]
144
165
],
145
166
'resolve ' => function (ContainerInterface $ container , $ args ) {
146
167
if (!$ container ->get (Session::class)->isAdmin ())
0 commit comments