Skip to content

Commit

Permalink
[Feature/400] 알림 설정 및 조회 API 구현 (#405)
Browse files Browse the repository at this point in the history
* feat: 알림 설정 및 조회 API 구현

* feat: 주석 추가

* feat: 응답 형태 변경

* feat: 웹훅 수정
  • Loading branch information
injoon2019 authored Sep 10, 2024
1 parent a731b51 commit f759bf3
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 12 deletions.
46 changes: 34 additions & 12 deletions .github/workflows/pull-request-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,44 @@ jobs:
env:
DATA: |
{
"content": "<@&${{ secrets.DISCORD_ROLE_ID }}>",
"embeds": [
"blocks": [
{
"author": {
"name": ${{ toJson(github.event.sender.login) }},
"url": "https://github.com/${{ github.event.sender.login }}",
"icon_url": ${{ toJson(github.event.sender.avatar_url) }}
},
"title": ${{ toJson(github.event.pull_request.title) }},
"description": ${{ toJson(github.event.pull_request.body) }},
"url": ${{ toJson(github.event.pull_request.html_url) }},
"color": 65280
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*서버 PR* :bell: <@U07L8AX9B4N><@U07L87A3WKY>"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Author:*\n<https://github.com/${{ github.event.sender.login }}|${{ github.event.sender.login }}>"
},
{
"type": "mrkdwn",
"text": "*Title:*\n${{ github.event.pull_request.title }}"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Description:*\n${{ github.event.pull_request.body }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Pull Request URL:*\n<${{ github.event.pull_request.html_url }}|View PR>"
}
}
]
}
run: |
curl -X POST -H 'Content-type: application/json' \
-d "$DATA" \
${{ secrets.DISCORD_WEBHOOK_URL }}
${{ secrets.SLACK_WEBHOOK_URL }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package com.nexters.bottles.api.user.controller
import com.nexters.bottles.api.global.interceptor.AuthRequired
import com.nexters.bottles.api.global.resolver.AuthUserId
import com.nexters.bottles.api.user.facade.UserFacade
import com.nexters.bottles.api.user.facade.dto.AlimyOnOffRequest
import com.nexters.bottles.api.user.facade.dto.AlimyResponse
import com.nexters.bottles.api.user.facade.dto.BlockContactListRequest
import com.nexters.bottles.api.user.facade.dto.ReportUserRequest
import io.swagger.annotations.ApiOperation
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
Expand All @@ -30,4 +33,18 @@ class UserController(
fun blockContactList(@AuthUserId userId: Long, @RequestBody blockContactListRequest: BlockContactListRequest) {
userFacade.blockContactList(userId, blockContactListRequest.blockContacts)
}

@ApiOperation("알림 설정")
@PostMapping("/alimy")
@AuthRequired
fun turnOnOffAlimy(@AuthUserId userId: Long, @RequestBody alimyOnOffRequest: AlimyOnOffRequest) {
userFacade.turnOnOffAlimy(userId, alimyOnOffRequest)
}

@ApiOperation("알림 설정 조회")
@GetMapping("/alimy")
@AuthRequired
fun turnOnOffAlimy(@AuthUserId userId: Long): List<AlimyResponse> {
return userFacade.getAlimy(userId)
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.nexters.bottles.api.user.facade

import com.nexters.bottles.api.user.facade.dto.AlimyOnOffRequest
import com.nexters.bottles.api.user.facade.dto.AlimyResponse
import com.nexters.bottles.api.user.facade.dto.ReportUserRequest
import com.nexters.bottles.app.user.domain.BlockContact
import com.nexters.bottles.app.user.domain.UserAlimy
import com.nexters.bottles.app.user.domain.UserReport
import com.nexters.bottles.app.user.service.BlockContactListService
import com.nexters.bottles.app.user.service.UserAlimyService
import com.nexters.bottles.app.user.service.UserReportService
import org.springframework.stereotype.Component

@Component
class UserFacade(
private val userReportService: UserReportService,
private val blockContactListService: BlockContactListService,
private val alimyService: UserAlimyService,
) {


Expand All @@ -33,4 +38,13 @@ class UserFacade(
blockContactListService.saveAll(newBlockContacts)
blockContactListService.deleteAll(deletedBlockContacts)
}

fun turnOnOffAlimy(userId: Long, alimyOnOffRequest: AlimyOnOffRequest) {
alimyService.turnOnOffAlimy(userId, alimyOnOffRequest.alimyType, alimyOnOffRequest.enabled)
}

fun getAlimy(userId: Long): List<AlimyResponse> {
return alimyService.findAlimies(userId)
.map { AlimyResponse(it.alimyType, it.enabled) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nexters.bottles.api.user.facade.dto

import com.nexters.bottles.app.user.domain.enum.AlimyType

data class AlimyOnOffRequest(
val alimyType: AlimyType,
val enabled: Boolean,
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nexters.bottles.api.user.facade.dto

import com.nexters.bottles.app.user.domain.enum.AlimyType

data class AlimyResponse(
val alimyType: AlimyType,
val enabled: Boolean,
) {
}
12 changes: 12 additions & 0 deletions api/src/main/resources/sql/ddl/table_query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,15 @@ CREATE TABLE block_contact
INDEX idx_created_at (created_at),
INDEX idx_updated_at (updated_at)
);

CREATE TABLE user_alimy
(
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
alimy_type VARCHAR(100) NOT NULL comment 'DAILY_RANDOM, RECEIVE_LIKE, PINGPONG, MARKETING',
enabled BOOLEAN NOT NULL DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

UNIQUE KEY unique_user_alimy (user_id, alimy_type)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.nexters.bottles.app.user.domain

import com.nexters.bottles.app.common.BaseEntity
import com.nexters.bottles.app.user.domain.enum.AlimyType
import org.springframework.data.relational.core.mapping.Table
import javax.persistence.*

@Entity
data class UserAlimy(

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0L,

val userId: Long,

@Enumerated(EnumType.STRING)
val alimyType: AlimyType,

val enabled: Boolean = true,
): BaseEntity() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nexters.bottles.app.user.domain.enum

enum class AlimyType {
DAILY_RANDOM, // 떠다니는 보틀 알림
RECEIVE_LIKE, // 호감 도착 알림
PINGPONG, // 대화 알림
MARKETING, // 마케팅 수신 동의
;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.nexters.bottles.app.user.repository

import com.nexters.bottles.app.user.domain.UserAlimy
import com.nexters.bottles.app.user.domain.enum.AlimyType
import org.springframework.data.jpa.repository.JpaRepository

interface UserAlimyRepository: JpaRepository<UserAlimy, Long> {

fun findByUserIdAndAlimyType(userId: Long, alimyType: AlimyType): UserAlimy?

fun findAllByUserId(userId: Long): List<UserAlimy>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.nexters.bottles.app.user.service

import com.nexters.bottles.app.user.domain.UserAlimy
import com.nexters.bottles.app.user.domain.enum.AlimyType
import com.nexters.bottles.app.user.repository.UserAlimyRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class UserAlimyService(
private val userAlimyRepository: UserAlimyRepository,
) {
@Transactional
fun turnOnOffAlimy(userId: Long, alimyType: AlimyType, enabled: Boolean) {
userAlimyRepository.findByUserIdAndAlimyType(userId, alimyType)?.let {
userAlimyRepository.save(
UserAlimy(userId = userId, alimyType = alimyType, enabled = enabled)
)
} ?: run {
userAlimyRepository.save(
UserAlimy(userId = userId, alimyType = alimyType, enabled = enabled)
)
}
}

@Transactional(readOnly = true)
fun findAlimies(userId: Long): List<UserAlimy> {
return userAlimyRepository.findAllByUserId(userId)
}
}

0 comments on commit f759bf3

Please sign in to comment.