You may have received the phone in February, but the iPhone 7 was introduced in Sept 2016 and discontinued in Sept 2019.
Best case, the phone is 6+ old and as much as 9+ depending on when it was placed in service. Frankly, the time that you got the phone was about the same time that most phones need to be replaced due to age.
If you are saying the phone will not stay "on" unless it is connected to the charger, there is a problem with the battery or the power supply in the iPhone that will need attention at an authorized Apple service shop. Parts may....or may not....still be available for the phone.
If you tap on Settings > Battery > Battery Health & Charging, what is the reading that you see for Maximum Capacity?