[noun] + が/の + [verb (plain)] + [noun] [noun] + が/の + [i-adj] + [noun] [noun] + が/の + [na-adj] + な + [noun]
Inside a clause that describes a noun, the subject can take の instead of が, and the meaning stays the same. The clause ends in a plain form and sits right before the noun it describes.
The swap works only in a clause that describes a noun. In the main sentence, the subject keeps が.
The same goes for とき時, まえ前 and あと後, since they are nouns too.
の reads as "of" whenever it can, so keep が when an object with を comes between the subject and the verb. わたくし私のほん本をかった買ったみせ店 reads as "the shop that bought my book", not "the shop where I bought the book".