Consider the first law of thermodynamics,
$$ dU = dq +dw$$
simplfying,
$$ dU + P_{\text{ext}} dV = dq$$
Now we can say that $ q $ is a function of $ U$ and $V$
$ dq(U,V) = dU + P_{\text{ext}} dV$
For a differential $dF(x,y) = A\, dx + B\, dy $ to be exact,
$$ \frac{\partial A}{\partial y} = \frac{\partial B}{\partial x}$$ is a necessary condition.
Clearly the function $q(U,V)$ doesn't obey this definition, and hence, let us multiply both sides by an integrating factor $ \phi(U,V)$ such that the condition of exact differential is satisfied.
$$ \phi(U,V) \, dq = \phi(U,V) \, dU + \phi(U,V) P_{\text{ext}} \, dV$$
For this to be exact,
$$ \frac{ \partial \phi(U,V) P_{\text{ext}} }{\partial U} = \frac{\partial \phi(U,V) }{\partial V}$$
Which leads to:
$$ \left( \frac{\partial P_{\text{ext}} }{ \partial U} \right)_V \phi + P_{\text{ext}}(\frac{\partial \phi}{\partial U})_V =(\frac{\partial \phi}{\partial V})_U $$
Now, I'm not sure how to get a general solution for the above partial differential equation...
My real goal is to derive the expression for entropy at end and prove that $ \frac{1}{T}$ is the integrating factor but I'm a bit stuck. I've seen the proof that $ \frac{1}{T}$ is the integrating factor by people pointing to carnots theorem that the circulation of the differentials over a loop is zero but I wanted to derive it using differential equations.
Now, I'm thinking of how I can include the assumption that the process is reversible because the entropy definition is written used $ dq_{\text{rev}}$; also maybe derive the entropy generation term.
Any hints?