This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enum 관련 * AlarmTypes 클래스 추가 - Alarm 관련 타입 상수를 담을 클래스 - DB에 저장 시 정수로, DB에서 꺼낼 때는 정식 명칭을 가진 상수로의 자동 변환을 위해 `TypeHandler` 구현 및 MyBatisConfig에 추가 Mapper 계층 관련 * AlarmMapper 인터페이스 추가 - 알람 추가 기능에 대한 로직 처리 후 이를 DB에 반영하기 위한 `insertAlarm` 메소드 추가 * AlarmMapper.xml 추가 - 위의 사항을 처리할 쿼리문 작성 Service 계층 관련 * AlarmService 클래스 추가 - 알람 추가 기능 요청에 대한 비즈니스 로직을 처리할 `addAlarm` 메소드 추가 - 알람 추가 요청을 받으면 보내는 대상과 받을 대상 그리고 알람 타입을 매핑해서 `Alarm 클래스의 인스턴스 생성` 후 Mapper로 넘김 * FriendService - AlarmService 주입 및 알람 추가가 필요한 메소드`(친구추가 요청, 친구수락 요청)들에addAlarm 코드 추가 테스트 관련 - 전체적인 내용을 포스트맨을 활용해 테스트
- Loading branch information
msugo1
committed
Mar 14, 2021
1 parent
d84e4dc
commit 6df61a8
Showing
9 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/me/soo/helloworld/enumeration/AlarmTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package me.soo.helloworld.enumeration; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import me.soo.helloworld.util.handler.EnumCategoryTypeHandler; | ||
import org.apache.ibatis.type.MappedTypes; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum AlarmTypes implements EnumCategory { | ||
|
||
FRIEND_REQUEST_RECEIVED(1), | ||
FRIEND_REQUEST_ACCEPTED(2); | ||
|
||
private final int category; | ||
|
||
@MappedTypes(AlarmTypes.class) | ||
public static class TypeHandler extends EnumCategoryTypeHandler<AlarmTypes> { | ||
|
||
public TypeHandler() { | ||
super(AlarmTypes.class); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package me.soo.helloworld.mapper; | ||
|
||
import me.soo.helloworld.model.alarm.Alarm; | ||
import org.apache.ibatis.annotations.Mapper; | ||
|
||
@Mapper | ||
public interface AlarmMapper { | ||
|
||
public void insertAlarm(Alarm alarm); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.soo.helloworld.model.alarm; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import me.soo.helloworld.enumeration.AlarmTypes; | ||
|
||
@Getter | ||
@Builder | ||
public class Alarm { | ||
|
||
private final String to; | ||
|
||
private final String from; | ||
|
||
private final AlarmTypes type; | ||
|
||
public static Alarm create(String userId, String targetId, AlarmTypes type) { | ||
|
||
return Alarm.builder() | ||
.from(userId) | ||
.to(targetId) | ||
.type(type) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package me.soo.helloworld.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import me.soo.helloworld.enumeration.AlarmTypes; | ||
import me.soo.helloworld.mapper.AlarmMapper; | ||
import me.soo.helloworld.model.alarm.Alarm; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AlarmService { | ||
|
||
private final AlarmMapper alarmMapper; | ||
|
||
public void addAlarm(String to, String from, AlarmTypes type) { | ||
Alarm alarm = Alarm.create(to, from, type); | ||
alarmMapper.insertAlarm(alarm); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
|
||
<mapper namespace="me.soo.helloworld.mapper.AlarmMapper"> | ||
|
||
<insert id="insertAlarm" parameterType="me.soo.helloworld.model.alarm.Alarm"> | ||
INSERT INTO alarms (alarmTo, alarmFrom, type) VALUES (#{to}, #{from}, #{type}) | ||
</insert> | ||
</mapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
create table alarms | ||
( | ||
id bigint auto_increment | ||
primary key, | ||
alarmTo varchar(20) not null, | ||
alarmFrom varchar(20) not null, | ||
type tinyint not null, | ||
hasRead enum ('Y', 'N') default 'N' not null, | ||
createdAt timestamp default CURRENT_TIMESTAMP not null | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package me.soo.helloworld; | ||
|
||
import me.soo.helloworld.enumeration.AlarmTypes; | ||
import me.soo.helloworld.mapper.AlarmMapper; | ||
import me.soo.helloworld.model.alarm.Alarm; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest | ||
public class AlarmMapperTest { | ||
private final String userId = "Soo1045"; | ||
|
||
private final String targetId = "Hello"; | ||
|
||
@Autowired | ||
AlarmMapper alarmMapper; | ||
|
||
@Test | ||
public void insertAlarmTest() { | ||
Alarm alarm = Alarm.create(userId, targetId, AlarmTypes.FRIEND_REQUEST_RECEIVED); | ||
|
||
alarmMapper.insertAlarm(alarm); | ||
} | ||
|
||
} |