Skip to content

Commit

Permalink
Merge pull request #219 from sopt-makers/sohyeon_#186
Browse files Browse the repository at this point in the history
[REFACTOR] Lecture 관련 리팩토링
  • Loading branch information
thguss authored Jan 23, 2024
2 parents c8bb76b + cb9f465 commit 51bb92c
Show file tree
Hide file tree
Showing 26 changed files with 843 additions and 358 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
implementation "com.querydsl:querydsl-apt:${queryDslVersion}"
testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.1'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
Expand All @@ -48,6 +50,9 @@ dependencies {
// swagger
implementation 'io.springfox:springfox-boot-starter:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'

// gson
implementation 'com.google.code.gson:gson:2.8.9'
}

tasks.named('test') {
Expand Down

This file was deleted.

23 changes: 23 additions & 0 deletions src/main/java/org/sopt/makers/operation/config/ValueConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sopt.makers.operation.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import lombok.Getter;

@Configuration
@Getter
public class ValueConfig {

@Value("${sopt.alarm.message.title_end}")
private String ALARM_MESSAGE_TITLE;
@Value("${sopt.alarm.message.content_end}")
private String ALARM_MESSAGE_CONTENT;
@Value("${sopt.current.generation}")
private int GENERATION;

private final int SUB_LECTURE_MAX_ROUND = 2;
private final String ETC_MESSAGE = "출석 점수가 반영되지 않아요.";
private final String SEMINAR_MESSAGE = "";
private final String EVENT_MESSAGE = "행사도 참여하고, 출석점수도 받고, 일석이조!";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ScheduleController {

@Scheduled(cron = "0 0 0 ? * SUN")
public void endLecture() {
lectureService.finishLecture();
lectureService.endLectures();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.sopt.makers.operation.controller.app;


import static java.util.Objects.*;
import static org.sopt.makers.operation.common.ResponseMessage.*;

import io.swagger.annotations.ApiOperation;
Expand All @@ -19,11 +17,14 @@
@RequiredArgsConstructor
@RequestMapping("/api/v1/app/lectures")
public class AppLectureController {

private final LectureService lectureService;
@ApiOperation(value = "단일 세미나 상태 조회")

@ApiOperation(value = "진행 중인 세미나 상태 조회")
@GetMapping
public ResponseEntity<ApiResponse> getLecture(@ApiIgnore Principal principal) {
val response = lectureService.getCurrentLecture(getMemberId(principal));
val memberPlaygroundId = Long.parseLong(principal.getName());
val response = lectureService.getTodayLecture(memberPlaygroundId);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_SINGLE_GET_LECTURE.getMessage(), response));
}

Expand All @@ -33,8 +34,4 @@ public ResponseEntity<ApiResponse> getRound(@PathVariable("lectureId") Long lect
val response = lectureService.getCurrentLectureRound(lectureId);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_LECTURE_ROUND.getMessage(), response));
}

private Long getMemberId(Principal principal) {
return nonNull(principal) ? Long.valueOf(principal.getName()) : null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.makers.operation.controller.web;

import static org.sopt.makers.operation.common.ApiResponse.*;
import static org.sopt.makers.operation.common.ResponseMessage.*;

import java.net.URI;
Expand Down Expand Up @@ -39,22 +40,21 @@ public ResponseEntity<ApiResponse> createLecture(@RequestBody LectureRequestDTO
val lectureId = lectureService.createLecture(requestDTO);
return ResponseEntity
.created(getURI(lectureId))
.body(ApiResponse.success(SUCCESS_CREATE_LECTURE.getMessage(), lectureId));
.body(success(SUCCESS_CREATE_LECTURE.getMessage(), lectureId));
}

@ApiOperation(value = "세션 리스트 조회")
@GetMapping
public ResponseEntity<ApiResponse> getLecturesByGeneration(
@RequestParam("generation") int generation, @RequestParam(required = false) Part part) {
val response = lectureService.getLecturesByGeneration(generation, part);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_LECTURES.getMessage(), response));
public ResponseEntity<ApiResponse> getLectures(@RequestParam int generation, @RequestParam(required = false) Part part) {
val response = lectureService.getLectures(generation, part);
return ResponseEntity.ok(success(SUCCESS_GET_LECTURES.getMessage(), response));
}

@ApiOperation(value = "세션 상세 조회")
@ApiOperation(value = "세션 단일 조회")
@GetMapping("/{lectureId}")
public ResponseEntity<ApiResponse> getLecture(@PathVariable Long lectureId) {
val response = lectureService.getLecture(lectureId);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_LECTURE.getMessage(), response));
return ResponseEntity.ok(success(SUCCESS_GET_LECTURE.getMessage(), response));
}

