From 1cd51dd7d0bb28bc91982e2071bd9d134cb19787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?toni=20=28=EC=9D=B4=EC=86=8C=EC=9D=80=29?= <144209738+saokiritoni@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:27:00 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Fix:=20=ED=8C=94=EB=A1=9C=EC=9A=B0=20?= =?UTF-8?q?=EC=9D=B4=EB=A9=94=EC=9D=BC=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../osori/domain/follow/FollowController.java | 14 +++++++------- .../domain/follow/service/FollowService.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/dongguk/osori/domain/follow/FollowController.java b/src/main/java/dongguk/osori/domain/follow/FollowController.java index 5ef3f81..3dadab4 100644 --- a/src/main/java/dongguk/osori/domain/follow/FollowController.java +++ b/src/main/java/dongguk/osori/domain/follow/FollowController.java @@ -65,18 +65,18 @@ public ResponseEntity getMyFollowerList(@SessionAttribute(name @ApiResponse(responseCode = "404", description = "해당 이메일의 사용자를 찾을 수 없음") }) @PostMapping() - public ResponseEntity followUserByEmail(@SessionAttribute(name = "userId", required = false) Long userId, @RequestBody FollowRequestDto followRequestDto) { + public ResponseEntity followUserByEmail(@SessionAttribute(name = "userId", required = false) Long userId, + @RequestBody FollowRequestDto followRequestDto) { if (userId == null) { return ResponseEntity.status(401).build(); } - User userToFollow = userService.findUserByEmail(followRequestDto.getEmail()); - if (userToFollow == null) { - return ResponseEntity.status(404).build(); + try { + followService.followUserByEmail(userId, followRequestDto.getEmail()); + return ResponseEntity.ok().build(); + } catch (IllegalArgumentException e) { + return ResponseEntity.status(404).body(null); } - - followService.followUser(userId, userToFollow.getUserId()); - return ResponseEntity.ok().build(); } @Operation(summary = "언팔로우", description = "사용자를 언팔로우합니다.") diff --git a/src/main/java/dongguk/osori/domain/follow/service/FollowService.java b/src/main/java/dongguk/osori/domain/follow/service/FollowService.java index b82049d..b3710d0 100644 --- a/src/main/java/dongguk/osori/domain/follow/service/FollowService.java +++ b/src/main/java/dongguk/osori/domain/follow/service/FollowService.java @@ -80,6 +80,23 @@ public void followUser(Long userId, Long followingUserId) { followRepository.save(follow); } + @Transactional + public void followUserByEmail(Long userId, String email) { + User follower = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("Logged-in user not found with id: " + userId)); + + User following = userRepository.findByEmail(email) + .orElseThrow(() -> new IllegalArgumentException("User not found with email: " + email)); + + boolean alreadyFollowing = followRepository.findByFollowerAndFollowing(follower, following).isPresent(); + if (alreadyFollowing) { + throw new IllegalArgumentException("You are already following this user."); + } + + followRepository.save(new Follow(follower, following)); + } + + // 언팔로우 @Transactional public void unfollowUser(Long userId, Long followingId) { From 29657fc5acf4465503db407ed8f18ad2c33dedbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?toni=20=28=EC=9D=B4=EC=86=8C=EC=9D=80=29?= <144209738+saokiritoni@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:19:21 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Feat:=20=ED=95=99=EC=82=AC=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AcademicEventController.java | 24 ++++++++++++++ .../academicEvent/entity/AcademicEvent.java | 31 +++++++++++++++++++ .../repository/AcademicEventRepository.java | 13 ++++++++ .../service/AcademicEventService.java | 25 +++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 src/main/java/dongguk/osori/domain/academicEvent/controller/AcademicEventController.java create mode 100644 src/main/java/dongguk/osori/domain/academicEvent/entity/AcademicEvent.java create mode 100644 src/main/java/dongguk/osori/domain/academicEvent/repository/AcademicEventRepository.java create mode 100644 src/main/java/dongguk/osori/domain/academicEvent/service/AcademicEventService.java diff --git a/src/main/java/dongguk/osori/domain/academicEvent/controller/AcademicEventController.java b/src/main/java/dongguk/osori/domain/academicEvent/controller/AcademicEventController.java new file mode 100644 index 0000000..61a5f61 --- /dev/null +++ b/src/main/java/dongguk/osori/domain/academicEvent/controller/AcademicEventController.java @@ -0,0 +1,24 @@ +package dongguk.osori.domain.academicEvent.controller; + +import dongguk.osori.domain.academicEvent.entity.AcademicEvent; +import dongguk.osori.domain.academicEvent.service.AcademicEventService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/academic-events") +@RequiredArgsConstructor +public class AcademicEventController { + + private final AcademicEventService service; + + @GetMapping("/{year}/{month}") + public ResponseEntity> getEventsByMonth( + @PathVariable int year, + @PathVariable int month) { + return ResponseEntity.ok(service.getEventsByMonth(year, month)); + } +} diff --git a/src/main/java/dongguk/osori/domain/academicEvent/entity/AcademicEvent.java b/src/main/java/dongguk/osori/domain/academicEvent/entity/AcademicEvent.java new file mode 100644 index 0000000..95fe197 --- /dev/null +++ b/src/main/java/dongguk/osori/domain/academicEvent/entity/AcademicEvent.java @@ -0,0 +1,31 @@ +package dongguk.osori.domain.academicEvent.entity; + +import jakarta.persistence.*; +import lombok.*; + +import java.time.LocalDate; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class AcademicEvent { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String eventTitle; + + @Column(nullable = false) + private String department; + + @Column(nullable = false) + private LocalDate startDate; + + @Column(nullable = false) + private LocalDate endDate; +} diff --git a/src/main/java/dongguk/osori/domain/academicEvent/repository/AcademicEventRepository.java b/src/main/java/dongguk/osori/domain/academicEvent/repository/AcademicEventRepository.java new file mode 100644 index 0000000..6710dbc --- /dev/null +++ b/src/main/java/dongguk/osori/domain/academicEvent/repository/AcademicEventRepository.java @@ -0,0 +1,13 @@ +package dongguk.osori.domain.academicEvent.repository; + +import dongguk.osori.domain.academicEvent.entity.AcademicEvent; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.time.LocalDate; +import java.util.List; + +@Repository +public interface AcademicEventRepository extends JpaRepository { + List findByStartDateBetween(LocalDate start, LocalDate end); +} diff --git a/src/main/java/dongguk/osori/domain/academicEvent/service/AcademicEventService.java b/src/main/java/dongguk/osori/domain/academicEvent/service/AcademicEventService.java new file mode 100644 index 0000000..7acdc7f --- /dev/null +++ b/src/main/java/dongguk/osori/domain/academicEvent/service/AcademicEventService.java @@ -0,0 +1,25 @@ +package dongguk.osori.domain.academicEvent.service; + +import dongguk.osori.domain.academicEvent.entity.AcademicEvent; +import dongguk.osori.domain.academicEvent.repository.AcademicEventRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.time.YearMonth; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class AcademicEventService { + + private final AcademicEventRepository repository; + + public List getEventsByMonth(int year, int month) { + YearMonth yearMonth = YearMonth.of(year, month); + LocalDate startOfMonth = yearMonth.atDay(1); + LocalDate endOfMonth = yearMonth.atEndOfMonth(); + + return repository.findByStartDateBetween(startOfMonth, endOfMonth); + } +} From 80ac15a59f3b8e388cf00c1c1423ba15a4cb3504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?toni=20=28=EC=9D=B4=EC=86=8C=EC=9D=80=29?= <144209738+saokiritoni@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:22:50 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Fix:=20=ED=8C=94=EB=A1=9C=EC=9A=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../osori/domain/follow/FollowController.java | 16 ++++++++-------- .../osori/domain/follow/FollowRepository.java | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/dongguk/osori/domain/follow/FollowController.java b/src/main/java/dongguk/osori/domain/follow/FollowController.java index 3dadab4..27bb471 100644 --- a/src/main/java/dongguk/osori/domain/follow/FollowController.java +++ b/src/main/java/dongguk/osori/domain/follow/FollowController.java @@ -65,18 +65,18 @@ public ResponseEntity getMyFollowerList(@SessionAttribute(name @ApiResponse(responseCode = "404", description = "해당 이메일의 사용자를 찾을 수 없음") }) @PostMapping() - public ResponseEntity followUserByEmail(@SessionAttribute(name = "userId", required = false) Long userId, - @RequestBody FollowRequestDto followRequestDto) { + public ResponseEntity followUserByEmail(@SessionAttribute(name = "userId", required = false) Long userId, @RequestBody FollowRequestDto followRequestDto) { if (userId == null) { return ResponseEntity.status(401).build(); } - try { - followService.followUserByEmail(userId, followRequestDto.getEmail()); - return ResponseEntity.ok().build(); - } catch (IllegalArgumentException e) { - return ResponseEntity.status(404).body(null); + User userToFollow = userService.findUserByEmail(followRequestDto.getEmail()); + if (userToFollow == null) { + return ResponseEntity.status(404).build(); } + + followService.followUser(userId, userToFollow.getUserId()); + return ResponseEntity.ok().build(); } @Operation(summary = "언팔로우", description = "사용자를 언팔로우합니다.") @@ -108,4 +108,4 @@ public ResponseEntity blockFollower(@SessionAttribute(name = "userId", req followService.blockFollower(userId, blockFollowerRequestDto.getFollowerId()); return ResponseEntity.ok().build(); } -} +} \ No newline at end of file diff --git a/src/main/java/dongguk/osori/domain/follow/FollowRepository.java b/src/main/java/dongguk/osori/domain/follow/FollowRepository.java index cbe549e..b64a713 100644 --- a/src/main/java/dongguk/osori/domain/follow/FollowRepository.java +++ b/src/main/java/dongguk/osori/domain/follow/FollowRepository.java @@ -22,4 +22,4 @@ public interface FollowRepository extends JpaRepository { // 팔로우 관계 삭제 void deleteByFollowerAndFollowing(User follower, User following); -} +} \ No newline at end of file