Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#86 - 사용자의 기본 프로필을 설정 및 차단된 유저의 프로필을 설정한다 #89

Merged
merged 26 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5b60b43
feat: 페이징 처리 될때 lastCursirId 응답 추가
sectionr0 Aug 9, 2024
c5c9e66
refactor: Gender Enum 추가
sectionr0 Aug 9, 2024
62a8a43
refactor: 프로필 API 스펙 변경
sectionr0 Aug 12, 2024
f66a8c6
feat: data.sql 추가
sectionr0 Aug 12, 2024
ac27dee
feat: 기본 프로필 추가
sectionr0 Aug 13, 2024
7373593
fix: test 오류 수정
sectionr0 Aug 13, 2024
9371341
chore: data 추가
kpeel5839 Aug 13, 2024
e183b27
test: beforeEach로도 테스트 데이터 삭제할 수 있도록 수정
kpeel5839 Aug 13, 2024
06e70df
test: 에러 픽스
kpeel5839 Aug 13, 2024
8df3169
chore: data.sql 수정
kpeel5839 Aug 13, 2024
d953284
test: test 수정
kpeel5839 Aug 13, 2024
462bfbd
chore: TimeZone 설정 추가
kpeel5839 Aug 13, 2024
e36a0ff
chore: test 설정 변경
kpeel5839 Aug 13, 2024
1adef4b
chore: 시간대 설정
kpeel5839 Aug 13, 2024
dc2c4e9
chore: profile 명시적으로 설정
kpeel5839 Aug 13, 2024
3c989bf
test: h2 database가 Timezone 설정을 따르지 않던 문제를 Profile 분리로써 해결
kpeel5839 Aug 13, 2024
92b3024
chore: application.yml sql mode를 설정한 이후, dev 서버에서 data.sql이 동작하지 않던 문…
kpeel5839 Aug 13, 2024
326bf9f
chore: data.sql 수정
kpeel5839 Aug 14, 2024
1491f1d
chore: data.sql 수정
kpeel5839 Aug 14, 2024
0ba533d
refactor: Receiver, Sender만 포함되게 요청을 보낼 수 있도록 수정
kpeel5839 Aug 14, 2024
88a2aa1
refactor: 차단된 iconurl 추가
sectionr0 Aug 14, 2024
b4b23cb
Merge branch 'feature/#86-profile-refactoring' of https://github.com/…
kpeel5839 Aug 14, 2024
b0378dd
chore: 서브모듈 커밋
kpeel5839 Aug 14, 2024
410bd89
fix: valid한 토큰을 보낼 수 있도록 수정
kpeel5839 Aug 15, 2024
c5b8aab
chore: data.sql vote 추가
kpeel5839 Aug 15, 2024
8dc9107
feat: FCM 저장 추가
kpeel5839 Aug 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/src/main/kotlin/com/wespot/config/TimeZoneConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.wespot.config

import jakarta.annotation.PostConstruct
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import java.util.*

@Configuration
@Profile("!local")
class TimeZoneConfig {

@PostConstruct
fun timeZoneSetUp() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"))
}

}
Comment on lines +8 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기천짱 미안해요. 여기다가 커밋 끼워넣었어잉 봐줘잉

image

이전에는 timezone 설정이 제대로 되어 있지 않아, 투표 독려도 정확하지 않은 시간에 들어갔었어요.

하지만, 이 설정으로 인해, 투표 독려가 실행되는 시각인 9,15,21시 중 9시에 정확히 잘 실행되는 것을 볼 수 있어요.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.wespot.user
import com.wespot.user.dto.response.BlockedUserResponse
import com.wespot.user.port.`in`.BlockedUserUseCase
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/resources/config
1,855 changes: 1,855 additions & 0 deletions app/src/main/resources/data.sql

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/src/test/kotlin/com/wespot/auth/fixture/AuthFixture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.wespot.auth.dto.request.SignUpRequest
import com.wespot.auth.dto.request.ConsentsRequest
import com.wespot.auth.dto.response.TokenResponse
import com.wespot.user.ConsentType
import com.wespot.user.Gender
import com.wespot.user.User
import com.wespot.user.fixture.UserFixture

