Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

[#11] 사용자의 언어레벨을 변경할 수 있는 기능구현 #28

Merged
merged 2 commits into from
Mar 1, 2021

Conversation

msugo1
Copy link
Collaborator

@msugo1 msugo1 commented Feb 26, 2021

Controller 계층 관련

LanguageController (new)

  • 사용자가 등록한 언어 레벨 변경 요청을 받을 modifyLanguageLevel 메소드 추가

Service 계층 관련

LanguageService (new)

  • 언어 레벨 변경 요청에 대한 로직을 처리할 modifyLevel 메소드 추가
  1. 등록된 언어 status 가 모국어(NATIVE) 인 언어들의 경우에는 레벨
    변경이 불가능 (예외)

  2. 필요시 여러 개의 언어레벨 변경 요청을 한번에 받아 처리해야
    @Transactional annotation 추가

Mapper 계층 관련

LanguageMapper

  • 서비스 계층에서 처리한 언어레벨 변경에 대한 요청을 DB에 반영하기 위한
    updateLevel 메소드 작성

LangaugeMapper.xml

  • 위의 메소드를 처리하기 위한 Query 추가

application.properties

  • Mybatis가 한 번에 여러 요청을 처리할 수 있도록 allowMultipleQueries 속성값 true
    추가

테스트 관련

  • 위에서 작성한 로직을 통합 테스트 할 클래스 추가

  • 포스트맨을 활용해 구현한 로직 테스트

Controller 계층 관련

* LanguageController (new)

- 사용자가 등록한 언어 레벨 변경 요청을 받을 `modifyLanguageLevel` 메소드 추가

Service 계층 관련

* LanguageService (new)

- 언어 레벨 변경 요청에 대한 로직을 처리할 `modifyLevel` 메소드 추가

1. 등록된 언어 status 가 `모국어(NATIVE)` 인 언어들의 경우에는 레벨
   변경이 불가능 (예외)

2. 필요시 여러 개의 언어레벨 변경 요청을 한번에 받아 처리해야
   `@Transactional` annotation 추가

Mapper 계층 관련

* LanguageMapper

- 서비스 계층에서 처리한 언어레벨 변경에 대한 요청을 DB에 반영하기 위한
  `updateLevel` 메소드 작성

* LangaugeMapper.xml

- 위의 메소드를 처리하기 위한 Query 추가

application.properties

* Mybatis가 한 번에 여러 요청을 처리할 수 있도록 `allowMultipleQueries` 속성값 true
  추가

테스트 관련

- 위에서 작성한 로직을 통합 테스트 할 클래스 추가

- 포스트맨을 활용해 구현한 로직 테스트
@msugo1 msugo1 self-assigned this Feb 26, 2021
@@ -27,4 +27,13 @@
SELECT langId, level FROM speak
WHERE userId = #{userId}
</select>

<update id="updateLevel" parameterType="map">
<foreach collection="langNewLevel" item="lang" separator=";">
Copy link
Member

Choose a reason for hiding this comment

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

이렇게하면 UPDATE 구문이 여러개가 실행될텐데 구문 한개로 같이 실행시킬 수 있는 방법은 없을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

조언주신대로 update ~ case when ~ then 을 이용해서 하나로 실행시키도록 변경하였습니다.

@@ -18,4 +18,10 @@ public void addLanguages(@CurrentUser String userId, @RequestBody LanguageDataWr

languageService.addLanguages(userId, languageDataWrapper.getDataList(), languageDataWrapper.getStatus());
}

@PutMapping
public void modifyLanguageLevel(@CurrentUser String userId, @RequestBody LanguageDataWrapper languageDataWrapper) {
Copy link
Member

Choose a reason for hiding this comment

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

여기서 LanguageDataWrapper는 Request용 클래스이니까 DataWrapper 보다는 LanguageModifyRequest 이런거로 해주는게 낫지 않을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

LanguageDataWrapper 클래스가 add/modify 시 모두 사용되는 점에 착안해서 LanguageUpsertRequest로 변경하였습니다.

- `LanguageDataWrapper -> LanguageUpsertRequest` 로 클래스 명칭 변경
: 사용자의 언어 추가/변경에 대한 요청에 사용되는 클래스로 그 용도가 더욱
명확해지도록

- `updateLevels` 쿼리 변경
: 기존에 개별로 실행되던 쿼리들을 `UPDATE ~ CASE WHEN ~ THEN`을 이용해
한 번에 실행되도록 변경

- 변수 이름 변경
@msugo1 msugo1 requested a review from f-lab-dev March 1, 2021 06:02
@msugo1 msugo1 added the Help Wanted Extra attention is needed label Mar 1, 2021
Copy link
Member

@f-lab-dev f-lab-dev left a comment

Choose a reason for hiding this comment

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

👍

@msugo1 msugo1 merged commit 9024cc3 into develop Mar 1, 2021
@msugo1 msugo1 deleted the feature/11 branch March 1, 2021 12:45
msugo1 pushed a commit that referenced this pull request Mar 15, 2021
Controller 계층 관련

* AlarmController

- 개별 알람 읽기 요청을 매핑할 `readAlarm` 메소드 추가

Service 계층 관련

* AlarmService

- 개별 알람 읽기 요청에 대한 비즈니스 로직을 처리할 `readAlarm` 메소드
  추가

- 알람이 존재하지 않는 경우 예외 발생

- 처음 알람을 읽을 때만 `hasRead` 값을 `Y`로 변경

Mapper 계층 관련

* AlarmMapper

- DB에서 개별 알람을 가져 올 `getAlarm` 메소드 추가

- 개별 알람을 읽은 경우 읽기 상태를 `Y`로 업데이트 하는 `updateToRead`
  메소드 추가

* AlarmMapper.xml

- 위의 내용을 처리할 쿼리 추가

예외 관련

* NoSuchAlarmException 클래스 추가

- 요청한 알람이 존재하지 않는 예외를 표시하기 위한 `NoSuchAlarmException` 클래스 추가

* ExceptionHandler에 예외 매핑

- 예외 제목과 메시지를 매핑 후 예외가 발생하면 상태코드 `404(Not
  Found)`를 리턴하도록 설정

테스트 관련

* AlarmServiceTest 추가

- 위의 로직을 테스트할 단위 테스트 작성

* 전체적인 로직을 포스트맨을 사용해 테스트
msugo1 pushed a commit that referenced this pull request Mar 15, 2021
* AlarmService

- 기존 로직: 테이블에서 한 row를 불러와 해당 알람에 대한 읽기 상태가
  'N' 인경우 'Y'로 업데이트 후 리턴

- 문제점: DB에 업데이트 반영 후 업데이트 전 객체를 리턴하므로 hasRead
  업데이트는 그 다음 읽어오기부터 반영도미

- 수정된 로직
1. 읽기 상태를 먼저 살펴본 다음 존재 하지 않으면 예외 처리
2. 존재하고 읽기 상태가 'N'인 경우만 'Y'로 업데이트
3. 해당 알람을 리턴

- 읽기 상태를 리턴하는 대신 존재여부를 불린으로 리턴하는 경우 hasRead
  상태 값이 체크되지 않아서 이전에 읽었던 읽지 않았던 'Y'로 업데이트
  하는 문제가 있었습니다.

- 때문에 읽기 상태를 처음에 리턴하는 것으로 알람의 존재여부와 상태값을
  모두 체크함으로써 이 문제를 해결하였습니다.

* 테스트에 로직 업데이트 내역 반영 및 테스트 구동/확인
@msugo1 msugo1 mentioned this pull request Mar 15, 2021
msugo1 pushed a commit that referenced this pull request Mar 16, 2021
* AlarmService

- 기존 로직: 테이블에서 한 row를 불러와 해당 알람에 대한 읽기 상태가
  'N' 인경우 'Y'로 업데이트 후 리턴

- 문제점: DB에 업데이트 반영 후 업데이트 전 객체를 리턴하므로 hasRead
  업데이트는 그 다음 읽어오기부터 반영도미

- 수정된 로직
1. 읽기 상태를 먼저 살펴본 다음 존재 하지 않으면 예외 처리
2. 존재하고 읽기 상태가 'N'인 경우만 'Y'로 업데이트
3. 해당 알람을 리턴

- 읽기 상태를 리턴하는 대신 존재여부를 불린으로 리턴하는 경우 hasRead
  상태 값이 체크되지 않아서 이전에 읽었던 읽지 않았던 'Y'로 업데이트
  하는 문제가 있었습니다.

- 때문에 읽기 상태를 처음에 리턴하는 것으로 알람의 존재여부와 상태값을
  모두 체크함으로써 이 문제를 해결하였습니다.

* 테스트에 로직 업데이트 내역 반영 및 테스트 구동/확인
msugo1 pushed a commit that referenced this pull request Mar 20, 2021
- `equals` 체크 시 상수를 먼저 써서 NPE를 방지할 수 있도록 변경
msugo1 added a commit that referenced this pull request Mar 21, 2021
[#28] 사용자의 개별 알람 읽기 기능 구현
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Help Wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[#11] 사용자가 추가한 언어에 대한 레벨을 변경할 수 있는 기능 구현하기
2 participants