Skip to content

Commit

Permalink
feat(Channel) : 채널 참가 승인 api 및 로직 변경.
Browse files Browse the repository at this point in the history
  • Loading branch information
F-hiller committed May 25, 2024
1 parent 7a46922 commit 56f819b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ out/
.vscode/

### env ###
.env
application-test.yml
.env
8 changes: 3 additions & 5 deletions src/main/java/gdsc/comunity/controller/ChannelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ ResponseEntity<String> deleteChannel(@PathVariable Long channelId, @UserId Long
return new ResponseEntity<>("Channel deleted.", HttpStatus.OK);
}

@PutMapping("/approve")
ResponseEntity<String> approveJoinChannel(@RequestBody ApproveJoinChannelDto approveJoinChannelDto, @UserId Long userId) {
Long targetUserId = approveJoinChannelDto.getUserId();
Long channelId = approveJoinChannelDto.getChannelId();
channelServiceImpl.approveJoinChannel(userId, targetUserId, channelId);
@PutMapping("/join-requests/{requestId}")
ResponseEntity<String> approveJoinChannel(@PathVariable Long requestId, @UserId Long userId) {
channelServiceImpl.approveJoinChannel(userId, requestId);
return new ResponseEntity<>("Channel joined.", HttpStatus.OK);
}

Expand Down
14 changes: 0 additions & 14 deletions src/main/java/gdsc/comunity/dto/channel/ApproveJoinChannelDto.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ChannelService {

ChannelInfoDto searchChannel(Long channelId);

void approveJoinChannel(Long userId, Long targetUserId, Long channelId);
void approveJoinChannel(Long userId, Long requestId);

void sendJoinRequest(String nickname, Long userId, Long channelId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,15 @@ public void sendJoinRequest(String nickname, Long userId, Long channelId) {

@Override
@Transactional
public void approveJoinChannel(Long userId, Long targetUserId, Long channelId) {
User user = findUserByIdThrowException(userId);
Channel channel = findChannelByIdThrowException(channelId);

checkManagerThrowException(userId, channel.getManager().getId());

public void approveJoinChannel(Long userId, Long requestId) {
// 채널 가입 요청을 승인하고 UserChannel에 저장. 이후 ChannelJoinRequest 삭제
ChannelJoinRequest channelJoinRequest = channelJoinRequestRepository.findByUserIdAndChannelId(targetUserId, channelId).orElseThrow(
User user = findUserByIdThrowException(userId);
ChannelJoinRequest channelJoinRequest = channelJoinRequestRepository.findById(requestId).orElseThrow(
() -> new IllegalArgumentException("해당 사용자의 채널 가입 요청이 존재하지 않습니다.")
);
Channel channel = channelJoinRequest.getChannel();

checkManagerThrowException(userId, channel.getManager().getId());

userChannelJpaRepository.save(UserChannel.builder()
.channel(channel)
Expand Down
46 changes: 46 additions & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
spring:
datasource:
url: "jdbc:h2:mem:community;MODE=mysql"
username: "sa"
password: ""
driver-class-name: org.h2.Driver

# redis 설정
data:
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}

jpa:
defer-datasource-initialization: true
hibernate:
ddl-auto: create
naming:
physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect

h2:
console:
enabled: true
path: /h2-console

security:
oauth2:
client:
registration:
google:
client-id: ${GOOGLE_CLIENT_ID}
client-secret: ${GOOGLE_CLIENT_SECRET}
redirect-uri: ${GOOGLE_REDIRECT_URI}

logging.level:
org.hibernate:
orm.jdbc.bind: trace
SQL: debug

jwt:
secret: "${JWT_SECRET}"


Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ void approveJoinChannel_Success() {

channelService.sendJoinRequest("nickname2", user.getId(), channel.getId());

Long requestId = channelJoinRequestRepository.findByUserIdAndChannelId(user.getId(), channel.getId()).orElseThrow().getId();

// do
channelService.approveJoinChannel(manager.getId(), user.getId(), channel.getId());
channelService.approveJoinChannel(manager.getId(), requestId);

// assert result
Optional<UserChannel> userChannel = userChannelJpaRepository.findByUserIdAndChannelId(user.getId(), channel.getId());
Expand Down Expand Up @@ -164,7 +166,8 @@ void leaveChannel_Success_WithNormalUser() {

Channel channel = channelService.createChannel(manager.getId(), "New Channel", "nickname");
channelService.sendJoinRequest("nickname2", user.getId(), channel.getId());
channelService.approveJoinChannel(manager.getId(), user.getId(), channel.getId());
Long requestId = channelJoinRequestRepository.findByUserIdAndChannelId(user.getId(), channel.getId()).orElseThrow().getId();
channelService.approveJoinChannel(manager.getId(), requestId);

// Act
channelService.leaveChannel(user.getId(), channel.getId());
Expand Down Expand Up @@ -232,8 +235,10 @@ void userRepositoryFindTop2ByChannelIdOrderByCreatedDateDesc() {
Channel channel = channelService.createChannel(manager.getId(), "New Channel", "nickname");
channelService.sendJoinRequest("nickname1", user1.getId(), channel.getId());
channelService.sendJoinRequest("nickname2", user2.getId(), channel.getId());
channelService.approveJoinChannel(manager.getId(), user1.getId(), channel.getId());
channelService.approveJoinChannel(manager.getId(), user2.getId(), channel.getId());
Long requestId1 = channelJoinRequestRepository.findByUserIdAndChannelId(user1.getId(), channel.getId()).orElseThrow().getId();
Long requestId2 = channelJoinRequestRepository.findByUserIdAndChannelId(user2.getId(), channel.getId()).orElseThrow().getId();
channelService.approveJoinChannel(manager.getId(), requestId1);
channelService.approveJoinChannel(manager.getId(), requestId2);

// Act
List<UserChannel> listUserChannel = userChannelJpaRepository.findTop2ByChannelIdOrderByCreatedDateAsc(channel.getId());
Expand Down Expand Up @@ -264,7 +269,8 @@ void leaveChannel_Success_WithManager_HasMoreUser() {

Channel channel = channelService.createChannel(manager.getId(), "New Channel", "nickname");
channelService.sendJoinRequest("nickname2", user.getId(), channel.getId());
channelService.approveJoinChannel(manager.getId(), user.getId(), channel.getId());
Long requestId = channelJoinRequestRepository.findByUserIdAndChannelId(user.getId(), channel.getId()).orElseThrow().getId();
channelService.approveJoinChannel(manager.getId(), requestId);

// Act
channelService.leaveChannel(manager.getId(), channel.getId());
Expand Down

0 comments on commit 56f819b

Please sign in to comment.