Noun に行きます vs Verb に行きます — same に different job?

I understand 「学校に行きます」= going to school (Noun に 行きます). But then I saw 「公園に遊びに行きます」and got confused because there's a verb stem before 行きます too. Is に doing something different in each sentence, or is this basically two separate patterns that happen to share the word 行きます?
Post
沐學 Mizuru