@ApiOperation(value = "출석 시작")
Expand All @@ -63,35 +63,35 @@ public ResponseEntity<ApiResponse> startAttendance(@RequestBody AttendanceReques
val response = lectureService.startAttendance(requestDTO);
return ResponseEntity
.created(getURI(requestDTO.lectureId()))
.body(ApiResponse.success(SUCCESS_START_ATTENDANCE.getMessage(), response));
.body(success(SUCCESS_START_ATTENDANCE.getMessage(), response));
}

@ApiOperation(value = "출석 점수 갱신 트리거 (출석 종료)")
private URI getURI(Long lectureId) {
return ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{lectureId}")
.buildAndExpand(lectureId)
.toUri();
}

@ApiOperation(value = "세션 종료 후 출석 점수 갱신")
@PatchMapping("/{lectureId}")
public ResponseEntity<ApiResponse> finishLecture(@PathVariable("lectureId") Long lectureId) {
lectureService.finishLecture(lectureId);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_UPDATE_MEMBER_SCORE.getMessage()));
public ResponseEntity<ApiResponse> endLecture(@PathVariable Long lectureId) {
lectureService.endLecture(lectureId);
return ResponseEntity.ok(success(SUCCESS_UPDATE_MEMBER_SCORE.getMessage()));
}

@ApiOperation(value = "세션 삭제")
@DeleteMapping("/{lectureId}")
public ResponseEntity<ApiResponse> deleteLecture(@PathVariable Long lectureId) {
lectureService.deleteLecture(lectureId);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_DELETE_LECTURE.getMessage()));
return ResponseEntity.ok(success(SUCCESS_DELETE_LECTURE.getMessage()));
}

@ApiOperation(value = "세션 상세 조회 (팝업)")
@ApiOperation(value = "세션 팝업용 상세 조회")
@GetMapping("/detail/{lectureId}")
public ResponseEntity<ApiResponse> getLectureDetail(@PathVariable Long lectureId) {
val response = lectureService.getLectureDetail(lectureId);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_LECTURE.getMessage(), response));
}

