Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#44] Domain(Facility, Reservation) 및 코드 개선 #45

Merged
merged 13 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/sonarcloud-analyze.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: F-Lab SonarCloud Code Analyze

on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

env:
CACHED_DEPENDENCIES_PATHS: '**/node_modules'

jobs:
CodeAnalyze:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set SonarCloud Project Key
run: |
REPO_NAME=$(echo $GITHUB_REPOSITORY | cut -d '/' -f 2)
ORG_NAME=$(echo $GITHUB_REPOSITORY | cut -d '/' -f 1)
SONAR_PROJECT_KEY="${ORG_NAME}_${REPO_NAME}"
echo "SONAR_PROJECT_KEY=$SONAR_PROJECT_KEY" >> $GITHUB_ENV

- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '19'
distribution: 'adopt'

- name: Create Sonar Gradle File
run: |
insert_string="plugins { id 'org.sonarqube' version '4.4.1.3373' }"
if [ -f "build.gradle" ]; then
echo "$insert_string" > temp.gradle
cat build.gradle >> temp.gradle
echo "" >> temp.gradle
echo "sonarqube {" >> temp.gradle
echo " properties {" >> temp.gradle
echo " property 'sonar.java.binaries', '**'" >> temp.gradle
echo " }" >> temp.gradle
echo "}" >> temp.gradle
mv temp.gradle build.gradle
else
echo "$insert_string" > build.gradle
echo "" >> build.gradle
echo "sonarqube {" >> build.gradle
echo " properties {" >> build.gradle
echo " property 'sonar.java.binaries', '**'" >> build.gradle
echo " }" >> build.gradle
echo "}" >> build.gradle
fi


- name: Analyze
run: ./gradlew sonar -Dsonar.projectKey=${{ env.SONAR_PROJECT_KEY }} -Dsonar.organization=f-lab-edu-1 -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=${{ secrets.SECRET_SONARQUBE }} -Dsonar.gradle.skipCompile=true
env:
SONAR_TOKEN: ${{ secrets.SECRET_SONARQUBE }}


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.modoospace.alarm.controller;

