Skip to content

Commit

Permalink
Merge pull request #42 from CSID-DGU/develop
Browse files Browse the repository at this point in the history
โœจ [Feat] ํ•™์‚ฌ์ผ์ •
  • Loading branch information
saokiritoni authored Dec 2, 2024
2 parents c1e4094 + 80ac15a commit 1bd9fc2
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 2 deletions.
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

0 comments on commit 1bd9fc2

Please sign in to comment.