private URI getURI(Long lectureId) {
return ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{lectureId}")
.buildAndExpand(lectureId)
.toUri();
return ResponseEntity.ok(success(SUCCESS_GET_LECTURE.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package org.sopt.makers.operation.dto.lecture;

public record AttendanceResponseDTO(Long lectureId, Long subLectureId) {
import org.sopt.makers.operation.entity.SubLecture;
import org.sopt.makers.operation.entity.lecture.Lecture;

import lombok.Builder;

@Builder
public record AttendanceResponseDTO(
Long lectureId,
Long subLectureId
) {

public static AttendanceResponseDTO of(Lecture lecture, SubLecture subLecture) {
return AttendanceResponseDTO.builder()
.lectureId(lecture.getId())
.subLectureId(subLecture.getId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import lombok.*;

@Builder
public record LectureRequestDTO(
@NonNull Part part,
@NonNull String name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.sopt.makers.operation.dto.lecture;

import static java.util.Objects.*;

import java.time.LocalDateTime;
import java.util.List;

import org.sopt.makers.operation.entity.Part;
Expand Down Expand Up @@ -35,16 +37,25 @@ public static LectureResponseDTO of(Lecture lecture) {
.status(lecture.getLectureStatus())
.build();
}
}

record SubLectureVO(
Long subLectureId,
int round,
String startAt,
String code
) {
static SubLectureVO of(SubLecture subLecture) {
val startAt = nonNull(subLecture.getStartAt()) ? subLecture.getStartAt().toString() : null;
return new SubLectureVO(subLecture.getId(), subLecture.getRound(), startAt, subLecture.getCode());
@Builder
public record SubLectureVO(
Long subLectureId,
int round,
String startAt,
String code
) {
private static SubLectureVO of(SubLecture subLecture) {
return SubLectureVO.builder()
.subLectureId(subLecture.getId())
.round(subLecture.getRound())
.startAt(getStartAt(subLecture.getStartAt()))
.code(subLecture.getCode())
.build();
}

private static String getStartAt(LocalDateTime startAt) {
return nonNull(startAt) ? startAt.toString() : null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,44 @@
import lombok.*;

public record LecturesResponseDTO(
int generation,
List<LectureVO> lectures
int generation,
List<LectureVO> lectures
) {

public static LecturesResponseDTO of(int generation, List<Lecture> lectures) {
return new LecturesResponseDTO(
generation,
lectures.stream().map(LectureVO::of).toList()
generation,
lectures.stream().map(LectureVO::of).toList()
);
}
}

@Builder
record LectureVO(
Long lectureId,
String name,
Part partValue,
String partName,
String startDate,
String endDate,
Attribute attributeValue,
String attributeName,
String place,
AttendancesStatusVO attendances
) {
public static LectureVO of(Lecture lecture) {
return LectureVO.builder()
.lectureId(lecture.getId())
.name(lecture.getName())
.partValue(lecture.getPart())
.partName(lecture.getPart().getName())
.startDate(lecture.getStartDate().toString())
.endDate(lecture.getEndDate().toString())
.attributeValue(lecture.getAttribute())
.attributeName(lecture.getAttribute().getName())
.place(lecture.getPlace())
.attendances(AttendancesStatusVO.of(lecture))
.build();
@Builder
public record LectureVO(
Long lectureId,
String name,
Part partValue,
String partName,
String startDate,
String endDate,
Attribute attributeValue,
String attributeName,
String place,
AttendancesStatusVO attendances
) {
private static LectureVO of(Lecture lecture) {
return LectureVO.builder()
.lectureId(lecture.getId())
.name(lecture.getName())
.partValue(lecture.getPart())
.partName(lecture.getPart().getName())
.startDate(lecture.getStartDate().toString())
.endDate(lecture.getEndDate().toString())
.attributeValue(lecture.getAttribute())
.attributeName(lecture.getAttribute().getName())
.place(lecture.getPlace())
.attendances(AttendancesStatusVO.of(lecture))
.build();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.stream.Collectors;

@Builder
public record LectureGetResponseDTO(
public record TodayLectureResponseDTO(
LectureResponseType type,
Long id,
String location,
Expand All @@ -21,9 +21,9 @@ public record LectureGetResponseDTO(
String message,
List<LectureGetResponseVO> attendances
) {
public static LectureGetResponseDTO of(LectureResponseType type, Lecture lecture, String message, List<SubAttendance> attendances) {
public static TodayLectureResponseDTO of(LectureResponseType type, Lecture lecture, String message, List<SubAttendance> attendances) {

return LectureGetResponseDTO.builder()
return TodayLectureResponseDTO.builder()
.type(type)
.id(lecture.getId())
.location(lecture.getPlace())
Expand All @@ -40,22 +40,22 @@ public static LectureGetResponseDTO of(LectureResponseType type, Lecture lecture
private static DateTimeFormatter convertFormat() {
return DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
}
}

@Builder
record LectureGetResponseVO(
AttendanceStatus status,
String attendedAt

) {
public static LectureGetResponseVO of(AttendanceStatus status, LocalDateTime attendedAt) {
return LectureGetResponseVO.builder()
.status(status)
.attendedAt(attendedAt.format((convertFormat())))
.build();
}

private static DateTimeFormatter convertFormat() {
return DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
@Builder
record LectureGetResponseVO(
AttendanceStatus status,
String attendedAt

) {
public static LectureGetResponseVO of(AttendanceStatus status, LocalDateTime attendedAt) {
return LectureGetResponseVO.builder()
.status(status)
.attendedAt(attendedAt.format((convertFormat())))
.build();
}

private static DateTimeFormatter convertFormat() {
return DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
}
}
}
Loading

0 comments on commit 51bb92c

Please sign in to comment.