Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [Feat] 학사일정 #42

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<List<AcademicEvent>> getEventsByMonth(
@PathVariable int year,
@PathVariable int month) {
return ResponseEntity.ok(service.getEventsByMonth(year, month));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<AcademicEvent, Long> {
List<AcademicEvent> findByStartDateBetween(LocalDate start, LocalDate end);
}
Original file line number Diff line number Diff line change
@@ -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<AcademicEvent> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ public ResponseEntity<Void> blockFollower(@SessionAttribute(name = "userId", req
followService.blockFollower(userId, blockFollowerRequestDto.getFollowerId());
return ResponseEntity.ok().build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public interface FollowRepository extends JpaRepository<Follow, Long> {

// 팔로우 관계 삭제
void deleteByFollowerAndFollowing(User follower, User following);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down