Skip to content

Commit

Permalink
Merge pull request #170 from Kusitms-29th-MeetUp-H/feat/159-main
Browse files Browse the repository at this point in the history
[refactor]:Main 코드 정리
  • Loading branch information
qogustj authored May 23, 2024
2 parents ecb7946 + c06b68a commit e1cfea8
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 131 deletions.
6 changes: 6 additions & 0 deletions Main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ dependencies {
implementation 'com.github.in-seo:univcert:master-SNAPSHOT'
//mongoDB
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:5.3.0'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation platform('org.junit:junit-bom:5.9.1')
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,19 @@ public SyncDetailResponseDto getSyncDetail(Long userId, Long syncId){
Boolean isOwner = syncManager.validateSync(mySync, sync);
if (sync.getSyncType() == SyncType.ONETIME||sync.getSyncType() == SyncType.FROM_FRIEND) {
return SyncDetailResponseDto.oneTimeOf(
sync.getSyncName(),
sync.getImage(),
sync.getSyncType(),
sync.getType(),
sync.getSyncIntro(),
sync.getDate(),
sync.getLocation(),
sync,
user,
participationManager.countParticipationBySyncId(sync.getId()),
sync.getMember_max(),
user.getProfile(),
user.getUserName(),
user.getUniversity(),
sync.getUserIntro(),
isFull,
participationManager.existParticipation(userId, syncId),
favoriteSyncManager.existsByUserIdAndSyncId(userId,syncId),
isOwner
);
} else if (sync.getSyncType() == SyncType.LONGTIME) {
return SyncDetailResponseDto.longTimeOf(
sync.getSyncName(),
sync.getImage(),
sync.getSyncType(),
sync.getType(),
sync.getSyncIntro(),
sync.getRegularDay(),
sync.getRegularTime(),
sync.getDate(),
sync.getLocation(),
sync,
user,
participationManager.countParticipationBySyncId(sync.getId()),
sync.getMember_max(),
user.getProfile(),
user.getUserName(),
user.getUniversity(),
sync.getUserIntro(),
isFull,
participationManager.existParticipation(userId, syncId),
favoriteSyncManager.existsByUserIdAndSyncId(userId,syncId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,10 @@ public List<SyncInfoResponse> recommendSync(Long userId, String clientIp){
User user = userReader.getByUserId(userId);
List<UserCategory> userCategories = userCategoryReader.getUserCategoriesByUserId(userId);
List<Type> types = userCategoryManager.getTypesByUserCategories(userCategories);
List<Sync> syncList = syncReader.findBySyncTypeWithTypesWithLocation(user.getSyncType(), types, user.getLocation());
List<Sync> syncList = syncReader.getSyncsBySyncTypeAndTypesAndLocation(user.getSyncType(), types, user.getLocation());
return syncList.stream().map( sync -> SyncInfoResponse.of(
sync.getId(),
sync.getSyncType(),
sync.getType(),
sync.getImage(),
sync,
participationManager.countParticipationBySyncId(sync.getId()),
sync.getMember_max(),
sync.getSyncName(),
sync.getLocation(),
sync.getDate(),
favoriteSyncManager.existsByUserIdAndSyncId(userId, sync.getId())
)).toList();
}
Expand All @@ -78,32 +71,17 @@ public List<SyncInfoResponse> friendSync(Long userId, SyncInfoRequestDto syncInf
//음 이거보다 위에서 if문써서 하는게 더 가독성 있는듯
// .filter(sync -> type == null || sync.getType().name().equals(type))
.map( sync -> SyncInfoResponse.of(
sync.getId(),
sync.getSyncType(),
sync.getType(),
sync.getImage(),
sync,
participationManager.countParticipationBySyncId(sync.getId()),
sync.getMember_max(),
sync.getSyncName(),
sync.getLocation(),
sync.getDate(),
favoriteSyncManager.existsByUserIdAndSyncId(userId, sync.getId())
)).toList();
return listUtils.getListByTake(syncInfoResponseDtos, syncInfoRequestDto.take());
}
public List<SyncAssociateInfoResponse> associateSync(Long userId, SyncInfoRequestDto syncInfoRequestDto){
List<Sync> syncList = syncReader.findAllByAssociateIsExist(getEnumFROMStringSyncType(syncInfoRequestDto.syncType()), getEnumTypeFromStringType(syncInfoRequestDto.type()));
List<SyncAssociateInfoResponse> syncAssociateInfoResponseDtos = syncList.stream().map( sync -> SyncAssociateInfoResponse.of(
sync.getId(),
sync.getSyncType(),
sync.getType(),
sync.getImage(),
sync,
participationManager.countParticipationBySyncId(sync.getId()),
sync.getMember_max(),
sync.getSyncName(),
sync.getLocation(),
sync.getDate(),
sync.getAssociate(),
favoriteSyncManager.existsByUserIdAndSyncId(userId, sync.getId())
)).toList();
return listUtils.getListByTake(syncAssociateInfoResponseDtos, syncInfoRequestDto.take());
Expand All @@ -112,15 +90,8 @@ public List<SyncInfoResponse> searchSync(Long userId, SyncInfoRequestDto syncInf
List<Sync> syncList = syncReader.findAllBySyncTypeAndType(getEnumFROMStringSyncType(syncInfoRequestDto.syncType()), getEnumTypeFromStringType(syncInfoRequestDto.type()));

List<SyncInfoResponse> syncInfoResponseDtos = syncList.stream().map( sync -> SyncInfoResponse.of(
sync.getId(),
sync.getSyncType(),
sync.getType(),
sync.getImage(),
sync,
participationManager.countParticipationBySyncId(sync.getId()),
sync.getMember_max(),
sync.getSyncName(),
sync.getLocation(),
sync.getDate(),
favoriteSyncManager.existsByUserIdAndSyncId(userId, sync.getId())
)).toList();
return listUtils.getListByTake(syncInfoResponseDtos, syncInfoRequestDto.take());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ public record SyncInfoRequestDto(
language = "한국어";
}
}
public static SyncInfoRequestDto of(int take,
String syncType,
String type,
String language){
return new SyncInfoRequestDto(take,syncType,type,language);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kusitms29.backendH.api.sync.service.dto.response;

import com.kusitms29.backendH.domain.category.entity.Type;
import com.kusitms29.backendH.domain.sync.entity.Sync;
import com.kusitms29.backendH.domain.sync.entity.SyncType;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -57,29 +58,21 @@ public SyncAssociateInfoResponse(
this.isMarked = isMarked;
}
public static SyncAssociateInfoResponse of(
Long syncId,
SyncType syncType,
Type type,
String image,
Sync sync,
int userCnt,
int totalCnt,
String syncName,
String location,
LocalDateTime date,
String associate,
Boolean isMarked) {
String dateString = date != null ? date.format(DATE_TIME_FORMATTER) : null;
String dateString = sync.getDate() != null ? sync.getDate().format(DATE_TIME_FORMATTER) : null;
return new SyncAssociateInfoResponse(
syncId,
syncType.getStringSyncType(),
type.getStringType(),
image,
sync.getId(),
sync.getSyncType().getStringSyncType(),
sync.getType().getStringType(),
sync.getImage(),
userCnt,
totalCnt,
syncName,
location,
sync.getMember_max(),
sync.getSyncName(),
sync.getLocation(),
dateString,
associate,
sync.getAssociate(),
isMarked
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.kusitms29.backendH.api.sync.service.dto.response;

import com.kusitms29.backendH.domain.category.entity.Type;
import com.kusitms29.backendH.domain.sync.entity.Sync;
import com.kusitms29.backendH.domain.sync.entity.SyncType;
import com.kusitms29.backendH.domain.user.entity.User;

import java.time.LocalDateTime;
import java.time.LocalTime;
Expand All @@ -28,51 +30,29 @@ public record SyncDetailResponseDto(
Boolean isOwner
) {
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("M월 d일 (EEE) a h:mm");
public static SyncDetailResponseDto oneTimeOf(String syncName,
String syncImage,
SyncType syncType,
Type type,
String syncIntro,
LocalDateTime date,
String location,
int userCnt,
int totalCnt,
String userImage,
String userName,
String university,
String userIntro,
public static SyncDetailResponseDto oneTimeOf(Sync sync,
User user,
int userCnt,
Boolean isFull,
Boolean isJoin,
Boolean isMarked,
Boolean isOwner){
String formattedDate = date.format(DATE_TIME_FORMATTER);
return new SyncDetailResponseDto(syncName, syncImage, syncType.getStringSyncType(), type.getStringType(), syncIntro, null, formattedDate, location, userCnt, totalCnt, userImage, userName, university, userIntro, isFull, isJoin,isMarked,isOwner);
String formattedDate = sync.getDate().format(DATE_TIME_FORMATTER);
return new SyncDetailResponseDto(sync.getSyncName(), sync.getImage(), sync.getSyncType().getStringSyncType(), sync.getType().getStringType(), sync.getSyncIntro(), null, formattedDate, sync.getLocation(), userCnt, sync.getMember_max(), user.getProfile(), user.getUserName(), user.getUniversity(), sync.getUserIntro(), isFull, isJoin,isMarked,isOwner);
}
public static SyncDetailResponseDto longTimeOf(String syncName,
String syncImage,
SyncType syncType,
Type type,
String syncIntro,
String regularDay,
LocalTime regularTime,
LocalDateTime date,
String location,
int userCnt,
int totalCnt,
String userImage,
String userName,
String university,
String userIntro,
public static SyncDetailResponseDto longTimeOf(Sync sync,
User user,
int userCnt,
Boolean isFull,
Boolean isJoin,
Boolean isMarked,
Boolean isOwner){
String formattedDate = null;
if(date != null) {
formattedDate = date.format(DATE_TIME_FORMATTER);
if(sync.getDate() != null) {
formattedDate = sync.getDate().format(DATE_TIME_FORMATTER);
}
String formattedRegularTime = regularTime.format(DateTimeFormatter.ofPattern("a h:mm"));
String regularDate = "매주 " + regularDay + " " + formattedRegularTime;
return new SyncDetailResponseDto(syncName, syncImage, syncType.getStringSyncType(), type.getStringType(), syncIntro, regularDate, formattedDate, location, userCnt, totalCnt, userImage, userName, university, userIntro, isFull, isJoin, isMarked, isOwner);
String formattedRegularTime = sync.getRegularTime().format(DateTimeFormatter.ofPattern("a h:mm"));
String regularDate = "매주 " + sync.getRegularDay() + " " + formattedRegularTime;
return new SyncDetailResponseDto(sync.getSyncName(), sync.getImage(), sync.getSyncType().getStringSyncType(), sync.getType().getStringType(), sync.getSyncIntro(), regularDate, formattedDate, sync.getLocation(), userCnt, sync.getMember_max(), user.getProfile(), user.getUserName(), user.getUniversity(), sync.getUserIntro(), isFull, isJoin, isMarked, isOwner);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kusitms29.backendH.api.sync.service.dto.response;

import com.kusitms29.backendH.domain.category.entity.Type;
import com.kusitms29.backendH.domain.sync.entity.Sync;
import com.kusitms29.backendH.domain.sync.entity.SyncType;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -55,26 +56,19 @@ public SyncInfoResponse(
}

public static SyncInfoResponse of(
Long syncId,
SyncType syncType,
Type type,
String image,
Sync sync,
int userCnt,
int totalCnt,
String syncName,
String location,
LocalDateTime date,
Boolean isMarked) {
String dateString = date != null ? date.format(DATE_TIME_FORMATTER) : null;
String dateString = sync.getDate() != null ? sync.getDate().format(DATE_TIME_FORMATTER) : null;
return new SyncInfoResponse(
syncId,
syncType.getStringSyncType(),
type.getStringType(),
image,
sync.getId(),
sync.getSyncType().getStringSyncType(),
sync.getType().getStringType(),
sync.getImage(),
userCnt,
totalCnt,
syncName,
location,
sync.getMember_max(),
sync.getSyncName(),
sync.getLocation(),
dateString,
isMarked
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void createRoom(List<User> userList, Boolean isPossible, Long syncId, Use
);
for (User user : userList) {
if (sync.getUser().getId().equals(user.getId())) {
ChatContent chatContent = ChatContent.createChatContent(user.getUserName(), "모두 반가워요~", room,"https://sync-content-bucket-01.s3.ap-northeast-2.amazonaws.com/a2d3a182-9054-42b9-b439-616bcbba9e87.png");
ChatContent chatContent = ChatContent.createChatContent(user.getUserName(), "모두 반가워요~", room,"https://sync-content-bucket-01.s3.ap-northeast-2.amazonaws.com/be965e97-e87d-45e9-9720-4d360323bebc.png");
contents.add(chatContent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<Sync> findAllByAssociateIsExist(SyncType syncType, Type type) {
List<Sync> syncList = syncRepository.findAll(spec, Sort.by(Sort.Direction.DESC, "date"));
return ListException.throwIfEmpty(syncList, () -> new EntityNotFoundException(ErrorCode.SYNC_NOT_FOUND));
}
public List<Sync> findBySyncTypeWithTypesWithLocation(SyncType syncType, List<Type> types, String location) {
public List<Sync> getSyncsBySyncTypeAndTypesAndLocation(SyncType syncType, List<Type> types, String location) {
List<Sync> syncList = new ArrayList<>();

for (Type type : types) {
Expand Down

0 comments on commit e1cfea8

Please sign in to comment.