Skip to content

Commit

Permalink
방해금지모드
Browse files Browse the repository at this point in the history
  • Loading branch information
zoangrak committed Jun 2, 2024
1 parent 2e6e261 commit e499bdc
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public class NotificationController {

@Operation(summary = "SSE 이벤트 구독")
@GetMapping(value="/subscribe/{teacherUserId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter subscribe(@PathVariable Long userId) {
Optional<Teacher> teacherOptional = teacherRepository.findByUserId(userId);
public SseEmitter subscribe(@PathVariable Long teacherUserId) {
Optional<Teacher> teacherOptional = teacherRepository.findByUserId(teacherUserId);
if (teacherOptional.isEmpty()) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Teacher의 userId {" + userId + "}의 SSE 페이지가 열리지 않았습니다.");
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Teacher의 userId {" + teacherUserId + "}의 SSE 페이지가 열리지 않았습니다.");
}
return notificationService.subscribe(userId);
return notificationService.subscribe(teacherUserId);
}

@Operation(summary = "데이터 변동 알림(부모의 친구추가 요청)")
@PostMapping("/send-data/{teacherUserId}")
public ResponseEntity<?> sendData(@PathVariable Long teacherId, @RequestBody Map<String, Long> requestBody) {
public ResponseEntity<?> sendData(@PathVariable Long teacherUserId, @RequestBody Map<String, Long> requestBody) {
Long parentUserId = requestBody.get("parentUserId");
Optional<Parent> parentOptional = parentRepository.findByUserId(parentUserId);
if (parentOptional.isPresent()) {
Expand All @@ -50,7 +50,7 @@ public ResponseEntity<?> sendData(@PathVariable Long teacherId, @RequestBody Map
eventData.put("parentName", parentName);
eventData.put("parentId", parent.getUser().getId());

notificationService.notify(teacherId, eventData);
notificationService.notify(teacherUserId, eventData);
return ResponseEntity.ok().build();
} else {
return ResponseEntity.notFound().build();
Expand All @@ -59,8 +59,8 @@ public ResponseEntity<?> sendData(@PathVariable Long teacherId, @RequestBody Map

@Operation(summary = "친구 요청 목록 반환")
@GetMapping("/friends-requests/{teacherUserId}")
public ResponseEntity<List<Map<String, Object>>> getFriendRequests(@PathVariable Long userId) {
List<Map<String, Object>> friendRequests = notificationService.getFriendRequests(userId);
public ResponseEntity<List<Map<String, Object>>> getFriendRequests(@PathVariable Long teacherUserId) {
List<Map<String, Object>> friendRequests = notificationService.getFriendRequests(teacherUserId);
return ResponseEntity.ok(friendRequests);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.capstone.backend.domain.chat.service.ChatRoomService;
import com.capstone.backend.domain.user.dto.*;
import com.capstone.backend.domain.user.entity.Role;
import com.capstone.backend.domain.user.entity.Teacher;
import com.capstone.backend.domain.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -78,18 +79,6 @@ public ResponseEntity<List<TeacherDto>> findTeachers(@RequestHeader("Authorizati
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
//
// /**
// * 특정 사용자의 주간별 로그인 횟수를 조회
// *
// * @param userId 로그인 횟수를 조회할 사용자의 ID
// * @return 특정 사용자의 주간별 로그인 횟수
// */
// @Operation(summary = "특정 사용자의 주간별 로그인 횟수 조회")
// @GetMapping("/auth/{userId}/weekly-logins")
// public ResponseEntity<Long> getUserWeeklyLoginCount(@PathVariable Long userId) {
// return ResponseEntity.ok(userService.getUserWeeklyLoginCount(userId));
// }

/**
* 전체 유저의 통합 주간 로그인 횟수 조회
Expand All @@ -111,23 +100,25 @@ public ResponseEntity<Long> getUserCount() {
return ResponseEntity.ok(userService.getUserCount());
}

// @Autowired
// private JwtService jwtService;
// @Operation(summary = "유저 정보 요청")
// @GetMapping("/entry")
// public ResponseEntity<?> getUserInfo(@RequestHeader(name="Authorization") String token) {
// Optional<String> extractedEmail = jwtService.extractEmail(token);
// Optional<String> extractedUsername = jwtService.extractUsername(token);
// Optional<String> extractedRole = jwtService.extractRole(token);
// if (extractedEmail.isPresent() && extractedUsername.isPresent()) {
// Map<String, String> userInfo = new HashMap<>();
// userInfo.put("email", extractedEmail.get());
// userInfo.put("username", extractedUsername.get());
// userInfo.put("role", extractedRole.get());
// return ResponseEntity.ok(userInfo);
// } else {
// // 이메일 또는 사용자 이름이 없거나 토큰이 유효하지 않은 경우에 대한 예외 처리
// return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("유효하지 않은 토큰, 이메일 또는 사용자 이름이 없습니다.");
// }
// }
@Operation(summary = "근무 상태 설정")
@PostMapping("/status/{teacherUserId}")
public ResponseEntity<String> setWorkStatus(@PathVariable Long teacherUserId, @RequestBody TeacherStatusDto teacherStatusDto) {
try {
userService.setWorkStatus(teacherUserId, teacherStatusDto);
return ResponseEntity.ok("상태가 설정되었습니다.");
} catch (Exception e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@Operation(summary = "근무 상태 조회")
@GetMapping("/status/{teacherUserId}")
public ResponseEntity<TeacherStatusDto> getWorkStatus(@PathVariable Long teacherUserId) {
try {
TeacherStatusDto teacherStatusDto = userService.getWorkStatus(teacherUserId);
return ResponseEntity.ok(teacherStatusDto);
} catch (Exception e) {
return ResponseEntity.badRequest().body(null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.capstone.backend.domain.user.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class TeacherStatusDto {
private boolean duty;
private String workStart;
private String workEnd;
private String disturbStart;
private String disturbEnd;
}
17 changes: 17 additions & 0 deletions src/main/java/com/capstone/backend/domain/user/entity/Teacher.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.capstone.backend.domain.user.entity;

import lombok.*;
import org.checkerframework.checker.units.qual.C;

import javax.persistence.*;

@Table(name = "TEACHERS")
Expand All @@ -23,6 +25,21 @@ public class Teacher {
@Column
private String teacherClass; // 학급

@Column
private boolean duty; // 0 - 근무아님 || 1 - 근무중

@Column
private String workStart;

@Column
private String workEnd;

@Column
private String disturbStart;

@Column
private String disturbEnd;

public Teacher(User user, String teacherSchool, String teacherClass) {
this.user = user;
if (user.getRole() != Role.TEACHER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,55 @@ public Long getUserId(String email) {
public Long getUserCount() {
return userRepository.count();
}

public void setWorkStatus(Long userId, TeacherStatusDto teacherStatusDto) {
Teacher teacher = findTeacherById(userId);
if (teacher == null) {
throw new NoSuchElementException("해당 선생님을 찾을 수 없습니다.");
}

teacher.setDuty(teacherStatusDto.isDuty());
if (teacherStatusDto.isDuty()) {
teacher.setWorkStart(teacherStatusDto.getWorkStart());
teacher.setWorkEnd(teacherStatusDto.getWorkEnd());
} else {
teacher.setDisturbStart(teacherStatusDto.getDisturbStart());
teacher.setDisturbEnd(teacherStatusDto.getDisturbEnd());
}

teacherRepository.save(teacher);
}

public TeacherStatusDto getWorkStatus(Long teacherUserId) {
// Teacher teacher = findTeacherById(userId);
// if (teacher == null) {
// throw new NoSuchElementException("해당 선생님을 찾을 수 없습니다.");
// }
//
// TeacherStatusDto teacherStatusDto = new TeacherStatusDto();
// teacherStatusDto.setDuty(teacher.isDuty());
//
// if (teacherStatusDto.isDuty()) {
// teacherStatusDto.setWorkStart(teacher.getWorkStart());
// teacherStatusDto.setWorkEnd(teacher.getWorkEnd());
// } else {
// teacherStatusDto.setDisturbStart(teacher.getDisturbStart());
// teacherStatusDto.setDisturbEnd(teacher.getDisturbEnd());
// }
//
// return teacherStatusDto;
Teacher teacher = findTeacherById(teacherUserId);
if (teacher == null) {
throw new NoSuchElementException("해당 선생님을 찾을 수 없습니다.");
}

TeacherStatusDto teacherStatusDto = new TeacherStatusDto();
teacherStatusDto.setDuty(teacher.isDuty());
teacherStatusDto.setWorkStart(teacher.getWorkStart());
teacherStatusDto.setWorkEnd(teacher.getWorkEnd());
teacherStatusDto.setDisturbStart(teacher.getDisturbStart());
teacherStatusDto.setDisturbEnd(teacher.getDisturbEnd());

return teacherStatusDto;
}
}

0 comments on commit e499bdc

Please sign in to comment.