@@ -151,7 +151,34 @@ async def get_custom_values(
151151 return [
152152 CustomColumnValueResponse (
153153 column_id = str (v .column_id ), column_slug = slug ,
154- target_id = str (v .target_id ), session_date = v .session_date ,
154+ target_id = str (v .target_id ) if v .target_id else None ,
155+ mosaic_id = str (v .mosaic_id ) if v .mosaic_id else None ,
156+ session_date = v .session_date ,
157+ rig_label = v .rig_label , value = v .value ,
158+ updated_by = str (v .updated_by ), updated_at = v .updated_at ,
159+ )
160+ for v , slug in rows
161+ ]
162+
163+
164+ @router .get ("/values/mosaic/{mosaic_id}" , response_model = list [CustomColumnValueResponse ])
165+ async def get_mosaic_custom_values (
166+ mosaic_id : uuid .UUID ,
167+ session : AsyncSession = Depends (get_session ),
168+ user : User = Depends (get_current_user ),
169+ ):
170+ q = (
171+ select (CustomColumnValue , CustomColumn .slug )
172+ .join (CustomColumn )
173+ .where (CustomColumnValue .mosaic_id == mosaic_id )
174+ )
175+ rows = (await session .execute (q )).all ()
176+ return [
177+ CustomColumnValueResponse (
178+ column_id = str (v .column_id ), column_slug = slug ,
179+ target_id = str (v .target_id ) if v .target_id else None ,
180+ mosaic_id = str (v .mosaic_id ) if v .mosaic_id else None ,
181+ session_date = v .session_date ,
155182 rig_label = v .rig_label , value = v .value ,
156183 updated_by = str (v .updated_by ), updated_at = v .updated_at ,
157184 )
@@ -166,7 +193,8 @@ async def set_custom_value(
166193 user : User = Depends (get_current_user ),
167194):
168195 col_id = uuid .UUID (body .column_id )
169- target_id = uuid .UUID (body .target_id )
196+ target_id = uuid .UUID (body .target_id ) if body .target_id else None
197+ mosaic_id = uuid .UUID (body .mosaic_id ) if body .mosaic_id else None
170198
171199 col = await session .get (CustomColumn , col_id )
172200 if not col :
@@ -179,8 +207,15 @@ async def set_custom_value(
179207
180208 conditions = [
181209 CustomColumnValue .column_id == col_id ,
182- CustomColumnValue .target_id == target_id ,
183210 ]
211+ if target_id is not None :
212+ conditions .append (CustomColumnValue .target_id == target_id )
213+ else :
214+ conditions .append (CustomColumnValue .target_id .is_ (None ))
215+ if mosaic_id is not None :
216+ conditions .append (CustomColumnValue .mosaic_id == mosaic_id )
217+ else :
218+ conditions .append (CustomColumnValue .mosaic_id .is_ (None ))
184219 if body .session_date is not None :
185220 conditions .append (CustomColumnValue .session_date == body .session_date )
186221 else :
@@ -201,6 +236,7 @@ async def set_custom_value(
201236 val = CustomColumnValue (
202237 column_id = col_id ,
203238 target_id = target_id ,
239+ mosaic_id = mosaic_id ,
204240 session_date = body .session_date ,
205241 rig_label = body .rig_label ,
206242 value = body .value ,
0 commit comments