Skip to content

Commit

Permalink
[deploy] 새롭게 반영된 사항 적용해서 배포합니다 (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
khyojun authored Jan 21, 2025
2 parents 38764a0 + 3a3bdab commit 686e2ea
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/ggang/be/api/facade/GroupRequestFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ private void isValidCoverImg(RegisterGongbaekRequest dto) {
private void isDateValid(RegisterGongbaekRequest dto) {
if(dto.groupType() == GroupType.ONCE) {
TimeValidator.isDateBeforeNow(dto.weekDate());
TimeValidator.isSameDate(dto.dueDate(), dto.weekDate());
}
TimeValidator.isDateBeforeNow(dto.dueDate());
}

private void isWeekDateRight(RegisterGongbaekRequest dto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ResponseEntity<ApiResponse<List<ActiveGroupsResponse>>> getFillGroups(
}

@GetMapping("/group/latest")
public ResponseEntity<ApiResponse<List<ActiveGroupsResponse>>> getLatestGroups(
public ResponseEntity<ApiResponse<List<LatestResponse>>> getLatestGroups(
@RequestHeader("Authorization") final String accessToken,
@RequestParam("groupType") final GroupType groupType
) {
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/ggang/be/api/group/dto/LatestResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ggang.be.api.group.dto;

import com.ggang.be.domain.constant.Category;
import com.ggang.be.domain.constant.GroupType;
import com.ggang.be.domain.constant.WeekDate;
import com.ggang.be.domain.group.dto.GroupVo;

import java.time.LocalDate;

public record LatestResponse(
long groupId,
Category category,
int coverImg,
int profileImg,
String nickname,
GroupType groupType,
String groupTitle,
WeekDate weekDate,
LocalDate groupDate,
double startTime,
double endTime,
String location
) {
public static LatestResponse fromGroupVo(GroupVo groupVo) {
return new LatestResponse(
groupVo.groupId(),
groupVo.category(),
groupVo.coverImg(),
groupVo.profileImg(),
groupVo.nickname(),
groupVo.groupType(),
groupVo.groupTitle(),
groupVo.weekDate(),
groupVo.groupDate(),
groupVo.startTime(),
groupVo.endTime(),
groupVo.location()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public record RegisterGongbaekRequest(
WeekDate weekDay,
double startTime,
double endTime,
@DateTimeFormat(pattern = "yyyy-MM-dd")
LocalDate dueDate,
Category category,
int coverImg,
String location,
Expand Down Expand Up @@ -78,7 +76,6 @@ public static RegisterGroupServiceRequest toServiceRequest(
request.weekDay(),
request.startTime(),
request.endTime(),
request.dueDate(),
request.category(),
request.coverImg(),
request.location(),
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/ggang/be/api/group/facade/GroupFacade.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ggang.be.api.group.facade;

import com.ggang.be.api.group.ActiveCombinedGroupVoPreparer;
import com.ggang.be.api.group.CombinedNearestGroupVo;
import com.ggang.be.api.group.CombinedNearestGroupVoPreparer;
import com.ggang.be.api.group.ActiveCombinedGroupVoPreparer;
import com.ggang.be.api.group.GroupVoAggregator;
import com.ggang.be.api.group.dto.*;
import com.ggang.be.api.group.registry.*;
Expand All @@ -15,12 +15,13 @@
import com.ggang.be.domain.user.UserEntity;
import com.ggang.be.domain.user.dto.UserInfo;
import com.ggang.be.global.annotation.Facade;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;


@Facade
@RequiredArgsConstructor
Expand Down Expand Up @@ -134,7 +135,7 @@ public List<ActiveGroupsResponse> getFillGroups(long userId, Category category)
.collect(Collectors.toList());
}

public List<ActiveGroupsResponse> getLatestGroups(long userId, GroupType groupType) {
public List<LatestResponse> getLatestGroups(long userId, GroupType groupType) {
UserEntity currentUser = userService.getUserById(userId);

LatestGroupStrategy latestGroupStrategy = latestGroupStrategyRegistry.getGroupStrategy(
Expand All @@ -143,8 +144,7 @@ public List<ActiveGroupsResponse> getLatestGroups(long userId, GroupType groupTy
return latestGroupStrategy.getLatestGroups(currentUser).stream()
.filter(groupVo -> lectureTimeSlotService.isActiveGroupsInLectureTimeSlot(currentUser, groupVo))
.sorted((group1, group2) -> group2.createdAt().compareTo(group1.createdAt()))
.limit(5)
.map(ActiveGroupsResponse::fromGroupVo)
.limit(5).map(LatestResponse::fromGroupVo)
.collect(Collectors.toList());
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/ggang/be/domain/group/dto/GroupVo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import java.time.LocalDate;
import java.time.LocalDateTime;

public record GroupVo(long groupId, Status status, Category category, int coverImg, int profileImg, GroupType groupType,
public record GroupVo(long groupId, Status status, Category category, int coverImg, int profileImg, String nickname,
GroupType groupType,
String groupTitle, WeekDate weekDate, LocalDate groupDate, double startTime, double endTime, String location, LocalDateTime createdAt) {

public static GroupVo fromEveryGroup(EveryGroupVo everyGroupVo) {
Expand All @@ -20,6 +21,7 @@ public static GroupVo fromEveryGroup(EveryGroupVo everyGroupVo) {
everyGroupVo.category(),
everyGroupVo.coverImg(),
everyGroupVo.profileImg(),
everyGroupVo.nickname(),
GroupType.WEEKLY,
everyGroupVo.groupTitle(),
everyGroupVo.weekDate(),
Expand All @@ -38,6 +40,7 @@ public static GroupVo fromOnceGroup(OnceGroupVo onceGroupVo) {
onceGroupVo.category(),
onceGroupVo.coverImg(),
onceGroupVo.profileImg(),
onceGroupVo.nickname(),
GroupType.ONCE,
onceGroupVo.groupTitle(),
WeekDate.fromDayOfWeek(onceGroupVo.dateTime().getDayOfWeek()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public record RegisterGroupServiceRequest(
WeekDate weekDay,
double startTime,
double endTime,
LocalDate dueDate,
Category category,
int coverImg,
String location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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;
Expand Down Expand Up @@ -167,9 +169,13 @@ public void updateStatus() {

private EveryGroupEntity buildEveryGroupEntity(RegisterGroupServiceRequest serviceRequest,
GongbaekTimeSlotEntity gongbaekTimeSlotEntity) {

LocalDate nowDate = LocalDate.now();
int month = nowDate.getMonth().getValue();

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

private LocalDate dueDateExtracter(int month, LocalDate nowDate) {
if(month < 7)
return LocalDate.of(nowDate.getYear(), Month.JUNE, 30);
return LocalDate.of(nowDate.getYear(), Month.DECEMBER, 31);
}

private void validateAlreadyApplied(UserEntity currentUser, EveryGroupEntity everyGroupEntity) {
if (everyGroupEntity.isApply(currentUser)) {
throw new GongBaekException(ResponseError.APPLY_ALREADY_EXIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import java.time.LocalDateTime;

public record EveryGroupVo(long groupId, Status status, Category category, int coverImg, int profileImg, GroupType groupType,
public record EveryGroupVo(long groupId, Status status, Category category, int coverImg, int profileImg,
String nickname, GroupType groupType,
String groupTitle, WeekDate weekDate, double startTime, double endTime, String location, LocalDateTime createdAt) {
public static EveryGroupVo of(EveryGroupEntity everyGroupEntity) {
return new EveryGroupVo(
Expand All @@ -17,6 +18,7 @@ public static EveryGroupVo of(EveryGroupEntity everyGroupEntity) {
everyGroupEntity.getCategory(),
everyGroupEntity.getCoverImg(),
everyGroupEntity.getUserEntity().getProfileImg(),
everyGroupEntity.getUserEntity().getNickname(),
GroupType.WEEKLY,
everyGroupEntity.getTitle(),
everyGroupEntity.getGongbaekTimeSlotEntity().getWeekDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import java.time.LocalDate;
import java.time.LocalDateTime;

public record OnceGroupVo(long groupId, Status status, Category category, int coverImg, int profileImg, GroupType groupType,
public record OnceGroupVo(long groupId, Status status, Category category, int coverImg, int profileImg, String nickname,
GroupType groupType,
String groupTitle, LocalDate dateTime, double startTime, double endTime, String location,
LocalDateTime createdAt, GongbaekTimeSlotEntity gongbaekTimeSlotEntity) {
public static OnceGroupVo of(OnceGroupEntity onceGroupEntity) {
Expand All @@ -19,6 +20,7 @@ public static OnceGroupVo of(OnceGroupEntity onceGroupEntity) {
onceGroupEntity.getCategory(),
onceGroupEntity.getCoverImg(),
onceGroupEntity.getUserEntity().getProfileImg(),
onceGroupEntity.getUserEntity().getNickname(),
GroupType.ONCE,
onceGroupEntity.getTitle(),
onceGroupEntity.getGroupDate(),
Expand Down
63 changes: 63 additions & 0 deletions src/test/java/com/ggang/be/api/school/SearchSchoolFacadeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.ggang.be.api.school;

import com.ggang.be.api.facade.SearchSchoolFacade;
import com.ggang.be.api.school.dto.SchoolSearchResponse;
import com.ggang.be.api.school.service.SchoolService;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

class SearchSchoolFacadeTest {

private final SchoolService schoolService = Mockito.mock(SchoolService.class);
private final SearchSchoolFacade searchSchoolFacade = new SearchSchoolFacade(schoolService);

@DisplayName("검색 키워드로 학교를 검색했을 때 결과를 반환한다.")
@Test
void searchSchool() {
// Given
String keyword = "서울";
List<String> mockResult = Arrays.asList("서울대학교", "서울시립대학교");
when(schoolService.searchSchoolContainingKeyword(keyword)).thenReturn(mockResult);

// When
SchoolSearchResponse response = searchSchoolFacade.searchSchool(keyword);

// Then
assertThat(response.schoolNames()).containsExactly("서울대학교", "서울시립대학교");
}

@DisplayName("검색 키워드가 없는 경우 빈 리스트를 반환한다.")
@Test
void searchSchoolNoResult() {
// Given
String keyword = "없는학교";
when(schoolService.searchSchoolContainingKeyword(keyword)).thenReturn(Collections.emptyList());

// When
SchoolSearchResponse response = searchSchoolFacade.searchSchool(keyword);

// Then
assertThat(response.schoolNames()).isEmpty();
}

@DisplayName("검색 키워드가 null인 경우 빈 리스트를 반환한다.")
@Test
void searchSchoolNullKeyword() {
// Given
when(schoolService.searchSchoolContainingKeyword(null)).thenReturn(Collections.emptyList());

// When
SchoolSearchResponse response = searchSchoolFacade.searchSchool(null);

// Then
assertThat(response.schoolNames()).isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.ggang.be.api.school;

import com.ggang.be.api.common.ResponseError;
import com.ggang.be.api.exception.GongBaekException;
import com.ggang.be.api.facade.SearchSchoolMajorFacade;
import com.ggang.be.api.school.service.SchoolService;
import com.ggang.be.api.schoolMajor.dto.SearchedSchoolMajorResponse;
import com.ggang.be.api.schoolMajor.service.SchoolMajorService;
import com.ggang.be.domain.school.application.School;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.mockito.Mockito.when;

class SearchSchoolMajorFacadeTest {

private final SchoolMajorService schoolMajorService = Mockito.mock(SchoolMajorService.class);
private final SchoolService schoolService = Mockito.mock(SchoolService.class);
private final SearchSchoolMajorFacade searchSchoolMajorFacade = new SearchSchoolMajorFacade(schoolMajorService, schoolService);

@DisplayName("학교 이름과 학과 키워드로 학과를 검색했을 때 결과를 반환한다.")
@Test
void searchSchoolMajorBySchoolName() {
// Given
String schoolName = "서울대학교";
String majorKeyword = "컴퓨터";
School mockSchool = School.builder().id(1L).schoolName("서울대학교").schoolDomain("서울대학교").build();
List<String> mockMajors = Arrays.asList("컴퓨터공학과", "컴퓨터과학과");

when(schoolService.findSchoolByName(schoolName)).thenReturn(mockSchool);
when(schoolMajorService.findSchoolMajorBySchoolAndMajorName(mockSchool.getId(), majorKeyword)).thenReturn(mockMajors);

// When
SearchedSchoolMajorResponse response = searchSchoolMajorFacade.searchSchoolMajorBySchoolName(schoolName, majorKeyword);

// Then
assertThat(response.schoolMajors()).containsExactly("컴퓨터공학과", "컴퓨터과학과");
}


@DisplayName("학교 이름이 잘못되었을 경우 예외가 발생하고 'NOT_FOUND' 응답을 반환한다.")
@Test
void searchSchoolMajorByInvalidSchoolName() {
// Given
String invalidSchoolName = "없는학교";
String majorKeyword = "컴퓨터";

when(schoolService.findSchoolByName(invalidSchoolName)).thenThrow(new GongBaekException(ResponseError.NOT_FOUND));

// When & Then
assertThatThrownBy(() -> searchSchoolMajorFacade.searchSchoolMajorBySchoolName(invalidSchoolName, majorKeyword)).isInstanceOf(GongBaekException.class).hasMessage(ResponseError.NOT_FOUND.getMessage());
}

@DisplayName("학교 이름이 null 일 경우 예외가 발생하고 'NOT_FOUND' 응답을 반환한다.")
@Test
void searchSchoolMajorBySchoolNameNull() {
// Given
String majorKeyword = "컴퓨터";

when(schoolService.findSchoolByName(null)).thenThrow(new GongBaekException(ResponseError.NOT_FOUND));

// When & Then
assertThatThrownBy(() -> searchSchoolMajorFacade.searchSchoolMajorBySchoolName(null, majorKeyword)).isInstanceOf(GongBaekException.class).hasMessage(ResponseError.NOT_FOUND.getMessage());
}

@DisplayName("학과 키워드가 없는 경우 빈 결과를 반환한다.")
@Test
void searchSchoolMajorWithoutKeyword() {
// Given
String schoolName = "서울대학교";
String emptyKeyword = "";
School mockSchool = School.builder().id(1L).schoolName("서울대학교").schoolDomain("서울대학교").build();

when(schoolService.findSchoolByName(schoolName)).thenReturn(mockSchool);
when(schoolMajorService.findSchoolMajorBySchoolAndMajorName(mockSchool.getId(), emptyKeyword)).thenReturn(Collections.emptyList());

// When
SearchedSchoolMajorResponse response = searchSchoolMajorFacade.searchSchoolMajorBySchoolName(schoolName, emptyKeyword);

// Then
assertThat(response.schoolMajors()).isEmpty();
}
}

0 comments on commit 686e2ea

Please sign in to comment.