Skip to content

Commit

Permalink
Add ads
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Oct 7, 2024
1 parent b3b0175 commit e8077ec
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class AuthService(
private val userRepository: UserRepository,
private val schoolRepository: SchoolRepository,
private val googleOAuth2Client: GoogleOAuth2Client,
private val googleOAuth2Helper: GoogleOAuth2Helper,
private val appleOAuth2Client: AppleOAuth2Client,
private val appleOAuth2Helper: AppleOAuth2Helper,
private val googleOAuth2Helper: GoogleOAuth2Helper,
private val jwtClient: JwtClient,
private val sessionHolder: UserAuthenticationHolder
private val authenticationHolder: UserAuthenticationHolder
) {
fun signIn(req: SignInReq): TokenRes {
val email = when (req.platformType) {
Expand All @@ -50,7 +50,7 @@ class AuthService(

fun signUp(req: SignUpReq): TokenRes {
val school = schoolRepository.getBy(req.schoolId)
val user = sessionHolder.current()
val user = authenticationHolder.current()

if (user.isActive) {
throw CustomException(HttpStatus.BAD_REQUEST, "User already sign in")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.bestswlkh0310.graduating.graduatingserver.api.meal
import com.bestswlkh0310.graduating.graduatingserver.api.meal.res.MealRes
import com.bestswlkh0310.graduating.graduatingserver.core.global.safeSaveAll
import com.bestswlkh0310.graduating.graduatingserver.core.meal.MealRepository
import com.bestswlkh0310.graduating.graduatingserver.core.school.SchoolRepository
import com.bestswlkh0310.graduating.graduatingserver.core.school.getBy
import com.bestswlkh0310.graduating.graduatingserver.core.user.UserAuthenticationHolder
import com.bestswlkh0310.graduating.graduatingserver.global.exception.CustomException
import com.bestswlkh0310.graduating.graduatingserver.infra.neis.meal.NeisMealClient
Expand All @@ -16,10 +14,10 @@ import java.time.LocalDate
class MealService(
private val mealRepository: MealRepository,
private val neisMealClient: NeisMealClient,
private val sessionHolder: UserAuthenticationHolder
private val authenticationHolder: UserAuthenticationHolder
) {
fun getMeals(): List<MealRes> {
val school = sessionHolder.current().school ?: throw CustomException(HttpStatus.NOT_FOUND, "Not found school")
val school = authenticationHolder.current().school ?: throw CustomException(HttpStatus.NOT_FOUND, "Not found school")

val currentTime = LocalDate.now()
val schools = mealRepository.findBySchoolIdAndMealDate(school.id, currentTime)
Expand Down
44 changes: 44 additions & 0 deletions Graduating-iOS/Graduating/Feature/Component/GoogleAdView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import SwiftUI
import GoogleMobileAds

public struct GoogleAdView: UIViewControllerRepresentable {
public func makeUIViewController(context: Context) -> UIViewController {
let viewController = UIViewController()
let bannerSize = GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(UIScreen.main.bounds.width)
let banner = GADBannerView(adSize: bannerSize)
banner.rootViewController = viewController
viewController.view.addSubview(banner)
viewController.view.frame = CGRect(origin: .zero, size: bannerSize.size)
#if DEBUG
banner.adUnitID = "ca-app-pub-3940256099942544/2435281174"
#else
banner.adUnitID = "ca-app-pub-2589637472995872/3554240467"
#endif
banner.load(GADRequest())
return viewController
}

public func updateUIViewController(_ viewController: UIViewController, context: Context) {}
}

public extension GoogleAdView {
struct BottomBannerPresenter<Banner: View, Label: View>: View {
public let banner: () -> Banner
public let label: () -> Label

public init(
@ViewBuilder banner: @escaping () -> Banner,
@ViewBuilder label: @escaping () -> Label
) {
self.banner = banner
self.label = label
}

public var body: some View {
VStack(spacing: 0) {
banner()
label()
}
}
}
}
15 changes: 10 additions & 5 deletions Graduating-iOS/Graduating/GraduatingApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ extension GraduatingApp {
datePickerProvider: datePickerProvider,
timePickerProvider: timePickerProvider
) {
NavigationStack(path: $router.path) {
if appState.shouldSignUp {
OnboardingCoordinator()
} else {
MainCoordinator()
GoogleAdView.BottomBannerPresenter {
GoogleAdView()
.frame(width: UIScreen.main.bounds.width, height: GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(UIScreen.main.bounds.width).size.height)
} label: {
NavigationStack(path: $router.path) {
if appState.shouldSignUp {
OnboardingCoordinator()
} else {
MainCoordinator()
}
}
}
}
Expand Down

0 comments on commit e8077ec

Please sign in to comment.