import com.modoospace.alarm.controller.dto.AlarmReadDto;
import com.modoospace.alarm.controller.dto.AlarmResponse;
import com.modoospace.alarm.service.AlarmService;
import com.modoospace.config.auth.LoginEmail;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,9 +22,9 @@ public class AlarmController {
private final AlarmService alarmService;

@GetMapping()
public ResponseEntity<Page<AlarmReadDto>> search(@LoginEmail String loginEmail,
public ResponseEntity<Page<AlarmResponse>> search(@LoginEmail String loginEmail,
Pageable pageable) {
Page<AlarmReadDto> alarms = alarmService.searchAlarms(loginEmail, pageable);
Page<AlarmResponse> alarms = alarmService.searchAlarms(loginEmail, pageable);
return ResponseEntity.ok().body(alarms);
}

Expand Down
94 changes: 47 additions & 47 deletions src/main/java/com/modoospace/alarm/controller/dto/AlarmEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,59 @@
@NoArgsConstructor
public class AlarmEvent {

@NotNull
private String email;
@NotNull
private String email;

@NotNull
private Long reservationId;
@NotNull
private Long reservationId;

@NotNull
private String facilityName;
@NotNull
private String facilityName;

@NotNull
private AlarmType alarmType;
@NotNull
private AlarmType alarmType;

@Builder
public AlarmEvent(String email, Long reservationId, String facilityName, AlarmType alarmType) {
this.email = email;
this.reservationId = reservationId;
this.facilityName = facilityName;
this.alarmType = alarmType;
}
@Builder
public AlarmEvent(String email, Long reservationId, String facilityName, AlarmType alarmType) {
this.email = email;
this.reservationId = reservationId;
this.facilityName = facilityName;
this.alarmType = alarmType;
}

public static AlarmEvent toNewReservationAlarm(Reservation reservation) {
return AlarmEvent.builder()
.email(reservation.getHost().getEmail())
.reservationId(reservation.getId())
.facilityName(reservation.getFacility().getFacilityName())
.alarmType(AlarmType.NEW_RESERVATION)
.build();
}
public static AlarmEvent ofNewReservationAlarm(Reservation reservation) {
return AlarmEvent.builder()
.email(reservation.getHost().getEmail())
.reservationId(reservation.getId())
.facilityName(reservation.getFacility().getName())
.alarmType(AlarmType.NEW_RESERVATION)
.build();
}

public static AlarmEvent toApprovedReservationAlarm(Reservation reservation) {
return AlarmEvent.builder()
.email(reservation.getVisitor().getEmail())
.reservationId(reservation.getId())
.facilityName(reservation.getFacility().getFacilityName())
.alarmType(AlarmType.APPROVED_RESERVATION)
.build();
}
public static AlarmEvent ofApprovedReservationAlarm(Reservation reservation) {
return AlarmEvent.builder()
.email(reservation.getVisitor().getEmail())
.reservationId(reservation.getId())
.facilityName(reservation.getFacility().getName())
.alarmType(AlarmType.APPROVED_RESERVATION)
.build();
}

public static AlarmEvent toCancelReservationAlarm(Reservation reservation) {
return AlarmEvent.builder()
.email(reservation.getHost().getEmail())
.reservationId(reservation.getId())
.facilityName(reservation.getFacility().getFacilityName())
.alarmType(AlarmType.CANCELED_RESERVATION)
.build();
}
public static AlarmEvent ofCancelReservationAlarm(Reservation reservation) {
return AlarmEvent.builder()
.email(reservation.getHost().getEmail())
.reservationId(reservation.getId())
.facilityName(reservation.getFacility().getName())
.alarmType(AlarmType.CANCELED_RESERVATION)
.build();
}

public Alarm toEntity() {
return Alarm.builder()
.email(email)
.reservationId(reservationId)
.facilityName(facilityName)
.alarmType(alarmType)
.build();
}
public Alarm toEntity() {
return Alarm.builder()
.email(email)
.reservationId(reservationId)
.facilityName(facilityName)
.alarmType(alarmType)
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.modoospace.alarm.controller.dto;

import com.modoospace.alarm.domain.AlarmType;
import java.io.Serializable;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class AlarmResponse implements Serializable {

@NotNull
private Long id;

@NotNull
private Long reservationId;

@NotNull
private String message;

@Builder
public AlarmResponse(Long id, Long reservationId, String facilityName, AlarmType alarmType) {
this.id = id;
this.reservationId = reservationId;
this.message = facilityName + alarmType.getAlarmText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static com.modoospace.alarm.domain.QAlarm.alarm;

import com.modoospace.alarm.controller.dto.AlarmReadDto;
import com.modoospace.alarm.controller.dto.AlarmResponse;
import com.modoospace.alarm.domain.Alarm;
import com.modoospace.member.domain.Member;
import com.querydsl.core.types.Projections;
Expand All @@ -24,11 +24,11 @@ public class AlarmQueryRepository {
private final JPAQueryFactory jpaQueryFactory;

@Cacheable(cacheNames = "searchAlarms", key = "#member.email +':'+ #pageable.pageNumber")
public Page<AlarmReadDto> searchByMember(Member member, Pageable pageable) {
public Page<AlarmResponse> searchByMember(Member member, Pageable pageable) {

List<AlarmReadDto> content = jpaQueryFactory
List<AlarmResponse> content = jpaQueryFactory
.select(
Projections.constructor(AlarmReadDto.class
Projections.constructor(AlarmResponse.class
, alarm.id
, alarm.reservationId
, alarm.facilityName
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/modoospace/alarm/service/AlarmService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.modoospace.alarm.service;

import com.modoospace.alarm.controller.dto.AlarmEvent;
import com.modoospace.alarm.controller.dto.AlarmReadDto;
import com.modoospace.alarm.controller.dto.AlarmResponse;
import com.modoospace.alarm.domain.Alarm;
import com.modoospace.alarm.domain.AlarmRepository;
import com.modoospace.alarm.repository.AlarmQueryRepository;
Expand Down Expand Up @@ -32,7 +32,7 @@ public class AlarmService {
private final AlarmQueryRepository alarmQueryRepository;
private final EmitterCacheRepository emitterRepository;

public Page<AlarmReadDto> searchAlarms(String loginEmail, Pageable pageable) {
public Page<AlarmResponse> searchAlarms(String loginEmail, Pageable pageable) {
Member loginMember = memberService.findMemberByEmail(loginEmail);

return alarmQueryRepository.searchByMember(loginMember, pageable);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/modoospace/common/DateFormatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@ public class DateFormatManager {
public static final String YEARMONTH_FORMAT = "yyyy-MM";

public static final String DATE_FORMAT = "yyyy-MM-dd";

public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";

public static final String TIME_FORMAT = "HH:mm:ss";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.modoospace.common.exception;

import com.modoospace.space.domain.FacilitySchedule;
import com.modoospace.space.domain.Schedule;
import com.modoospace.space.domain.TimeSetting;

public class ConflictingTimeException extends RuntimeException {
Expand All @@ -9,8 +9,7 @@ public ConflictingTimeException(TimeSetting timeSetting1, TimeSetting timeSettin
super(timeSetting1 + "과 " + timeSetting2 + " 시간이 겹칩니다.");
}

public ConflictingTimeException(FacilitySchedule facilitySchedule1,
FacilitySchedule facilitySchedule2) {
super(facilitySchedule1 + "과 " + facilitySchedule2 + " 시간이 겹칩니다.");
public ConflictingTimeException(Schedule schedule1, Schedule schedule2) {
super(schedule1 + "과 " + schedule2 + " 시간이 겹칩니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.modoospace.common.exception;

public class DeleteSpaceWithFacilitiesException extends RuntimeException {

private static final String message = "시설을 갖는 공간은 삭제할 수 없습니다.";

public DeleteSpaceWithFacilitiesException() {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.modoospace.common.exception;

public class InvalidHourException extends RuntimeException {

public InvalidHourException(Integer hour) {
super("올바른 시간이 아닙니다.(" + hour + ")");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.modoospace.common.exception;

public class InvalidNumOfUserException extends RuntimeException {

public InvalidNumOfUserException(Integer numOfUser) {
super("올바른 사용자 수가 아닙니다. (" + numOfUser + ")");
}

public InvalidNumOfUserException(Integer minUser, Integer maxUser) {
super("최소사용자수는 최대사용자수 보다 클 수 없습니다. (minUser=" + minUser + ", maxUser=" + maxUser + ")");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

public class InvalidTimeRangeException extends RuntimeException {

public InvalidTimeRangeException(LocalTime startTime, LocalTime endTime) {
super("시작시간(" + startTime.toString() + ") 은 종료시간(" + endTime.toString() + ") 보다 이후일 수 없습니다.");
}
public InvalidTimeRangeException(LocalTime startHour, LocalTime endHour) {
super("시작 시간(" + startHour + ") 은 마지막 시작 시간(" + endHour + ") 보다 이후일 수 없습니다.");
}

public InvalidTimeRangeException(LocalDateTime startDateTime, LocalDateTime endDateTime) {
super("시작시간(" + startDateTime.toString() + ") 은 종료시간(" + endDateTime.toString()
+ ") 보다 이후일 수 없습니다.");
}
public InvalidTimeRangeException(LocalDateTime startDate, LocalDateTime endDate) {
super("시작 시간(" + startDate.toString() + ") 은 마지막 시작 시간(" + endDate.toString()
+ ") 보다 이후일 수 없습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.modoospace.common.exception;

public class LimitNumOfUserException extends RuntimeException {

private static final String MESSAGE = "시설 허용 인원에 미달 또는 초과입니다.";

public LimitNumOfUserException() {
super(MESSAGE);
}
}
Loading
Loading