I don't think this should preclude a happy ending.
From what you write, it looks to me like a girl, that was not even "dating or anything" boy X but was "in love" with him, had sex with another boy Y. Perhaps she was drunk or high. Perhaps she had some previous relationship with boy Y and it went further.
To my mind, there is no relationship, she and boy X haven't done anything to suggest they are supposed to be faithful. It is implausible for readers to believe they have sworn undying fidelity before their first kiss or date. She may regret having sex with boy Y, but she wasn't cheating and boy Y had no right to believe she was.
You haven't told us enough to make his rejection of her plausible, unless he is just a prude and cannot forgive her for having sex without love of this other boy. This might be due to a repressed culture, as well.
But in the USA, the average age at which women lose their virginity is 16.3 years, and the average age of first marriage in the USA is currently 27 (women) and 29 (men). That is a good 10 years after, and ten sexually active years for most of them. Somehow, all those men and women getting married have "gotten over" their spouse's previous sexual lives, if they even felt there was something to get over. It is not at all common, in the USA, for either men or women to marry as virgins, but they do get married and after that most of them remain faithful to their spouse while married.
There is no reason your story cannot have a happy ending, this all depends on whether the girl has a good excuse for her tryst with boy Y. You can make boy X a jerk, or worthy of love for putting whatever hurt he felt aside in order to try again with her. If he actually DOES love her, then he should be willing to make that sacrifice, otherwise he's a prude and a jerk, whose ego is more important to him than either his own happiness or the happiness of the girl he supposedly loves. That is some kind of mental illness, in my book.