Lista de Narrativas-correcciones

This commit is contained in:
Christian Dacid Sullca Puma 2022-10-17 10:56:03 -05:00
parent 46a5276843
commit 9020aed4af

View File

@ -9,89 +9,91 @@
//edita solo contenido //edita solo contenido
//eliminar //eliminar
// Cabecera endopoint unico // Cabecera endopoint unico
class NarrativasController extends Controller{ class NarrativasController extends Controller
{
public function create(Request $request){ public function create(Request $request)
$request->validate([ {
"id_estandar"=> "required|integer", $request->validate([
"semestre"=> "required", "id_estandar" => "required|integer",
"contenido"=> "required", "semestre" => "required",
"contenido" => "required",
]); ]);
if(Estandar::where("id",$request->id_estandar)->exists()){ if (Estandar::where("id", $request->id_estandar)->exists()) {
$narrativa = new Narrativa(); $narrativa = new Narrativa();
$narrativa->id_estandar = $request->id_estandar; $narrativa->id_estandar = $request->id_estandar;
$narrativa->semestre = $request->semestre; $narrativa->semestre = $request->semestre;
$narrativa->contenido = $request->contenido; $narrativa->contenido = $request->contenido;
$narrativa->save(); $narrativa->save();
return response([ return response([
"status" => 1, "status" => 1,
"msg" => "!Narrativa creada exitosamente", "msg" => "!Narrativa creada exitosamente",
"data" => $narrativa, "data" => $narrativa,
]); ]);
} } else {
else{ return response([
return response([
"status" => 0,
"msg" => "!No se encontro el estandar",
],404);
}
}
public function update(Request $request){
$request->validate([
"id"=> "required",
"contenido"=> "required",
]);
if(Narrativa::where("id",$request->id)->exists()){
$narrativa = Narrativa::find($request->id);
$narrativa -> update([
"contenido" => $request->contenido,
]);
return response()->json($narrativa, 200);
}
else{
return response([
"status" => 0, "status" => 0,
"message" => "!No se encontro la narrativa", "msg" => "!No se encontro el estandar",
],404); ], 404);
} }
}
public function delete($id){
if(Narrativa::where("id",$id)->exists()){
$narrativa = Narrativa::find($id);
$narrativa ->delete();
return response([
"status" => 1,
"message" => "!Narrativa eliminada",
]);
}
else{
return response([
"status" => 0,
"message" => "!No se encontro la narrativa",
],404);
}
} }
public function show($id){ public function update(Request $request)
if(Narrativa::where("id",$id)->exists()){ {
$request->validate([
"id" => "required",
"contenido" => "required",
]);
if (Narrativa::where("id", $request->id)->exists()) {
$narrativa = Narrativa::find($request->id);
$narrativa->update([
"contenido" => $request->contenido,
]);
return response()->json($narrativa, 200);
} else {
return response([
"status" => 0,
"message" => "!No se encontro la narrativa",
], 404);
}
}
public function delete($id)
{
if (Narrativa::where("id", $id)->exists()) {
$narrativa = Narrativa::find($id);
$narrativa->delete();
return response([
"status" => 1,
"message" => "!Narrativa eliminada",
]);
} else {
return response([
"status" => 0,
"message" => "!No se encontro la narrativa",
], 404);
}
}
public function show($id)
{
if (Narrativa::where("id", $id)->exists()) {
$narrativa = Narrativa::find($id); $narrativa = Narrativa::find($id);
return response([ return response([
"status" => 1, "status" => 1,
"message" => "!Narrativa encontrada", "message" => "!Narrativa encontrada",
"data" => $narrativa, "data" => $narrativa,
]); ]);
} else {
return response([
"status" => 0,
"message" => "!No se encontro la narrativa",
], 404);
} }
else{ }
return response([ public function listNarrativas()
"status" => 0, {
"message" => "!No se encontro la narrativa", $narrativas = Narrativa::all();
],404);
}
}
public function listNarrativas(){
$narrativas = Narrativas::all();
return response([ return response([
"status" => 1, "status" => 1,
"msg" => "!Lista de Narrativas", "message" => "!Lista de narrativas",
"data" => $narrativas, "data" => $narrativas,
]); ]);
} }