Skip to content

Commit

Permalink
Merge pull request #13 from ondosee/12-feature/save-notification
Browse files Browse the repository at this point in the history
디바이스(FCM) 토큰 저장 API 구현
  • Loading branch information
uuuuuuuk authored Sep 15, 2024
2 parents ff40ac1 + d4a5961 commit 4f1963e
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ondosee-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ jobs:
redis-version: 7
redis-port: 6379

- name: Set up MariaDB
uses: getong/[email protected]
with:
host-port: 3306
mariadb-database: 'ondosee'
mariadb-user: 'ondosee-admin'
mariadb-password: ${{ secrets.MARIA_DB_PASSWORD }}

- name: Grant MariaDB permissions
run: |
sudo apt-get install mariadb-client
mysql -h 127.0.0.1 -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'ondosee-admin'@'%' IDENTIFIED BY '${{ secrets.MARIA_DB_PASSWORD }}'; FLUSH PRIVILEGES;"
- name: Create 'ondosee' database
run: |
sudo apt-get install mariadb-client
mysql -h 127.0.0.1 -u ondosee-admin -p${{ secrets.MARIA_DB_PASSWORD }} -e "CREATE DATABASE IF NOT EXISTS ondosee;"
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ dependencies {
implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.0")
implementation("io.github.openfeign:feign-core:11.8")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ondosee.common.adapter.notification

import com.ondosee.common.spi.notification.CommandNotificationPort
import com.ondosee.common.spi.notification.QueryNotificationPort
import com.ondosee.domain.notification.domain.entity.Notification
import org.springframework.stereotype.Component

@Component
class CommandNotificationAdapter(
private val queryNotificationPort: QueryNotificationPort
) : CommandNotificationPort {

override fun saveDeviceToken(deviceToken: String) {

val notification = Notification(
deviceToken = deviceToken,
alarmTime = null
)

queryNotificationPort.saveNotification(notification)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ondosee.common.adapter.notification

import com.ondosee.common.spi.notification.QueryNotificationPort
import com.ondosee.domain.notification.domain.entity.Notification
import com.ondosee.domain.notification.domain.repository.NotificationRepository
import org.springframework.stereotype.Component

@Component
class QueryNotificationAdapter(
private val notificationRepository: NotificationRepository
) : QueryNotificationPort {

override fun saveNotification(notification: Notification): Notification {

return notificationRepository.save(notification)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ondosee.common.spi.notification

interface CommandNotificationPort {
fun saveDeviceToken(deviceToken: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ondosee.common.spi.notification

import com.ondosee.domain.notification.domain.entity.Notification

interface QueryNotificationPort {
fun saveNotification(notification: Notification): Notification
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ondosee.domain.notification.domain.entity

import java.time.LocalDateTime
import javax.persistence.*

@Entity
@Table(name = "notification")
data class Notification(
@Id
@Column(name = "notification_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,

@Column(name = "device_token")
val deviceToken: String,

@Column(name = "alarm_time")
var alarmTime: LocalDateTime?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ondosee.domain.notification.domain.repository

import com.ondosee.domain.notification.domain.entity.Notification
import org.springframework.data.repository.CrudRepository

interface NotificationRepository : CrudRepository<Notification, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ondosee.domain.notification.presentation

import com.ondosee.domain.notification.service.NotificationService
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/notification")
class NotificationController(
private val notificationService: NotificationService
) {
@PostMapping
fun saveNotification(@RequestParam deviceToken: String): ResponseEntity<Void> =
notificationService.saveNotification(deviceToken)
.let { ResponseEntity.status(HttpStatus.CREATED).build() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ondosee.domain.notification.service

interface NotificationService {
fun saveNotification(deviceToken: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ondosee.domain.notification.service

import com.ondosee.common.spi.notification.CommandNotificationPort
import org.springframework.stereotype.Service

@Service
class NotificationServiceImpl(
private val commandNotificationPort: CommandNotificationPort
) : NotificationService {
override fun saveNotification(deviceToken: String) {
commandNotificationPort.saveDeviceToken(deviceToken)
}
}
15 changes: 15 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ spring:
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}


datasource:
driver-class-name: ${DB_DRIVER}
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}

jpa:
hibernate:
ddl-auto: ${JPA_DDL_AUTO}
show-sql: true
properties:
hibernate:
format_sql: true

vworld:
key: ${VWORLD_KEY}

Expand Down

0 comments on commit 4f1963e

Please sign in to comment.