Skip to content

Commit

Permalink
Feature: 세션 데브톡 컨텐츠 추가 및 임베디드화 (#27)
Browse files Browse the repository at this point in the history
* feat: 세션 데브톡 컨텐츠 추가

* feat: 세션 컨텐츠 임베디드화

- SessionContents 임베디드 타입 추가
- 세션 리스트 반환 API Response 변경
- Jpa 메서드명 변경
  • Loading branch information
Youthhing authored Jun 18, 2024
1 parent 20641f4 commit c7db38b
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public ResponseEntity<List<SessionListResponse>> findSessionsByGenerationId(@Req
@PostMapping(value = "/add", consumes = "multipart/form-data")
public ResponseEntity<AddSessionResponse> addSession(@ModelAttribute @Valid AddSessionRequest request)
throws ImageException {
log.info("세션 추가 컨트롤러 : {}", request.description());
return ResponseEntity.status(HttpStatus.CREATED).body(sessionService.addSession(request));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cotato.csquiz.api.session.dto;

import org.cotato.csquiz.domain.generation.enums.CSEducation;
import org.cotato.csquiz.domain.generation.enums.DevTalk;
import org.cotato.csquiz.domain.generation.enums.ItIssue;
import org.cotato.csquiz.domain.generation.enums.Networking;
import jakarta.validation.constraints.NotNull;
Expand All @@ -14,6 +15,7 @@ public record AddSessionRequest(
String description,
ItIssue itIssue,
Networking networking,
CSEducation csEducation
CSEducation csEducation,
DevTalk devTalk
) {
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.cotato.csquiz.api.session.dto;

import org.cotato.csquiz.domain.generation.enums.CSEducation;
import org.cotato.csquiz.domain.generation.enums.ItIssue;
import org.cotato.csquiz.domain.generation.enums.Networking;
import org.cotato.csquiz.domain.generation.embedded.SessionContents;
import org.cotato.csquiz.domain.generation.entity.Session;

public record SessionListResponse(
Expand All @@ -11,9 +9,7 @@ public record SessionListResponse(
String photoUrl,
String description,
Long generationId,
ItIssue itIssue,
Networking networking,
CSEducation csEducation
SessionContents sessionContents
) {
public static SessionListResponse from(Session session) {
return new SessionListResponse(
Expand All @@ -22,9 +18,7 @@ public static SessionListResponse from(Session session) {
(session.getPhotoS3Info() != null) ? session.getPhotoS3Info().getUrl() : null,
session.getDescription(),
session.getGeneration().getId(),
session.getItIssue(),
session.getNetworking(),
session.getCsEducation()
session.getSessionContents()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cotato.csquiz.api.session.dto;

import org.cotato.csquiz.domain.generation.enums.CSEducation;
import org.cotato.csquiz.domain.generation.enums.DevTalk;
import org.cotato.csquiz.domain.generation.enums.ItIssue;
import org.cotato.csquiz.domain.generation.enums.Networking;
import jakarta.validation.constraints.NotNull;
Expand All @@ -18,6 +19,9 @@ public record UpdateSessionRequest(
@NotNull
Networking networking,
@NotNull
CSEducation csEducation
CSEducation csEducation,

@NotNull
DevTalk devTalk
) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cotato.csquiz.common.entity;
package org.cotato.csquiz.domain.generation.embedded;

import jakarta.persistence.Embeddable;
import java.time.LocalDate;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.cotato.csquiz.domain.generation.embedded;

import jakarta.persistence.Embeddable;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.cotato.csquiz.domain.generation.enums.CSEducation;
import org.cotato.csquiz.domain.generation.enums.DevTalk;
import org.cotato.csquiz.domain.generation.enums.ItIssue;
import org.cotato.csquiz.domain.generation.enums.Networking;
import org.hibernate.annotations.ColumnDefault;

@Embeddable
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class SessionContents {

@Enumerated(EnumType.STRING)
@ColumnDefault(value = "'IT_OFF'")
private ItIssue itIssue;

@Enumerated(EnumType.STRING)
@ColumnDefault(value = "'NW_OFF'")
private Networking networking;

@Enumerated(EnumType.STRING)
@ColumnDefault(value = "'CS_OFF'")
private CSEducation csEducation;

@Enumerated(EnumType.STRING)
@ColumnDefault(value = "'DEVTALK_OFF'")
private DevTalk devTalk;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Persistence;
import java.time.LocalDate;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.cotato.csquiz.common.entity.BaseTimeEntity;
import org.cotato.csquiz.common.entity.GenerationPeriod;
import org.cotato.csquiz.domain.generation.embedded.GenerationPeriod;

@Entity
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import static jakarta.persistence.FetchType.LAZY;

import jakarta.persistence.AttributeOverride;
import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand All @@ -16,12 +16,9 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.cotato.csquiz.common.entity.S3Info;
import org.cotato.csquiz.domain.generation.enums.CSEducation;
import org.cotato.csquiz.domain.generation.enums.ItIssue;
import org.cotato.csquiz.domain.generation.enums.Networking;
import org.cotato.csquiz.common.entity.BaseTimeEntity;
import org.hibernate.annotations.ColumnDefault;
import org.cotato.csquiz.common.entity.S3Info;
import org.cotato.csquiz.domain.generation.embedded.SessionContents;
import org.hibernate.annotations.DynamicInsert;

@Entity
Expand All @@ -48,34 +45,28 @@ public class Session extends BaseTimeEntity {
@JoinColumn(name = "generation_id")
private Generation generation;

@Column(name = "session_it_issue")
@Enumerated(EnumType.STRING)
@ColumnDefault(value = "'IT_OFF'")
private ItIssue itIssue;

@Column(name = "session_networking")
@Enumerated(EnumType.STRING)
@ColumnDefault(value = "'NW_OFF'")
private Networking networking;

@Column(name = "session_cs_education")
@Enumerated(EnumType.STRING)
@ColumnDefault(value = "'CS_OFF'")
private CSEducation csEducation;
@AttributeOverrides({
@AttributeOverride(name = "itIssue",
column = @Column(name = "session_it_issue")),
@AttributeOverride(name = "networking",
column = @Column(name = "session_networking")),
@AttributeOverride(name = "csEducation",
column = @Column(name = "session_cs_education")),
@AttributeOverride(name = "devTalk",
column = @Column(name = "session_dev_talk"))
})
private SessionContents sessionContents;

@Builder
public Session(int number, S3Info s3Info, String description, Generation generation, ItIssue itIssue,
CSEducation csEducation, Networking networking) {
public Session(Integer number, S3Info s3Info, String description, Generation generation, SessionContents sessionContents) {
this.number = number;
this.photoS3Info = s3Info;
this.description = description;
this.generation = generation;
this.itIssue = itIssue;
this.csEducation = csEducation;
this.networking = networking;
this.sessionContents = sessionContents;
}

public void changeSessionNumber(int sessionNumber) {
public void changeSessionNumber(Integer sessionNumber) {
this.number = sessionNumber;
}

Expand All @@ -87,9 +78,7 @@ public void changePhotoUrl(S3Info photoUrl) {
this.photoS3Info = photoUrl;
}

public void updateToggle(ItIssue itIssue, CSEducation csEducation, Networking networking) {
this.itIssue = itIssue;
this.csEducation = csEducation;
this.networking = networking;
public void updateSessionContents(SessionContents sessionContents) {
this.sessionContents = sessionContents;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.cotato.csquiz.domain.generation.enums;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum DevTalk {
ON("데브톡 존재"),
OFF("데브톡 없음")
;
private final String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
public interface SessionRepository extends JpaRepository<Session, Long> {
List<Session> findAllByGeneration(Generation generation);

List<Session> findAllByGenerationAndCsEducation(Generation generation, CSEducation csEducation);
List<Session> findAllByGenerationAndSessionContentsCsEducation(Generation generation, CSEducation csEducation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.cotato.csquiz.api.generation.dto.ChangeGenerationPeriodRequest;
import org.cotato.csquiz.api.generation.dto.ChangeRecruitingStatusRequest;
import org.cotato.csquiz.api.generation.dto.GenerationInfoResponse;
import org.cotato.csquiz.common.entity.GenerationPeriod;
import org.cotato.csquiz.domain.generation.embedded.GenerationPeriod;
import org.cotato.csquiz.domain.generation.entity.Generation;
import org.cotato.csquiz.common.error.exception.AppException;
import org.cotato.csquiz.common.error.ErrorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.cotato.csquiz.common.entity.S3Info;
import org.cotato.csquiz.domain.education.entity.Education;
import org.cotato.csquiz.domain.education.service.EducationService;
import org.cotato.csquiz.domain.generation.embedded.SessionContents;
import org.cotato.csquiz.domain.generation.enums.CSEducation;
import org.cotato.csquiz.domain.generation.entity.Generation;
import org.cotato.csquiz.domain.generation.entity.Session;
Expand Down Expand Up @@ -54,9 +55,12 @@ public AddSessionResponse addSession(AddSessionRequest request) throws ImageExce
.s3Info(s3Info)
.description(request.description())
.generation(findGeneration)
.itIssue(request.itIssue())
.csEducation(request.csEducation())
.networking(request.networking())
.sessionContents(SessionContents.builder()
.csEducation(request.csEducation())
.devTalk(request.devTalk())
.itIssue(request.itIssue())
.networking(request.networking())
.build())
.build();
Session savedSession = sessionRepository.save(session);
log.info("세션 생성 완료");
Expand Down Expand Up @@ -87,8 +91,12 @@ public void updateSession(UpdateSessionRequest request) throws ImageException {
Session session = findSessionById(request.sessionId());

session.updateDescription(request.description());
session.updateToggle(request.itIssue(), request.csEducation(),
request.networking());
session.updateSessionContents(SessionContents.builder()
.csEducation(request.csEducation())
.devTalk(request.devTalk())
.itIssue(request.itIssue())
.networking(request.networking())
.build());
if (request.isPhotoUpdated()) {
updatePhoto(session, request.sessionImage());
}
Expand Down Expand Up @@ -139,7 +147,7 @@ public Session findSessionById(Long sessionId) {
public List<CsEducationOnSessionNumberResponse> findAllNotLinkedCsOnSessionsByGenerationId(Long generationId) {
Generation generation = generationRepository.findById(generationId)
.orElseThrow(() -> new EntityNotFoundException("해당 기수를 찾을 수 없습니다."));
List<Session> sessions = sessionRepository.findAllByGenerationAndCsEducation(generation, CSEducation.CS_ON);
List<Session> sessions = sessionRepository.findAllByGenerationAndSessionContentsCsEducation(generation, CSEducation.CS_ON);

List<Long> educationLinkedSessionIds = educationService.findAllEducationByGenerationId(generationId).stream()
.map(Education::getSessionId)
Expand Down

0 comments on commit c7db38b

Please sign in to comment.