From ad76e6687f17e3e62d41fccabfd3e0584dbae3cb Mon Sep 17 00:00:00 2001 From: koreaioi Date: Tue, 12 Nov 2024 02:49:27 +0900 Subject: [PATCH 01/19] =?UTF-8?q?feat:=20=EC=A0=95=EA=B7=9C=20=EC=84=B8?= =?UTF-8?q?=EC=85=98=20=EB=93=B1=EB=A1=9D=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/session/entity/Session.java | 10 ++++++ .../entity/controller/SessionController.java | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/com/tave/tavewebsite/domain/session/entity/controller/SessionController.java diff --git a/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java b/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java index 0659679..519a6a6 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java @@ -1,5 +1,6 @@ package com.tave.tavewebsite.domain.session.entity; +import com.tave.tavewebsite.domain.session.entity.dto.request.SessionRequestDto; import com.tave.tavewebsite.global.common.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; @@ -47,4 +48,13 @@ public Session(String title, String description, boolean isPublic, String imgUrl this.isPublic = isPublic; this.imgUrl = imgUrl; } + + public static Session of(SessionRequestDto sessionRequestDto, java.net.URL imgUrl) { + return Session.builder() + .title(sessionRequestDto.title()) + .description(sessionRequestDto.description()) + .isPublic(sessionRequestDto.isPublic()) + .imgUrl(imgUrl.toString()) + .build(); + } } diff --git a/src/main/java/com/tave/tavewebsite/domain/session/entity/controller/SessionController.java b/src/main/java/com/tave/tavewebsite/domain/session/entity/controller/SessionController.java new file mode 100644 index 0000000..e60b889 --- /dev/null +++ b/src/main/java/com/tave/tavewebsite/domain/session/entity/controller/SessionController.java @@ -0,0 +1,31 @@ +package com.tave.tavewebsite.domain.session.entity.controller; + +import com.tave.tavewebsite.domain.session.entity.dto.request.SessionRequestDto; +import com.tave.tavewebsite.domain.session.entity.dto.response.SessionResponseDto; +import com.tave.tavewebsite.domain.session.entity.service.SessionService; +import com.tave.tavewebsite.global.success.SuccessResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import static com.tave.tavewebsite.domain.session.entity.controller.SuccessMessage.*; + +@Slf4j +@RestController +@RequiredArgsConstructor +public class SessionController { + + private final SessionService sessionService; + + @PostMapping + public SuccessResponse registerSession(@RequestBody SessionRequestDto sessionRequestDto, MultipartFile file){ + SessionResponseDto response = sessionService.saveSession(sessionRequestDto, file); + + return new SuccessResponse<>(response, SESSION_SUCCESS_REGISTER.getMessage()); + } + + +} From e84be8ca037f2afc9782ef580af1c7d250ae342d Mon Sep 17 00:00:00 2001 From: koreaioi Date: Tue, 12 Nov 2024 03:42:49 +0900 Subject: [PATCH 02/19] =?UTF-8?q?feat:=20Session=20-=20generation=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tavewebsite/domain/session/entity/Session.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java b/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java index 519a6a6..59ee71d 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java @@ -1,6 +1,6 @@ package com.tave.tavewebsite.domain.session.entity; -import com.tave.tavewebsite.domain.session.entity.dto.request.SessionRequestDto; +import com.tave.tavewebsite.domain.session.dto.request.SessionRequestDto; import com.tave.tavewebsite.global.common.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; @@ -32,6 +32,10 @@ public class Session extends BaseEntity { @Column(nullable = false) private String description; + @Size(min = 1, max = 5) + @Column(length = 5) + private String generation; + @NotNull @Column(nullable = false) private boolean isPublic; @@ -42,9 +46,10 @@ public class Session extends BaseEntity { private String imgUrl; @Builder - public Session(String title, String description, boolean isPublic, String imgUrl) { + public Session(String title, String description, String generation,boolean isPublic, String imgUrl) { this.title = title; this.description = description; + this.generation = generation; this.isPublic = isPublic; this.imgUrl = imgUrl; } @@ -53,6 +58,7 @@ public static Session of(SessionRequestDto sessionRequestDto, java.net.URL imgUr return Session.builder() .title(sessionRequestDto.title()) .description(sessionRequestDto.description()) + .generation(sessionRequestDto.generation()) .isPublic(sessionRequestDto.isPublic()) .imgUrl(imgUrl.toString()) .build(); From 029dabde94aec0ea0b198e294d0b17e7be778279 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Tue, 12 Nov 2024 03:43:14 +0900 Subject: [PATCH 03/19] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=EC=99=80=20?= =?UTF-8?q?=EA=B3=B5=EA=B0=9C=EC=97=AC=EB=B6=80=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/session/repository/SessionRepository.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/tave/tavewebsite/domain/session/repository/SessionRepository.java diff --git a/src/main/java/com/tave/tavewebsite/domain/session/repository/SessionRepository.java b/src/main/java/com/tave/tavewebsite/domain/session/repository/SessionRepository.java new file mode 100644 index 0000000..503d52f --- /dev/null +++ b/src/main/java/com/tave/tavewebsite/domain/session/repository/SessionRepository.java @@ -0,0 +1,11 @@ +package com.tave.tavewebsite.domain.session.repository; + +import com.tave.tavewebsite.domain.session.entity.Session; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface SessionRepository extends JpaRepository { + + List findByGenerationAndIsPublic(String generation, boolean isPublic); +} From d35df8efc198c495adad7fa59194d23e7f613ed1 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Tue, 12 Nov 2024 03:44:49 +0900 Subject: [PATCH 04/19] =?UTF-8?q?feat:=20SessionService=20save()=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session/service/SessionService.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java diff --git a/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java b/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java new file mode 100644 index 0000000..8359b93 --- /dev/null +++ b/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java @@ -0,0 +1,34 @@ +package com.tave.tavewebsite.domain.session.service; + +import com.tave.tavewebsite.domain.session.entity.Session; +import com.tave.tavewebsite.domain.session.dto.request.SessionRequestDto; +import com.tave.tavewebsite.domain.session.dto.response.SessionResponseDto; +import com.tave.tavewebsite.domain.session.repository.SessionRepository; +import com.tave.tavewebsite.global.s3.service.S3Service; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.net.URL; + +@Slf4j +@Service +@RequiredArgsConstructor +public class SessionService { + + private final SessionRepository sessionRepository; + private final S3Service s3Service; + + public SessionResponseDto saveSession(SessionRequestDto sessionRequestDto, MultipartFile file) { + + // 이미지 업로드 후 저장 + URL savedImageUrl = s3Service.uploadImages(file); + log.info(savedImageUrl.toString()); + + // RequestDto -> Entity -> save() -> ResponseDto + Session savedSession = sessionRepository.save(Session.of(sessionRequestDto, savedImageUrl)); + return SessionResponseDto.from(savedSession); + } + +} From b6e8dcf7626117a9d76044e8eccd578d42bd0dfa Mon Sep 17 00:00:00 2001 From: koreaioi Date: Tue, 12 Nov 2024 03:45:04 +0900 Subject: [PATCH 05/19] =?UTF-8?q?feat:=20SessionResponseDto=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/SessionResponseDto.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/com/tave/tavewebsite/domain/session/dto/response/SessionResponseDto.java diff --git a/src/main/java/com/tave/tavewebsite/domain/session/dto/response/SessionResponseDto.java b/src/main/java/com/tave/tavewebsite/domain/session/dto/response/SessionResponseDto.java new file mode 100644 index 0000000..669606b --- /dev/null +++ b/src/main/java/com/tave/tavewebsite/domain/session/dto/response/SessionResponseDto.java @@ -0,0 +1,24 @@ +package com.tave.tavewebsite.domain.session.dto.response; + +import com.tave.tavewebsite.domain.session.entity.Session; + +public record SessionResponseDto( + Long sessionId, + String title, + String description, + String generation, + boolean isPublic, + String imgUrl + +) { + public static SessionResponseDto from(Session session) { + return new SessionResponseDto( + session.getId(), + session.getTitle(), + session.getDescription(), + session.getGeneration(), + session.isPublic(), + session.getImgUrl() + ); + } +} From beb3fd1d97b08ccc64dded07a80fdab1efeb658b Mon Sep 17 00:00:00 2001 From: koreaioi Date: Tue, 12 Nov 2024 03:45:16 +0900 Subject: [PATCH 06/19] =?UTF-8?q?feat:=20SessionRequestDto=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session/dto/request/SessionRequestDto.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/com/tave/tavewebsite/domain/session/dto/request/SessionRequestDto.java diff --git a/src/main/java/com/tave/tavewebsite/domain/session/dto/request/SessionRequestDto.java b/src/main/java/com/tave/tavewebsite/domain/session/dto/request/SessionRequestDto.java new file mode 100644 index 0000000..94b6ee5 --- /dev/null +++ b/src/main/java/com/tave/tavewebsite/domain/session/dto/request/SessionRequestDto.java @@ -0,0 +1,13 @@ +package com.tave.tavewebsite.domain.session.dto.request; + +import com.tave.tavewebsite.domain.session.entity.Session; + +public record SessionRequestDto( + + String title, + String description, + String generation, + boolean isPublic + +) { +} From 0e686c97a525b75d8cc08abe018ee9eab8c50793 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Tue, 12 Nov 2024 03:45:48 +0900 Subject: [PATCH 07/19] =?UTF-8?q?feat:=20SessionController=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session/controller/SessionController.java | 30 ++++++++++++++++++ .../entity/controller/SessionController.java | 31 ------------------- 2 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java delete mode 100644 src/main/java/com/tave/tavewebsite/domain/session/entity/controller/SessionController.java diff --git a/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java b/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java new file mode 100644 index 0000000..73eed3f --- /dev/null +++ b/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java @@ -0,0 +1,30 @@ +package com.tave.tavewebsite.domain.session.controller; + +import com.tave.tavewebsite.domain.session.dto.request.SessionRequestDto; +import com.tave.tavewebsite.domain.session.dto.response.SessionResponseDto; +import com.tave.tavewebsite.domain.session.service.SessionService; +import com.tave.tavewebsite.global.success.SuccessResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import static com.tave.tavewebsite.domain.session.controller.SuccessMessage.*; + +@Slf4j +@RestController +@RequestMapping("/api/v1/session") +@RequiredArgsConstructor +public class SessionController { + + private final SessionService sessionService; + + @PostMapping + public SuccessResponse registerSession(@ModelAttribute SessionRequestDto sessionRequestDto, MultipartFile file){ + SessionResponseDto response = sessionService.saveSession(sessionRequestDto, file); + + return new SuccessResponse<>(response, SESSION_SUCCESS_REGISTER.getMessage()); + } + + +} diff --git a/src/main/java/com/tave/tavewebsite/domain/session/entity/controller/SessionController.java b/src/main/java/com/tave/tavewebsite/domain/session/entity/controller/SessionController.java deleted file mode 100644 index e60b889..0000000 --- a/src/main/java/com/tave/tavewebsite/domain/session/entity/controller/SessionController.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.tave.tavewebsite.domain.session.entity.controller; - -import com.tave.tavewebsite.domain.session.entity.dto.request.SessionRequestDto; -import com.tave.tavewebsite.domain.session.entity.dto.response.SessionResponseDto; -import com.tave.tavewebsite.domain.session.entity.service.SessionService; -import com.tave.tavewebsite.global.success.SuccessResponse; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -import static com.tave.tavewebsite.domain.session.entity.controller.SuccessMessage.*; - -@Slf4j -@RestController -@RequiredArgsConstructor -public class SessionController { - - private final SessionService sessionService; - - @PostMapping - public SuccessResponse registerSession(@RequestBody SessionRequestDto sessionRequestDto, MultipartFile file){ - SessionResponseDto response = sessionService.saveSession(sessionRequestDto, file); - - return new SuccessResponse<>(response, SESSION_SUCCESS_REGISTER.getMessage()); - } - - -} From 89aa8908ae1cd1b201c14818f03d1b3b7c258ab7 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:38:54 +0900 Subject: [PATCH 08/19] =?UTF-8?q?feat:=20=EA=B8=B0=EC=88=98=EB=B3=84=20?= =?UTF-8?q?=EC=84=B8=EC=85=98=20=EC=A1=B0=ED=9A=8C=20+=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session/controller/SessionController.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java b/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java index 73eed3f..75a8d09 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java @@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + import static com.tave.tavewebsite.domain.session.controller.SuccessMessage.*; @Slf4j @@ -20,11 +22,18 @@ public class SessionController { private final SessionService sessionService; @PostMapping - public SuccessResponse registerSession(@ModelAttribute SessionRequestDto sessionRequestDto, MultipartFile file){ + public SuccessResponse registerSession(@RequestPart(name = "request") SessionRequestDto sessionRequestDto, + @RequestPart(name = "file", required = false) MultipartFile file){ SessionResponseDto response = sessionService.saveSession(sessionRequestDto, file); return new SuccessResponse<>(response, SESSION_SUCCESS_REGISTER.getMessage()); } - + @GetMapping("/{generation}/{page}/{size}") + public SuccessResponse> getSession(@PathVariable String generation, + @PathVariable int page, + @PathVariable int size){ + List response = sessionService.findSessionByGeneration(generation, page, size); + return new SuccessResponse<>(response, SESSION_SUCCESS_REGISTER.getMessage()); + } } From 38fe235487e6be27b806821860d497080083b000 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:39:29 +0900 Subject: [PATCH 09/19] =?UTF-8?q?feat:=20=EC=84=9C=EB=B9=84=EC=8A=A4=20-?= =?UTF-8?q?=20=EA=B8=B0=EC=88=98=EB=B3=84=20=EC=84=B8=EC=85=98=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/session/service/SessionService.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java b/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java index 8359b93..3c0d2e3 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java @@ -3,14 +3,18 @@ import com.tave.tavewebsite.domain.session.entity.Session; import com.tave.tavewebsite.domain.session.dto.request.SessionRequestDto; import com.tave.tavewebsite.domain.session.dto.response.SessionResponseDto; +import com.tave.tavewebsite.domain.session.exception.SessionNotFoundException; import com.tave.tavewebsite.domain.session.repository.SessionRepository; import com.tave.tavewebsite.global.s3.service.S3Service; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.net.URL; +import java.util.List; @Slf4j @Service @@ -21,14 +25,18 @@ public class SessionService { private final S3Service s3Service; public SessionResponseDto saveSession(SessionRequestDto sessionRequestDto, MultipartFile file) { - - // 이미지 업로드 후 저장 URL savedImageUrl = s3Service.uploadImages(file); - log.info(savedImageUrl.toString()); - - // RequestDto -> Entity -> save() -> ResponseDto Session savedSession = sessionRepository.save(Session.of(sessionRequestDto, savedImageUrl)); return SessionResponseDto.from(savedSession); } + public List findSessionByGeneration(String generation, int page, int size) { + return sessionRepository.findByGenerationAndIsPublic(generation, true, PageRequest.of(page- 1, size)) + .getContent() + .stream() + .map(SessionResponseDto::from) + .toList(); + } + + } From ffed24c0f9863e9650d82b11a36ddee7ab777869 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:40:04 +0900 Subject: [PATCH 10/19] =?UTF-8?q?feat:=20SessionRepository=20-=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/session/repository/SessionRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/repository/SessionRepository.java b/src/main/java/com/tave/tavewebsite/domain/session/repository/SessionRepository.java index 503d52f..520503d 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/repository/SessionRepository.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/repository/SessionRepository.java @@ -1,11 +1,14 @@ package com.tave.tavewebsite.domain.session.repository; import com.tave.tavewebsite.domain.session.entity.Session; +import org.springframework.data.domain.Page; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.domain.Pageable; import java.util.List; public interface SessionRepository extends JpaRepository { - List findByGenerationAndIsPublic(String generation, boolean isPublic); + Page findByGenerationAndIsPublic(String generation, boolean isPublic, Pageable pageable); + } From e9c7fe6ed0abaa29a7899a8a3e9122828f6202ab Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:40:56 +0900 Subject: [PATCH 11/19] =?UTF-8?q?feat:=20SessionController=20-=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/session/controller/SessionController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java b/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java index 75a8d09..aaeaa51 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java @@ -36,4 +36,11 @@ public SuccessResponse> getSession(@PathVariable String List response = sessionService.findSessionByGeneration(generation, page, size); return new SuccessResponse<>(response, SESSION_SUCCESS_REGISTER.getMessage()); } + + @DeleteMapping("/{sessionId}") + public SuccessResponse deleteSession(@PathVariable Long sessionId){ + sessionService.deleteSession(sessionId); + return new SuccessResponse<>(null, SESSION_DELETE.getMessage()); + } + } From 3684d762208784620b734f3a8b42ddd7c309576b Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:41:41 +0900 Subject: [PATCH 12/19] =?UTF-8?q?feat:=20SessionService=20-=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/session/service/SessionService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java b/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java index 3c0d2e3..5ccad4a 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java @@ -38,5 +38,18 @@ public List findSessionByGeneration(String generation, int p .toList(); } + public void deleteSession(Long sessionId) { + Session findSession = findBySessionId(sessionId); + sessionRepository.delete(findSession); + } + + /* + * 리팩토링 + * */ + + private Session findBySessionId(Long sessionId) { + return sessionRepository.findById(sessionId) + .orElseThrow(SessionNotFoundException::new); + } } From 37ca162eef24e574ed1c175142876874a4211249 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:42:18 +0900 Subject: [PATCH 13/19] =?UTF-8?q?feat:=20SessionController=20-=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/session/controller/SessionController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java b/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java index aaeaa51..2910262 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/controller/SessionController.java @@ -43,4 +43,15 @@ public SuccessResponse deleteSession(@PathVariable Long sessionId){ return new SuccessResponse<>(null, SESSION_DELETE.getMessage()); } + @PatchMapping("/{sessionId}") + public SuccessResponse updateSession(@PathVariable Long sessionId, + @RequestPart(name = "request") SessionRequestDto sessionRequestDto, + @RequestPart(name = "file", required = false) MultipartFile file){ + sessionService.updateSession(sessionId, sessionRequestDto, file); + return new SuccessResponse<>(null, SESSION_UPDATE.getMessage()); + } + + + + } From 9799e96454be12dcaab79ea936f0e6a6e7dc2544 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:43:32 +0900 Subject: [PATCH 14/19] =?UTF-8?q?feat:=20SessionController=20-=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84=20=EB=B0=8F?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session/service/SessionService.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java b/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java index 5ccad4a..332cdc3 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/service/SessionService.java @@ -43,6 +43,13 @@ public void deleteSession(Long sessionId) { sessionRepository.delete(findSession); } + @Transactional + public void updateSession(Long sessionId, SessionRequestDto sessionRequestDto, MultipartFile file){ + Session findSession = findBySessionId(sessionId); + updateSessionField(findSession,sessionRequestDto); + updateSessionImgUrl(findSession, file); + } + /* * 리팩토링 * */ @@ -52,4 +59,17 @@ private Session findBySessionId(Long sessionId) { .orElseThrow(SessionNotFoundException::new); } + private void updateSessionField(Session findSession, SessionRequestDto sessionRequestDto) { + log.info(findSession.getTitle(), findSession.getDescription()); + findSession.updateField(sessionRequestDto); + log.info(findSession.getTitle(), findSession.getDescription()); + } + + private void updateSessionImgUrl( Session findSession, MultipartFile file) { + if(file != null){ + URL savedImageUrl = s3Service.uploadImages(file); + findSession.updateImgUrl(savedImageUrl); + } + } + } From 31d7fff54585a2e3038f6e16564501c0c5961f87 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:44:20 +0900 Subject: [PATCH 15/19] =?UTF-8?q?feat:=20=EC=84=B8=EC=85=98=20ErrorMessage?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/session/exception/ErrorMessage.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/com/tave/tavewebsite/domain/session/exception/ErrorMessage.java diff --git a/src/main/java/com/tave/tavewebsite/domain/session/exception/ErrorMessage.java b/src/main/java/com/tave/tavewebsite/domain/session/exception/ErrorMessage.java new file mode 100644 index 0000000..e8a0a54 --- /dev/null +++ b/src/main/java/com/tave/tavewebsite/domain/session/exception/ErrorMessage.java @@ -0,0 +1,15 @@ +package com.tave.tavewebsite.domain.session.exception; + +import jakarta.annotation.security.DenyAll; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ErrorMessage { + + SESSION_NOT_FOUND(400, "세션을 찾을 수 없습니다."); + + private final int code; + private final String message; +} From 29194ff5756e1b8abc0f9eaad21c3c949f5c15c1 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:44:31 +0900 Subject: [PATCH 16/19] =?UTF-8?q?feat:=20=EC=84=B8=EC=85=98=20SuccessMessa?= =?UTF-8?q?ge=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session/controller/SuccessMessage.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/tave/tavewebsite/domain/session/controller/SuccessMessage.java diff --git a/src/main/java/com/tave/tavewebsite/domain/session/controller/SuccessMessage.java b/src/main/java/com/tave/tavewebsite/domain/session/controller/SuccessMessage.java new file mode 100644 index 0000000..04760d6 --- /dev/null +++ b/src/main/java/com/tave/tavewebsite/domain/session/controller/SuccessMessage.java @@ -0,0 +1,16 @@ +package com.tave.tavewebsite.domain.session.controller; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum SuccessMessage { + + SESSION_SUCCESS_REGISTER("새로운 정규 세션 정보를 기입했습니다."), + SESSION_SUCCESS_GET("성공적으로 세션을 조회했습니다."), + SESSION_DELETE("성공적으로 세션을 삭제했습니다."), + SESSION_UPDATE("성공적으로 세션을 수정했습니다."); + + private final String message; +} From 6d94dbe54a9d7ba9e5002e12df0c4e8ea491c9b2 Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:44:43 +0900 Subject: [PATCH 17/19] =?UTF-8?q?feat:=20SessionNotFoundException=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session/exception/SessionNotFoundException.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/tave/tavewebsite/domain/session/exception/SessionNotFoundException.java diff --git a/src/main/java/com/tave/tavewebsite/domain/session/exception/SessionNotFoundException.java b/src/main/java/com/tave/tavewebsite/domain/session/exception/SessionNotFoundException.java new file mode 100644 index 0000000..7f75a73 --- /dev/null +++ b/src/main/java/com/tave/tavewebsite/domain/session/exception/SessionNotFoundException.java @@ -0,0 +1,11 @@ +package com.tave.tavewebsite.domain.session.exception; + +import com.tave.tavewebsite.global.exception.BaseErrorException; + +import static com.tave.tavewebsite.domain.session.exception.ErrorMessage.SESSION_NOT_FOUND; + +public class SessionNotFoundException extends BaseErrorException { + public SessionNotFoundException() { + super(SESSION_NOT_FOUND.getCode(), SESSION_NOT_FOUND.getMessage()); + } +} From 47fab62094bcd957719b33379fa6d648445c494f Mon Sep 17 00:00:00 2001 From: koreaioi Date: Wed, 13 Nov 2024 03:45:11 +0900 Subject: [PATCH 18/19] =?UTF-8?q?feat:=20Session=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tavewebsite/domain/session/entity/Session.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java b/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java index 59ee71d..b1a7d3e 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java @@ -63,4 +63,15 @@ public static Session of(SessionRequestDto sessionRequestDto, java.net.URL imgUr .imgUrl(imgUrl.toString()) .build(); } + + public void updateField(SessionRequestDto sessionRequestDto) { + this.title = sessionRequestDto.title(); + this.description = sessionRequestDto.description(); + this.generation = sessionRequestDto.generation(); + this.isPublic = sessionRequestDto.isPublic(); + } + + public void updateImgUrl( java.net.URL imgUrl) { + this.imgUrl = imgUrl.toString(); + } } From fa527d2e0c7ec612596edb08977848165ab4221f Mon Sep 17 00:00:00 2001 From: koreaioi Date: Fri, 15 Nov 2024 02:49:24 +0900 Subject: [PATCH 19/19] =?UTF-8?q?fix:=20Session=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tave/tavewebsite/domain/session/entity/Session.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java b/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java index b1a7d3e..8326171 100644 --- a/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java +++ b/src/main/java/com/tave/tavewebsite/domain/session/entity/Session.java @@ -32,6 +32,10 @@ public class Session extends BaseEntity { @Column(nullable = false) private String description; + /* + * 동아리 지원 관리자 페이지에서 사용 시 "세션 진행 날짜" 필드를 추가하는 게 좋다고 생각. + * */ + @Size(min = 1, max = 5) @Column(length = 5) private String generation;