Expand All @@ -15,7 +16,7 @@ object AuthFixture {
return SignUpRequest(
signUpToken = "signUpToken",
name = "Test User",
gender = "male",
gender = Gender.MALE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오우 쮓, 이거 Notification과 관련이 있는뎅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 좀만 커밋 밀어넣을게용 허허허 ^.^

consents = ConsentsRequest(
marketing = true
),
Expand Down
16 changes: 11 additions & 5 deletions app/src/test/kotlin/com/wespot/common/infra/TestContainer.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package com.wespot.common.infra

import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.jdbc.datasource.init.DataSourceInitializer
import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName
import javax.sql.DataSource


@TestConfiguration
class TestContainer {

companion object {
private const val REDIS_DOCKER_IMAGE: String = "redis:7.0.8-alpine"

init {
val REDIS_CONTAINER = GenericContainer(DockerImageName.parse(REDIS_DOCKER_IMAGE))
.withExposedPorts(6379)
.withReuse(true)
private val REDIS_CONTAINER = GenericContainer(DockerImageName.parse(REDIS_DOCKER_IMAGE))
.withExposedPorts(6379)
.withReuse(true)

init {
REDIS_CONTAINER.start()

System.setProperty("spring.data.redis.host", REDIS_CONTAINER.getHost())
System.setProperty("spring.data.redis.host", REDIS_CONTAINER.host)
System.setProperty("spring.data.redis.port", REDIS_CONTAINER.getMappedPort(6379).toString())
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ class IntegrationTest {
private var port: Int? = null

@Autowired
private var databaseCleanup: DatabaseCleanup? = null
private lateinit var databaseCleanup: DatabaseCleanup

@BeforeEach
fun setUp() {
RestAssured.port = port!!
databaseCleanup.execute()
}

@AfterEach
fun tearDown() {
databaseCleanup!!.execute()
databaseCleanup.execute()
}

}
3 changes: 2 additions & 1 deletion app/src/test/kotlin/com/wespot/common/service/ServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.wespot.common.service
import com.wespot.DatabaseCleanup
import com.wespot.common.infra.TestContainer
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.Import
Expand All @@ -12,7 +13,7 @@ import org.springframework.context.annotation.Import
class ServiceTest {

@Autowired
private lateinit var databaseCleanup: DatabaseCleanup
lateinit var databaseCleanup: DatabaseCleanup

@AfterEach
fun tearDown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package com.wespot.message.service
import com.wespot.auth.service.SecurityUtils
import com.wespot.message.Message
import com.wespot.message.MessageTimeValidator
import com.wespot.message.MessageType
import com.wespot.message.dto.response.*
import com.wespot.message.fixture.MessageFixture
import com.wespot.message.port.out.MessagePort
import com.wespot.school.School
import com.wespot.school.SchoolType
import com.wespot.school.fixture.SchoolFixture
import com.wespot.school.port.out.SchoolPort
import com.wespot.user.Profile
import com.wespot.user.User
import com.wespot.user.fixture.BlockedUserFixture
import com.wespot.user.fixture.UserFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.wespot.notification.domain.vote

import com.wespot.notification.NotificationType
import com.wespot.notification.vote.ReceivedVoteNotificationService
import com.wespot.user.Gender
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe
import java.time.LocalDate
Expand All @@ -11,7 +12,7 @@ class ReceivedVoteNotificationServiceTest : BehaviorSpec({
given("남학생이 투표를 완료했을 때") {
val service = ReceivedVoteNotificationService()
`when`("투표를 받은이에게") {
val notification = service.getNotification(100L, "female")
val notification = service.getNotification(100L, Gender.FEMALE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

머야 자기야 바꿔줬네? 대-박

then("알림이 발송된다.") {
notification.userId shouldBe 100L
notification.type shouldBe NotificationType.VOTE_RECEIVED
Expand All @@ -26,7 +27,7 @@ class ReceivedVoteNotificationServiceTest : BehaviorSpec({
given("여학생이 투표를 완료했을 때") {
val service = ReceivedVoteNotificationService()
`when`("투표를 받은이에게") {
val notification = service.getNotification(100L, "male")
val notification = service.getNotification(100L, Gender.MALE)
then("알림이 발송된다.") {
notification.userId shouldBe 100L
notification.type shouldBe NotificationType.VOTE_RECEIVED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class SavedReportServiceTest @Autowired constructor(
private val userJpaRepository: UserJpaRepository,
private val messageJpaRepository: MessageJpaRepository,
private val reportJpaRepository: ReportJpaRepository,
private val restrictionJpaRepository: RestrictionJpaRepository
) : ServiceTest() {

@Test
Expand Down
17 changes: 9 additions & 8 deletions app/src/test/kotlin/com/wespot/user/fixture/UserFixture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.wespot.user.SocialType
import com.wespot.user.User
import com.wespot.user.UserConsent
import com.wespot.user.UserIntroduction
import com.wespot.user.Gender
import com.wespot.user.dto.request.UpdateProfileRequest
import org.springframework.security.authentication.TestingAuthenticationToken
import org.springframework.security.core.context.SecurityContextHolder
Expand All @@ -29,7 +30,7 @@ object UserFixture {
role = Role.USER,
name = "TestUser",
introduction = UserIntroduction.from("hello"),
gender = "male",
gender = Gender.MALE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자기야 이걸로 인해서 Postman 스펙도 조금 바뀌었엉 확인해줘잉

schoolId = 1L,
grade = 1,
classNumber = 1,
Expand Down Expand Up @@ -64,7 +65,7 @@ object UserFixture {
role = Role.USER,
name = "TestUser",
introduction = UserIntroduction.from("hello"),
gender = "male",
gender = Gender.MALE,
schoolId = 1L,
grade = 1,
classNumber = 1,
Expand Down Expand Up @@ -98,7 +99,7 @@ object UserFixture {
role = Role.USER,
name = "Sender",
introduction = UserIntroduction.from("intro"),
gender = "M",
gender = Gender.MALE,
schoolId = 1L,
grade = 1,
classNumber = 1,
Expand Down Expand Up @@ -132,7 +133,7 @@ object UserFixture {
role = Role.USER,
name = "Receiver",
introduction = UserIntroduction.from("intro"),
gender = "M",
gender = Gender.MALE,
schoolId = 1L,
grade = 1,
classNumber = 1,
Expand Down Expand Up @@ -189,7 +190,7 @@ object UserFixture {
password = "password",
name = name,
introduction = UserIntroduction.from("소개 $id"),
gender = "M",
gender = Gender.MALE,
schoolId = schoolId,
profile = Profile(profileId, "", ""),
fcm = null,
Expand Down Expand Up @@ -227,7 +228,7 @@ object UserFixture {
role = Role.USER,
name = "TestUser",
introduction = UserIntroduction.from("hello"),
gender = "male",
gender = Gender.MALE,
schoolId = schoolId,
grade = grade,
classNumber = classNumber,
Expand Down Expand Up @@ -264,7 +265,7 @@ object UserFixture {
role = Role.USER,
name = "TestUser",
introduction = UserIntroduction.from("hello"),
gender = "male",
gender = Gender.MALE,
schoolId = schoolId,
grade = grade,
classNumber = classNumber,
Expand Down Expand Up @@ -301,7 +302,7 @@ object UserFixture {
role = Role.USER,
name = "TestUser",
introduction = UserIntroduction.from("hello"),
gender = "male",
gender = Gender.MALE,
schoolId = schoolId,
grade = grade,
classNumber = classNumber,
Expand Down
21 changes: 12 additions & 9 deletions app/src/test/kotlin/com/wespot/user/service/UserServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,26 @@ class UserServiceTest : BehaviorSpec({
val profileRequest = UserFixture.updateProfileRequest()

every { getLoginUser(userPort) } returns user
every { user.updateProfile(any()) } returns user.copy(
introduction = UserIntroduction.from(profileRequest.introduction)
)
every { profile.update(any(), any()) } returns profile.copy(
backgroundColor = profileRequest.profile.backgroundColor,
iconUrl = profileRequest.profile.iconUrl
)
every { user.updateProfile(any()) } answers {
user.copy(
introduction = profileRequest.introduction?.let { UserIntroduction.from(it) } ?: user.introduction,
profile = profile.copy(
backgroundColor = profileRequest.profile?.backgroundColor ?: user.profile.backgroundColor,
iconUrl = profileRequest.profile?.iconUrl ?: user.profile.iconUrl
)
)
}
every { profilePort.save(any()) } returns profile
every { userPort.save(any()) } returns user

userService.updateProfile(profileRequest)

then("프로필이 업데이트 되어야 한다") {
user.introduction.introduction shouldBe profileRequest.introduction
user.profile.backgroundColor shouldBe profileRequest.profile.backgroundColor
user.profile.iconUrl shouldBe profileRequest.profile.iconUrl
user.profile.backgroundColor shouldBe profileRequest.profile?.backgroundColor
user.profile.iconUrl shouldBe profileRequest.profile?.iconUrl
}
}

}
})
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,28 @@ class CreatedVoteServiceTest @Autowired constructor(
votes[0].voteNumber shouldBe 0
}

@Test
fun `학급에 처음으로 가입하지 않는 경우 투표를 더 이상 생성하지 않는다`() {
// given
userJpaRepository.deleteAll()
val savedUserJpaEntity1 = userJpaRepository.save(UserMapper.mapToJpaEntity(users[0]))
val savedUserJpaEntity2 = userJpaRepository.save(UserMapper.mapToJpaEntity(users[1]))
val savedUserDomainEntity1 = UserMapper.mapToDomainEntity(savedUserJpaEntity1)
val savedUserDomainEntity2 = UserMapper.mapToDomainEntity(savedUserJpaEntity2)

// when
createdVoteService.createVoteByUser(savedUserDomainEntity1)
createdVoteService.createVoteByUser(savedUserDomainEntity2)
val votes = voteJpaRepository.findAll()

// then
votes.size shouldBe 1
votes[0].schoolId shouldBe savedUserDomainEntity1.schoolId
votes[0].grade shouldBe savedUserDomainEntity1.grade
votes[0].classNumber shouldBe savedUserDomainEntity1.classNumber
votes[0].voteNumber shouldBe 0
}

@Test
fun `가입하지 않은 유저가 투표 생성을 요청할 경우 예외가 발생한다`() {
// given when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wespot.vote.service

import com.wespot.DatabaseCleanup
import com.wespot.common.service.ServiceTest
import com.wespot.user.entity.UserJpaEntity
import com.wespot.user.fixture.UserFixture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wespot.vote.service

import com.wespot.DatabaseCleanup
import com.wespot.common.service.ServiceTest
import com.wespot.notification.port.out.NotificationPort
import com.wespot.user.entity.UserJpaEntity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wespot.vote.service

import com.wespot.DatabaseCleanup
import com.wespot.common.service.ServiceTest
import com.wespot.user.entity.UserJpaEntity
import com.wespot.user.fixture.UserFixture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wespot.vote.service

import com.wespot.DatabaseCleanup
import com.wespot.common.service.ServiceTest
import com.wespot.user.entity.UserJpaEntity
import com.wespot.user.fixture.UserFixture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wespot.auth.dto.request

data class ProfileRequest(
val backgroundColor: String,
val iconUrl: String,
val backgroundColor: String?,
val iconUrl: String?,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.wespot.auth.dto.request

import com.wespot.user.Gender

data class SignUpRequest(
val name: String,
val gender: String,
val gender: Gender,
val schoolId: Long,
val grade: Int,
val classNumber: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package com.wespot.message.dto.response

data class MessageBlockedListResponse(
val messages: List<MessageBlockedResponse>,
val hasNext: Boolean
val hasNext: Boolean,
val lastCursorId: Long,
) {
companion object {

fun from(messages: List<MessageBlockedResponse>, hasNext: Boolean): MessageBlockedListResponse {
return MessageBlockedListResponse(
messages = messages,
hasNext = hasNext
hasNext = hasNext,
lastCursorId = messages.lastOrNull()?.id ?: 0L
Comment on lines +13 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳굳!

)
}

Expand Down
Loading
Loading