Skip to content

Commit

Permalink
Merge pull request #43 from Modagbul/feat/마이페이지
Browse files Browse the repository at this point in the history
Feat/마이페이지 설정 추가 및 소모임 가입 버그 수정
  • Loading branch information
minsu20 authored Oct 22, 2023
2 parents b40fc75 + 92caa13 commit 9b4fe17
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 19 deletions.
11 changes: 11 additions & 0 deletions src/docs/asciidoc/Mypage-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ Host: localhost:8080
{
"profileImage" : "PROFILE_IMAGE_URL"
}


[[Mypage-알람설정_조회]]
=== Mypage 알람설정 조회
operation::mypage-controller-test/get_alarm[snippets='http-request,http-response,response-fields']


[[Mypage-알람설정_수정]]
=== Mypage 알람설정 수정
operation::mypage-controller-test/update_alarm[snippets='http-request,http-response,request-parameters,response-fields']

20 changes: 20 additions & 0 deletions src/docs/asciidoc/Overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@
| `T0002`
| 소모임을 수정, 삭제하려고 할 때
| 소모임장이 아님 (권한 없음)

| `T0003`
| 소모임을 가입할 때
| 소모임을 이미 탈퇴함

| `T0004`
| 소모임을 가입할 때
| 소모임을 이미 가입함

|===

=== Board ErrorCode
Expand All @@ -108,6 +117,17 @@
| 작성자가 아님 (권한 없음)
|===

|===
| ErrorCode | Scope | Description
| `BC0001`
| API PATH에 boardId가 있을 때
| boardId가 유효하지 않음 (존재하지 않음)

| `BC0002`
| 게시글을 수정, 삭제하려고 할 때
| 작성자가 아님 (권한 없음)
|===

=== Mission ErrorCode
|===
| ErrorCode | Scope | Description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public void signUp(SignUpRequest signUpRequest) {
this.birthDate = LocalDate.parse(signUpRequest.getBirthDate(), DateTimeFormatter.ISO_DATE);;
this.fcmToken = signUpRequest.getFcmToken();
this.registrationStatus = RegistrationStatus.COMPLETED;
this.isNewUploadPush=true;
this.isFirePush=true;
this.isRemindPush=true;
}

@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.moing.backend.domain.mypage.application.service;

import com.moing.backend.domain.member.application.mapper.MemberMapper;
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.domain.mypage.application.dto.response.GetAlarmResponse;
import com.moing.backend.domain.mypage.exception.AlarmInvalidException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.transaction.Transactional;

