Skip to content

Commit

Permalink
[feat] #177 나의 모임 삭제하기 API 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
2hyunjinn committed Jan 23, 2025
1 parent 6d1998a commit da9734a
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,15 @@ public ResponseEntity<ApiResponse<Void>> cancelMyApplication(

return ResponseBuilder.ok(null);
}

@DeleteMapping("/my/groups")
public ResponseEntity<ApiResponse<Void>> deleteMyGroup(
@RequestHeader("Authorization") String accessToken,
@RequestBody final GroupRequest requestDto
) {
Long userId = jwtService.parseTokenAndGetUserId(accessToken);
groupFacade.deleteMyGroup(userId, requestDto);

return ResponseBuilder.ok(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public interface EveryGroupService {
ReadCommentGroup readCommentInGroup(UserEntity userEntity, boolean commentEntity, final long groupId);

EveryGroupEntity registerEveryGroup(RegisterGroupServiceRequest serviceRequest,
GongbaekTimeSlotEntity gongbaekTimeSlotEntity);
GongbaekTimeSlotEntity gongbaekTimeSlotEntity);

void deleteEveryGroup(UserEntity currentUser, EveryGroupEntity everyGroupEntity);

ReadEveryGroup getActiveEveryGroups(UserEntity currentUser, Category category);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ggang.be.api.group.everyGroup.strategy;

import com.ggang.be.api.group.dto.GroupRequest;
import com.ggang.be.api.group.everyGroup.service.EveryGroupService;
import com.ggang.be.api.group.registry.DeleteGroupStrategy;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.domain.group.everyGroup.EveryGroupEntity;
import com.ggang.be.domain.user.UserEntity;
import com.ggang.be.global.annotation.Strategy;
import lombok.RequiredArgsConstructor;

@Strategy
@RequiredArgsConstructor
public class DeleteEveryGroupStrategy implements DeleteGroupStrategy {
private final EveryGroupService everyGroupService;

@Override
public boolean support(GroupType groupType) {
return groupType.equals(GroupType.WEEKLY);
}

@Override
public void deleteGroup(UserEntity userEntity, GroupRequest request) {
EveryGroupEntity everyGroupEntity = everyGroupService.findEveryGroupEntityByGroupId(request.groupId());
everyGroupService.deleteEveryGroup(userEntity, everyGroupEntity);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/ggang/be/api/group/facade/GroupFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class GroupFacade {
private final RegisterGroupStrategyRegistry registerGroupStrategyRegistry;
private final PrepareRegisterGongbaekFacade prepareRegisterGongbaekFacade;
private final CancelGroupStrategyRegistry cancelGroupStrategyRegistry;
private final DeleteGroupStrategyRegistry deleteGroupStrategyRegistry;
private final GroupUserInfoStrategyRegistry groupUserInfoStrategyRegistry;
private final ActiveCombinedGroupVoPreparer activeCombinedGroupVoPreparer;
private final MyGroupStrategyRegistry myGroupStrategyRegistry;
Expand Down Expand Up @@ -107,6 +108,17 @@ public void cancelMyApplication(Long userId, GroupRequest requestDto) {
cancelGroupStrategy.cancelGroup(findUserEntity, requestDto);
}

@Transactional
public void deleteMyGroup(Long userId, GroupRequest requestDto) {
UserEntity findUserEntity = userService.getUserById(userId);

DeleteGroupStrategy deleteGroupStrategy = deleteGroupStrategyRegistry.getDeleteGroupStrategy(
requestDto.groupType()
);

deleteGroupStrategy.deleteGroup(findUserEntity, requestDto);
}

public List<MyGroupResponse> getMyGroups(long userId, FillGroupType category, boolean status) {
UserEntity currentUser = userService.getUserById(userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface OnceGroupService {
OnceGroupEntity registerOnceGroup(RegisterGroupServiceRequest serviceRequest,
GongbaekTimeSlotEntity gongbaekTimeSlotEntity);

void deleteOnceGroup(UserEntity currentUser, OnceGroupEntity onceGroupEntity);

ReadOnceGroup getActiveOnceGroups(UserEntity currentUser, Category category);

void validateApplyOnceGroup(UserEntity currentUser, OnceGroupEntity onceGroupEntity);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ggang.be.api.group.onceGroup.strategy;

import com.ggang.be.api.group.dto.GroupRequest;
import com.ggang.be.api.group.onceGroup.service.OnceGroupService;
import com.ggang.be.api.group.registry.DeleteGroupStrategy;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.domain.group.onceGroup.OnceGroupEntity;
import com.ggang.be.domain.user.UserEntity;
import com.ggang.be.global.annotation.Strategy;
import lombok.RequiredArgsConstructor;

@Strategy
@RequiredArgsConstructor
public class DeleteOnceGroupStrategy implements DeleteGroupStrategy {
private final OnceGroupService onceGroupService;

@Override
public boolean support(GroupType groupType) {
return groupType.equals(GroupType.ONCE);
}

@Override
public void deleteGroup(UserEntity userEntity, GroupRequest request) {
OnceGroupEntity onceGroupEntity = onceGroupService.findOnceGroupEntityByGroupId(request.groupId());
onceGroupService.deleteOnceGroup(userEntity, onceGroupEntity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ggang.be.api.group.registry;

import com.ggang.be.api.group.dto.GroupRequest;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.domain.user.UserEntity;

public interface DeleteGroupStrategy {
boolean support(GroupType groupType);

void deleteGroup(UserEntity userEntity, GroupRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ggang.be.api.group.registry;

import com.ggang.be.api.common.ResponseError;
import com.ggang.be.api.exception.GongBaekException;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.global.annotation.Registry;
import lombok.RequiredArgsConstructor;

import java.util.List;

@Registry
@RequiredArgsConstructor
public class DeleteGroupStrategyRegistry {
private final List<DeleteGroupStrategy> deleteGroupStrategies;

public DeleteGroupStrategy getDeleteGroupStrategy(GroupType groupType) {
return deleteGroupStrategies.stream()
.filter(applyGroupStrategy -> applyGroupStrategy.support(groupType))
.findFirst()
.orElseThrow(() -> new GongBaekException(ResponseError.BAD_REQUEST));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import com.ggang.be.domain.group.vo.ReadCommentGroup;
import com.ggang.be.domain.timslot.gongbaekTimeSlot.GongbaekTimeSlotEntity;
import com.ggang.be.domain.user.UserEntity;
import java.time.LocalDate;
import java.time.Month;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.Month;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -143,6 +143,13 @@ public EveryGroupEntity registerEveryGroup(RegisterGroupServiceRequest serviceRe
return everyGroupRepository.save(buildEntity);
}

@Override
@Transactional
public void deleteEveryGroup(UserEntity currentUser, EveryGroupEntity everyGroupEntity) {
validateDeleteEveryGroup(currentUser, everyGroupEntity);
everyGroupRepository.delete(everyGroupEntity);
}

@Override
@Transactional
public void validateApplyEveryGroup(UserEntity currentUser, EveryGroupEntity everyGroupEntity) {
Expand All @@ -166,6 +173,10 @@ public void updateStatus() {
everyGroupEntities.forEach(groupStatusUpdater::updateEveryGroup);
}

private void validateDeleteEveryGroup(UserEntity currentUser, EveryGroupEntity everyGroupEntity) {
if (!everyGroupEntity.isHost(currentUser))
throw new GongBaekException(ResponseError.UNAUTHORIZED_ACCESS);
}

private EveryGroupEntity buildEveryGroupEntity(RegisterGroupServiceRequest serviceRequest,
GongbaekTimeSlotEntity gongbaekTimeSlotEntity) {
Expand All @@ -175,7 +186,7 @@ private EveryGroupEntity buildEveryGroupEntity(RegisterGroupServiceRequest servi

return EveryGroupEntity.builder()
.category(serviceRequest.category())
.dueDate(dueDateExtracter(month, nowDate))
.dueDate(dueDateExtractor(month, nowDate))
.coverImg(serviceRequest.coverImg())
.location(serviceRequest.location())
.status(Status.RECRUITING)
Expand All @@ -187,7 +198,7 @@ private EveryGroupEntity buildEveryGroupEntity(RegisterGroupServiceRequest servi
.build();
}

private LocalDate dueDateExtracter(int month, LocalDate nowDate) {
private LocalDate dueDateExtractor(int month, LocalDate nowDate) {
if(month < 7)
return LocalDate.of(nowDate.getYear(), Month.JUNE, 30);
return LocalDate.of(nowDate.getYear(), Month.DECEMBER, 31);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ public OnceGroupEntity registerOnceGroup(RegisterGroupServiceRequest serviceRequ
return onceGroupRepository.save(buildEntity);
}

@Override
@Transactional
public void deleteOnceGroup(UserEntity currentUser, OnceGroupEntity onceGroupEntity) {
validateDeleteOnceGroup(currentUser, onceGroupEntity);
onceGroupRepository.delete(onceGroupEntity);
}

@Override
@Transactional
public void validateApplyOnceGroup(UserEntity currentUser, OnceGroupEntity onceGroupEntity){
Expand All @@ -155,6 +162,11 @@ public void updateStatus() {
.forEach(groupStatusUpdater::updateOnceGroup);
}

private void validateDeleteOnceGroup(UserEntity currentUser, OnceGroupEntity onceGroupEntity) {
if (!onceGroupEntity.isHost(currentUser))
throw new GongBaekException(ResponseError.UNAUTHORIZED_ACCESS);
}

private OnceGroupEntity buildOnceGroupEntity(RegisterGroupServiceRequest serviceRequest,
GongbaekTimeSlotEntity gongbaekTimeSlotEntity) {
return OnceGroupEntity.builder()
Expand Down

0 comments on commit da9734a

Please sign in to comment.