Skip to content

Commit

Permalink
fix: 스케줄 설계 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
SangWoon123 committed May 19, 2024
1 parent 387787d commit 8e0b26b
Show file tree
Hide file tree
Showing 44 changed files with 752 additions and 395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import com.tukorea.planding.domain.group.service.GroupFavoriteService;
import com.tukorea.planding.domain.user.dto.UserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Group Favorite", description = "그룹 즐겨찾기 관련")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/favorite")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@
import com.tukorea.planding.domain.group.dto.response.GroupInviteMessageResponse;
import com.tukorea.planding.domain.user.dto.UserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Group Invite", description = "그룹 초대 관련")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/invitation")
public class GroupInviteController {
private final GroupInviteService groupInviteService;

@Operation(summary = "유저에게 초대를 보낸다")
@PostMapping()
public CommonResponse<GroupInviteMessageResponse> invite(@AuthenticationPrincipal UserInfo userInfo, @RequestBody GroupInviteRequest groupInviteRequest) {
return CommonUtils.success(groupInviteService.inviteGroupRoom(userInfo, groupInviteRequest));
}

@Operation(summary = "초대를 수락한다")
@GetMapping("/accept/{groupId}/{code}")
public CommonResponse<?> accept(@AuthenticationPrincipal UserInfo userInfo, @PathVariable(name = "groupId") Long groupId, @PathVariable(name = "code") String code) {
groupInviteService.acceptInvitation(userInfo, code, groupId);
Expand All @@ -37,6 +41,7 @@ public CommonResponse<List<GroupInviteMessageResponse>> getInvitations(@Authenti
return CommonUtils.success(groupInviteResponse);
}

@Operation(summary = "초대를 거절한다.")
@DeleteMapping("/decline/{code}")
public CommonResponse<?> declineInvitation(@AuthenticationPrincipal UserInfo userInfo, @PathVariable(name = "code") String code) {
groupInviteService.declineInvitation(userInfo, code);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class GroupRoom extends BaseEntity {
@OneToMany(mappedBy = "groupRoom", cascade = CascadeType.ALL, orphanRemoval = true)
private final Set<UserGroup> userGroups = new HashSet<>();

@OneToMany(mappedBy = "groupRoom", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Schedule> schedules = new ArrayList<>();
// @OneToMany(mappedBy = "groupRoom", cascade = CascadeType.ALL, orphanRemoval = true)
// private final List<Schedule> schedules = new ArrayList<>();

@OneToMany(mappedBy = "groupRoom", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<GroupFavorite> groupFavorites = new ArrayList<>();
Expand Down Expand Up @@ -75,10 +75,10 @@ public void validateUserNotAlreadyMember(User user) throws BusinessException {
}
}

// 스케줄을 그룹룸에 추가하는 메서드
public void addSchedule(Schedule schedule) {
this.schedules.add(schedule);
}
// // 스케줄을 그룹룸에 추가하는 메서드
// public void addSchedule(Schedule schedule) {
// this.schedules.add(schedule);
// }

public void updateNameOrDes(String name, String description) {
if (name != null && !name.equals(this.name)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.tukorea.planding.domain.group.repository.normal;

import com.tukorea.planding.domain.group.entity.GroupRoom;
import com.tukorea.planding.domain.schedule.entity.Schedule;
import com.tukorea.planding.domain.user.entity.User;

import java.util.List;

public interface GroupRoomRepositoryCustom {
List<GroupRoom> findGroupRoomsByUserId(Long userId);
List<User> getGroupUsers(Long groupId);

List<User> getGroupUsers(Long groupId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

public interface UserGroupRepositoryCustom {
boolean existsByGroupRoomIdAndUserId(Long groupRoomId, Long userId);

List<User> findUserByIsConnectionFalse(Long groupRoomId);
UserGroup findUserByGroupId(Long userId, Long groupRoomId);

UserGroup findUserByGroupId(Long userId, Long groupRoomId);

boolean existsByUserCodeAndGroupId(String userCode, Long groupId);

List<UserGroup> findAllUsersByGroupId(Long groupRoomId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ public boolean existsByUserCodeAndGroupId(String userCode, Long groupId) {

return count > 0;
}

@Override
public List<UserGroup> findAllUsersByGroupId(Long groupRoomId) {
return queryFactory.selectFrom(userGroup)
.where(userGroup.groupRoom.id.eq(groupRoomId))
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.tukorea.planding.domain.group.entity.GroupRoom;
import com.tukorea.planding.domain.group.entity.UserGroup;
import com.tukorea.planding.domain.group.service.query.GroupQueryService;
import com.tukorea.planding.domain.group.service.query.UserGroupQueryService;
import com.tukorea.planding.domain.notify.service.NotificationService;
import com.tukorea.planding.domain.user.dto.UserInfo;
import com.tukorea.planding.domain.user.entity.User;
Expand All @@ -24,7 +25,7 @@
public class GroupInviteService {
private final UserQueryService userQueryService;
private final GroupQueryService groupQueryService;
private final UserGroupService userGroupService;
private final UserGroupQueryService userGroupQueryService;
private final NotificationService notificationService;
private final RedisGroupInviteService redisGroupInviteService;

Expand Down Expand Up @@ -64,7 +65,7 @@ public void acceptInvitation(UserInfo userInfo, String code, Long groupId) {
GroupRoom group = groupQueryService.getGroupById(groupId);

final UserGroup userGroup = UserGroup.createUserGroup(user, group);
userGroupService.save(userGroup);
userGroupQueryService.save(userGroup);

redisGroupInviteService.deleteInvitation(userInfo.getUserCode(), code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.tukorea.planding.domain.group.entity.UserGroup;
import com.tukorea.planding.domain.group.repository.normal.GroupRoomRepository;
import com.tukorea.planding.domain.group.service.query.GroupQueryService;
import com.tukorea.planding.domain.group.service.query.UserGroupQueryService;
import com.tukorea.planding.domain.user.dto.UserInfo;
import com.tukorea.planding.domain.user.entity.User;
import com.tukorea.planding.domain.user.service.UserQueryService;
Expand All @@ -27,7 +28,7 @@
public class GroupRoomService {

private final UserQueryService userQueryService;
private final UserGroupService userGroupService;
private final UserGroupQueryService userGroupQueryService;
private final GroupQueryService groupQueryService;

@Transactional
Expand All @@ -40,7 +41,7 @@ public GroupResponse createGroupRoom(UserInfo userInfo, GroupCreateRequest creat
final UserGroup userGroup = UserGroup.createUserGroup(user, savedGroupRoom);

// 중간테이블에 유저, 그룹 정보 저장
userGroupService.save(userGroup);
userGroupQueryService.save(userGroup);

return toGroupResponse(newGroupRoom);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,4 @@ public void updateConnectionStatus(String userCode, String groupCode, boolean is
test.setConnected(isConnected);
}

public void save(UserGroup userGroup) {
userGroupRepository.save(userGroup);
}

public void checkUserAccessToGroupRoom(Long groupRoomId, Long userId) {
boolean exists = userGroupRepository.existsByGroupRoomIdAndUserId(groupRoomId, userId);
if (!exists) {
throw new BusinessException(ErrorCode.ACCESS_DENIED);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class GroupQueryService {
private final GroupRoomRepository groupRoomRepository;
private final UserGroupRepository userGroupRepository;


public GroupRoom createGroup(GroupRoom groupRoom) {
return groupRoomRepository.save(groupRoom);
}
Expand All @@ -35,6 +34,12 @@ public GroupRoom getGroupById(Long groupId) {
.orElseThrow(() -> new BusinessException(ErrorCode.GROUP_ROOM_NOT_FOUND));
}

public GroupRoom getGroupByCode(String groupCode) {
return groupRoomRepository.findByGroupCode(groupCode)
.orElseThrow(() -> new BusinessException(ErrorCode.GROUP_ROOM_NOT_FOUND));
}


public void delete(GroupRoom groupRoom) {
groupRoomRepository.delete(groupRoom);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.tukorea.planding.domain.group.service.query;

import com.tukorea.planding.domain.group.entity.UserGroup;
import com.tukorea.planding.domain.group.repository.usergroup.UserGroupRepository;
import com.tukorea.planding.global.error.BusinessException;
import com.tukorea.planding.global.error.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UserGroupQueryService {

private final UserGroupRepository userGroupRepository;

public void save(UserGroup userGroup) {
userGroupRepository.save(userGroup);
}

public void checkUserAccessToGroupRoom(Long groupRoomId, Long userId) {
boolean exists = userGroupRepository.existsByGroupRoomIdAndUserId(groupRoomId, userId);
if (!exists) {
throw new BusinessException(ErrorCode.ACCESS_DENIED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.tukorea.planding.domain.notify.service.NotificationService;
import com.tukorea.planding.domain.user.dto.UserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -13,7 +14,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@Tag(name = "Notify", description = "알림 메시지 관련")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/notification")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.tukorea.planding.domain.schedule.controller;

import com.tukorea.planding.common.CommonResponse;
import com.tukorea.planding.common.CommonUtils;
import com.tukorea.planding.domain.schedule.dto.request.ScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.response.PersonalScheduleResponse;
import com.tukorea.planding.domain.schedule.dto.response.ScheduleResponse;
import com.tukorea.planding.domain.schedule.service.CommonScheduleService;
import com.tukorea.planding.domain.user.dto.UserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Tag(name = "CommonSchedule", description = "공통 스케줄")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/common/schedule")
public class CommonScheduleController {

private final CommonScheduleService commonScheduleService;

@Operation(summary = "오늘 스케줄 조회")
@GetMapping("/today")
public CommonResponse<List<ScheduleResponse>> showTodaySchedule(@AuthenticationPrincipal UserInfo userInfo) {
List<ScheduleResponse> responses = commonScheduleService.showTodaySchedule(userInfo);
return CommonUtils.success(responses);
}

@Operation(summary = "공통: 스케쥴 생성을 할 때 내가 포함된 모든 그룹, 개인 시간때에 스케쥴을 확인")
@PostMapping("/overlap")
public CommonResponse<List<ScheduleResponse>> findOverlapSchedule(@AuthenticationPrincipal UserInfo userInfo, @RequestBody ScheduleRequest scheduleRequest) {
List<ScheduleResponse> scheduleResponses = commonScheduleService.findOverlapSchedule(userInfo.getId(), scheduleRequest);
return CommonUtils.success(scheduleResponses);
}

@Operation(summary = "주간으로 가져오기")
@GetMapping("/week/{startDate}/{endDate}")
public CommonResponse<List<ScheduleResponse>> getWeekSchedule(@PathVariable(name = "startDate") LocalDate startDate,
@PathVariable(name = "endDate") LocalDate endDate
, @AuthenticationPrincipal UserInfo userInfo) {
List<ScheduleResponse> scheduleResponse = commonScheduleService.getWeekSchedule(startDate, endDate, userInfo);
return CommonUtils.success(scheduleResponse);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package com.tukorea.planding.domain.schedule.controller;

import com.tukorea.planding.domain.schedule.dto.GroupScheduleAttendanceRequest;
import com.tukorea.planding.domain.schedule.dto.request.GroupScheduleAttendanceRequest;
import com.tukorea.planding.domain.schedule.service.GroupScheduleAttendanceService;
import com.tukorea.planding.domain.user.dto.UserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Tag(name = "GroupAttendance", description = "그룹 스케줄 참여설정")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/attendance")
public class GroupScheduleAttendanceController {

private final GroupScheduleAttendanceService groupScheduleAttendanceService;

@GetMapping()
@PostMapping()
@Operation(summary = "스케줄 참여 여부 선택")
public ResponseEntity<?> participationGroupSchedule(@AuthenticationPrincipal UserInfo userInfo, GroupScheduleAttendanceRequest status) {
public ResponseEntity<?> participationGroupSchedule(@AuthenticationPrincipal UserInfo userInfo, @RequestBody GroupScheduleAttendanceRequest status) {
groupScheduleAttendanceService.participationGroupSchedule(userInfo, status);
return new ResponseEntity<>("스케줄 참여여부 변경 완료되었습니다.", HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.tukorea.planding.domain.schedule.controller;

import com.tukorea.planding.common.CommonResponse;
import com.tukorea.planding.common.CommonUtils;
import com.tukorea.planding.domain.schedule.dto.response.PersonalScheduleResponse;
import com.tukorea.planding.domain.schedule.service.PersonalScheduleService;
import com.tukorea.planding.domain.user.dto.UserInfo;
import com.tukorea.planding.domain.schedule.dto.request.ScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.response.ScheduleResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Tag(name = "PersonalSchedule", description = "개인 스케줄")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/schedule")
public class PersonalScheduleController {

private final PersonalScheduleService personalScheduleService;

@Operation(summary = "개인 스케줄: 생성")
@PostMapping()
public CommonResponse<PersonalScheduleResponse> createSchedule(@AuthenticationPrincipal UserInfo userInfo, @RequestBody ScheduleRequest scheduleRequest) {
PersonalScheduleResponse response = personalScheduleService.createSchedule(userInfo, scheduleRequest);
return CommonUtils.success(response);
}

@Operation(summary = "개인 스케줄: 삭제")
@DeleteMapping("/{id}")
public ResponseEntity<PersonalScheduleResponse> deleteSchedule(@AuthenticationPrincipal UserInfo userInfo, @PathVariable Long id) {
personalScheduleService.deleteSchedule(userInfo, id);
return new ResponseEntity<>(HttpStatus.OK);
}

@Operation(summary = "개인 스케줄: 조회")
@GetMapping("/{schedule_id}")
public CommonResponse<PersonalScheduleResponse> getScheduleById(@PathVariable(name = "schedule_id") Long id, @AuthenticationPrincipal UserInfo userInfo) {
PersonalScheduleResponse scheduleResponse = personalScheduleService.getSchedule(id, userInfo);
return CommonUtils.success(scheduleResponse);
}

//TODO 아직 요구사항 미정
@Operation(summary = "개인 스케줄: 제목,내용,시작시간,끝낼시간 항목 수정")
@PatchMapping("/{schedule_id}")
public CommonResponse<PersonalScheduleResponse> updateSchedule(@PathVariable(name = "schedule_id") Long id, @RequestBody ScheduleRequest scheduleRequest, @AuthenticationPrincipal UserInfo userInfo) {
PersonalScheduleResponse scheduleResponse = personalScheduleService.updateSchedule(id, scheduleRequest, userInfo);
return CommonUtils.success(scheduleResponse);
}
}
Loading

0 comments on commit 8e0b26b

Please sign in to comment.