Expand All @@ -15,10 +14,33 @@
@RequiredArgsConstructor
public class AlarmUserCase {

private MemberGetService memberGetService;
private final MemberGetService memberGetService;

public GetAlarmResponse getAlarm(String socialId){
Member member=memberGetService.getMemberBySocialId(socialId);
return new GetAlarmResponse(member.isNewUploadPush(),member.isRemindPush(), member.isFirePush());
}

public GetAlarmResponse updateAlarm(String socialId, String type, String status) {
Member member = memberGetService.getMemberBySocialId(socialId);
boolean push = "on".equals(status);

switch (type) {
case "all":
member.updateAllPush(push);
break;
case "isNewUploadPush":
member.updateNewUploadPush(push);
break;
case "isRemindPush":
member.updateRemindPush(push);
break;
case "isFirePush":
member.updateFirePush(push);
break;
default:
throw new AlarmInvalidException();
}
return new GetAlarmResponse(member.isNewUploadPush(),member.isRemindPush(), member.isFirePush());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.moing.backend.domain.mypage.exception;

import com.moing.backend.global.response.ErrorCode;
import org.springframework.http.HttpStatus;

public class AlarmInvalidException extends MyPageException {
public AlarmInvalidException() {
super(ErrorCode.INVALID_ALARM_ERROR,
HttpStatus.NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.moing.backend.domain.mypage.exception;

import com.moing.backend.global.exception.ApplicationException;
import com.moing.backend.global.response.ErrorCode;
import org.springframework.http.HttpStatus;

public abstract class MyPageException extends ApplicationException {
protected MyPageException(ErrorCode errorCode, HttpStatus httpStatus) {
super(errorCode, httpStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class MyPageController {
private final AlarmUserCase alarmUserCase;
private final GetMyPageUserCase getMyPageUserCase;

//TODO 알림설정 수정

/**
* 로그아웃
* [POST] api/mypage/signOut
Expand Down Expand Up @@ -95,4 +93,15 @@ public ResponseEntity<SuccessResponse<GetAlarmResponse>> getAlarm(@Authenticatio
return ResponseEntity.ok(SuccessResponse.create(GET_ALARM_SUCCESS.getMessage(), this.alarmUserCase.getAlarm(user.getSocialId())));
}

/**
* 알림정보 수정
* [POST] api/mypage/alarm?type=all || isNewUploadPush || isRemindPush || isFirePush && status= on || off
*/
@PutMapping("/alarm")
public ResponseEntity<SuccessResponse<GetAlarmResponse>> updateAlarm(@AuthenticationPrincipal User user,
@RequestParam(name = "type") String type,
@RequestParam(name = "status") String status) {
return ResponseEntity.ok(SuccessResponse.create(UPDATE_PROFILE_SUCCESS.getMessage(), this.alarmUserCase.updateAlarm(user.getSocialId(), type, status)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
public class TeamMemberSaveService {
private final TeamMemberRepository teamMemberRepository;
public void addTeamMember(Team team, Member member){
Optional<TeamMember> existingTeamMemberOpt = teamMemberRepository.findTeamMemberByTeamAndMember(team, member);

TeamMember teamMember = existingTeamMemberOpt.orElseGet(() -> {
Optional<TeamMember> teamMember = teamMemberRepository.findTeamMemberByTeamAndMember(team, member);
if (teamMember.isPresent()) {
if (teamMember.get().isDeleted()) {
throw new AlreadyWithdrawTeamException();
} else {
throw new AlreadyJoinTeamException();
}
} else {
TeamMember newMember = new TeamMember();
newMember.updateMember(member);
newMember.updateTeam(team);
team.addTeamMember();
return teamMemberRepository.save(newMember);
});

if (teamMember.isDeleted()) {
throw new AlreadyWithdrawTeamException();
} else {
throw new AlreadyJoinTeamException();
this.teamMemberRepository.save(newMember);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ public enum ErrorCode {
ALREADY_WITHDRAW_ERROR("T0003","이미 탈퇴한 회원입니다."),
ALREADY_JOIN_ERROR("T0004","이미 가입한 회원입니다."),

//마이페이지 관련 에러 코드
INVALID_ALARM_ERROR("MP0001","유효하지 않는 알람 입력값입니다"),

//게시글 관련 에러 코드
NOT_FOUND_BY_BOARD_ID_ERROR("B0001","해당 boardId인 게시글이 존재하지 않습니다."),
NOT_AUTH_BY_BOARD_ID_ERROR("B0002","권한이 없습니다."),

//게시글 댓글 관련 에러 코드
NOT_FOUND_BY_BOARD_COMMENT_ID_ERROR("B0001","해당 boardCommentId인 댓글이 존재하지 않습니다."),
NOT_AUTH_BY_BOARD_COMMENT_ID_ERROR("B0002","권한이 없습니다.");

NOT_FOUND_BY_BOARD_COMMENT_ID_ERROR("BC0001","해당 boardCommentId인 댓글이 존재하지 않습니다."),
NOT_AUTH_BY_BOARD_COMMENT_ID_ERROR("BC0002","권한이 없습니다.");
private String errorCode;
private String message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.moing.backend.config.CommonControllerTest;
import com.moing.backend.domain.mypage.application.dto.request.UpdateProfileRequest;
import com.moing.backend.domain.mypage.application.dto.request.WithdrawRequest;
import com.moing.backend.domain.mypage.application.dto.response.GetAlarmResponse;
import com.moing.backend.domain.mypage.application.dto.response.GetMyPageResponse;
import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock;
import com.moing.backend.domain.mypage.application.dto.response.GetProfileResponse;
import com.moing.backend.domain.mypage.application.service.*;
import com.moing.backend.domain.team.application.dto.response.CreateTeamResponse;
import com.moing.backend.domain.team.domain.constant.Category;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -23,6 +23,8 @@
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand Down Expand Up @@ -240,4 +242,87 @@ public void update_profile() throws Exception {
)
);
}


@Test
public void get_alarm() throws Exception {
//given
GetAlarmResponse output = GetAlarmResponse.builder()
.isNewUploadPush(true)
.isFirePush(true)
.isRemindPush(true)
.build();

given(alarmUserCase.getAlarm(any())).willReturn(output);

//when
ResultActions actions = mockMvc.perform(
get("/api/mypage/alarm")
.header("Authorization", "Bearer ACCESS_TOKEN")
.contentType(MediaType.APPLICATION_JSON)
);


//then
actions
.andExpect(status().isOk())
.andDo(
restDocs.document(
requestHeaders(
headerWithName("Authorization").description("접근 토큰")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
fieldWithPath("message").description("알람 정보를 조회했습니다"),
fieldWithPath("data.newUploadPush").description("신규 공지 알림"),
fieldWithPath("data.remindPush").description("미션 리마인드 알림"),
fieldWithPath("data.firePush").description("불 던지기 알림")
)
)
);
}

@Test
public void update_alarm() throws Exception {
//given
GetAlarmResponse output = GetAlarmResponse.builder()
.isNewUploadPush(true)
.isFirePush(true)
.isRemindPush(true)
.build();

given(alarmUserCase.updateAlarm(any(),any(),any())).willReturn(output);

//when
ResultActions actions = mockMvc.perform(
put("/api/mypage/alarm")
.header("Authorization", "Bearer ACCESS_TOKEN")
.contentType(MediaType.APPLICATION_JSON)
.param("type", "all") // 파라미터 추가
.param("status", "on") // 파라미터 추가
);


//then
actions
.andExpect(status().isOk())
.andDo(
restDocs.document(
requestHeaders(
headerWithName("Authorization").description("접근 토큰")
),
requestParameters( // 요청 파라미터 문서화
parameterWithName("type").description("all || isNewUploadPush || isRemindPush || isFirePush"),
parameterWithName("status").description("on || off")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
fieldWithPath("message").description("알람 정보를 수정했습니다"),
fieldWithPath("data.newUploadPush").description("신규 공지 알림"),
fieldWithPath("data.remindPush").description("미션 리마인드 알림"),
fieldWithPath("data.firePush").description("불 던지기 알림")
)
)
);
}
}

0 comments on commit 9b4fe17

Please sign in to comment.