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); + } +} diff --git a/src/main/java/dongguk/osori/domain/follow/FollowController.java b/src/main/java/dongguk/osori/domain/follow/FollowController.java index 5ef3f81..27bb471 100644 --- a/src/main/java/dongguk/osori/domain/follow/FollowController.java +++ b/src/main/java/dongguk/osori/domain/follow/FollowController.java @@ -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 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) {