-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
150 additions
and
28 deletions.
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/nice/petudio/api/controller/member/MemberController.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,29 @@ | ||
package com.nice.petudio.api.controller.member; | ||
|
||
import com.nice.petudio.api.controller.member.dto.ChangeNotificationStatusResponse; | ||
import com.nice.petudio.api.controller.member.service.MemberCommandService; | ||
import com.nice.petudio.api.dto.ApiResponse; | ||
import com.nice.petudio.global.auth.auth.Auth; | ||
import com.nice.petudio.global.auth.resolver.MemberId; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
public class MemberController { | ||
private final MemberCommandService memberCommandService; | ||
|
||
@Auth | ||
@ResponseStatus(HttpStatus.OK) | ||
@PatchMapping("/member/notification/status-change") | ||
public ApiResponse<ChangeNotificationStatusResponse> changeMemberNotificationStatus(@MemberId final Long memberId, | ||
@RequestParam("status") final boolean notificationStatus) { | ||
return ApiResponse.success(memberCommandService.changeMemberNotificationStatus(memberId, notificationStatus)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ain/java/com/nice/petudio/api/controller/member/dto/ChangeNotificationStatusResponse.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,10 @@ | ||
package com.nice.petudio.api.controller.member.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ChangeNotificationStatusResponse { | ||
private final boolean notificationStatus; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/nice/petudio/api/controller/member/service/MemberCommandService.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,40 @@ | ||
package com.nice.petudio.api.controller.member.service; | ||
|
||
import com.nice.petudio.api.controller.member.dto.ChangeNotificationStatusResponse; | ||
import com.nice.petudio.api.controller.member.dto.CreateMemberRequest; | ||
import com.nice.petudio.domain.member.Member; | ||
import com.nice.petudio.domain.member.point.Point; | ||
import com.nice.petudio.domain.member.point.repository.PointRepository; | ||
import com.nice.petudio.domain.member.repository.MemberRepository; | ||
import com.nice.petudio.domain.member.setting.Setting; | ||
import com.nice.petudio.domain.member.setting.repository.SettingRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class MemberCommandService { | ||
private final MemberRepository memberRepository; | ||
private final PointRepository pointRepository; | ||
private final SettingRepository settingRepository; | ||
|
||
public Long registerMember(CreateMemberRequest request) { | ||
MemberServiceUtils.validateNotExistsMember(memberRepository, request.getSocialId(), request.getSocialType()); | ||
|
||
Member member = memberRepository.save( | ||
Member.newInstance(request.getSocialId(), request.getSocialType())); | ||
pointRepository.save(Point.fromMemberId(member.getId())); | ||
settingRepository.save(Setting.fromMemberId(member.getId())); | ||
|
||
return member.getId(); | ||
} | ||
|
||
public ChangeNotificationStatusResponse changeMemberNotificationStatus(final Long memberId, final boolean notificationStatus) { | ||
Setting setting = SettingServiceUtils.findSettingByMemberId(settingRepository, memberId); | ||
setting.changeNotificationStatus(notificationStatus); | ||
|
||
return new ChangeNotificationStatusResponse(notificationStatus); | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/main/java/com/nice/petudio/api/controller/member/service/MemberService.java
This file was deleted.
Oops, something went wrong.
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/nice/petudio/api/controller/member/service/SettingServiceUtils.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,16 @@ | ||
package com.nice.petudio.api.controller.member.service; | ||
|
||
import com.nice.petudio.domain.member.setting.Setting; | ||
import com.nice.petudio.domain.member.setting.repository.SettingRepository; | ||
import com.nice.petudio.global.exception.error.ErrorCode; | ||
import com.nice.petudio.global.exception.model.NotFoundException; | ||
|
||
public class SettingServiceUtils { | ||
|
||
public static Setting findSettingByMemberId(SettingRepository settingRepository, final Long memberId) { | ||
return settingRepository.findByMemberId(memberId) | ||
.orElseThrow(() -> new NotFoundException( | ||
ErrorCode.NOT_FOUND_MEMBER_EXCEPTION, | ||
String.format("memberId(%d)의 Setting 정보를 찾을 수 없습니다.", memberId))); | ||
} | ||
} |
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
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
4 changes: 4 additions & 0 deletions
4
src/main/java/com/nice/petudio/domain/member/setting/repository/SettingRepositoryCustom.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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
package com.nice.petudio.domain.member.setting.repository; | ||
|
||
import com.nice.petudio.domain.member.setting.Setting; | ||
import java.util.Optional; | ||
|
||
public interface SettingRepositoryCustom { | ||
Optional<Setting> findByMemberId(Long memberId); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/nice/petudio/domain/member/setting/repository/SettingRepositoryImpl.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 |
---|---|---|
@@ -1,4 +1,21 @@ | ||
package com.nice.petudio.domain.member.setting.repository; | ||
|
||
import static com.nice.petudio.domain.member.setting.QSetting.setting; | ||
|
||
import com.nice.petudio.domain.member.setting.Setting; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class SettingRepositoryImpl implements SettingRepositoryCustom { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Optional<Setting> findByMemberId(Long memberId) { | ||
return Optional.ofNullable(queryFactory | ||
.selectFrom(setting) | ||
.where(setting.member_id.eq(memberId)) | ||
.fetchOne()); | ||
} | ||
} |
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