Skip to content
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
@@ -1,6 +1,7 @@
package devkor.com.teamcback.domain.ble.controller;

import devkor.com.teamcback.domain.ble.dto.request.UpdateBLEReq;
import devkor.com.teamcback.domain.ble.dto.response.BLEDeviceListRes;
import devkor.com.teamcback.domain.ble.dto.response.BLETimePatternRes;
import devkor.com.teamcback.domain.ble.dto.response.GetBLERes;
import devkor.com.teamcback.domain.ble.dto.response.UpdateBLERes;
Expand All @@ -16,6 +17,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/ble")
Expand Down Expand Up @@ -63,4 +66,14 @@ public CommonResponse<BLETimePatternRes> getBLETimePattern(
return CommonResponse.success(bleService.getBLETimePattern(placeId));
}

@GetMapping("/list")
@Operation(summary = "BLE 가능 place 목록 조회",
description = "ble_device 테이블에 등록된 BLE 장비 목록(id, deviceName, placeId, capacity)을 반환")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정상 처리 되었습니다.")
})
public CommonResponse<List<BLEDeviceListRes>> getBLEDeviceList() {
return CommonResponse.success(bleService.getBLEDeviceList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package devkor.com.teamcback.domain.ble.dto.response;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class BLEDeviceListRes {

private Long id;
private String deviceName;
private Long placeId;
private Integer capacity;

public BLEDeviceListRes(Long id, String deviceName, Long placeId, int capacity) {
this.id = id;
this.deviceName = deviceName;
this.placeId = placeId;
this.capacity = capacity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
public class BLETimePatternRes {
private Long placeId; // 요청 placeId
private int[] hours; // {7,10,13,16,19,21,24}
private int[] dayOfWeeks; // {1,2,3,4,5,6,7} (java.time.DayOfWeek 값)
private String[] dayOfWeeks; // {1,2,3,4,5,6,7} (java.time.DayOfWeek 값)
private int[][] averages; // [dayIndex][timeIndex] 형태, 각 원소는 반올림된 int

public BLETimePatternRes(Long placeId, int[] timeSlots, int[] dayOfWeeks, int[][] averages) {
public BLETimePatternRes(Long placeId, int[] timeSlots, String[] dayOfWeeks, int[][] averages) {
this.placeId = placeId;
this.hours = timeSlots;
this.dayOfWeeks = dayOfWeeks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import devkor.com.teamcback.domain.ble.dto.request.UpdateBLEReq;
import devkor.com.teamcback.domain.ble.dto.response.BLEDeviceListRes;
import devkor.com.teamcback.domain.ble.dto.response.BLETimePatternRes;
import devkor.com.teamcback.domain.ble.dto.response.GetBLERes;
import devkor.com.teamcback.domain.ble.dto.response.UpdateBLERes;
Expand All @@ -21,6 +22,7 @@

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import static devkor.com.teamcback.global.response.ResultCode.NOT_FOUND_PLACE;
Expand All @@ -37,6 +39,9 @@ public class BLEService {
private static final int[] TIME_SLOTS = {7, 10, 13, 16, 19, 22};
//요일 라벨 (1=월요일, 7=일요일)
private static final int[] DAY_OF_WEEKS = {1, 2, 3, 4, 5, 6, 7};
private static final String[] DAY_OF_WEEK_LABELS = {
"mon", "tue", "wed", "thu", "fri", "sat", "sun"
};

@Transactional
public UpdateBLERes updateBLE(UpdateBLEReq updateBLEReq) {
Expand Down Expand Up @@ -83,9 +88,10 @@ public GetBLERes getBLE(Long placeId) {
status = BLEstatus.FAILURE;
}
else status = latest.getLastStatus();
// 사람 수를 예측 후 10의 배수로 리턴

int people = getBlEPeople(latest.getLastCount(), device);
people = (int) Math.round(people / 10.0) * 10;
// 사람 수를 예측 후 10의 배수로 리턴: 이젠 필요 없음
//people = (int) Math.round(people / 10.0) * 10;
return new GetBLERes(device, latest, status, people);
}

Expand Down Expand Up @@ -157,9 +163,27 @@ public BLETimePatternRes getBLETimePattern(Long placeId) {
return new BLETimePatternRes(
placeId,
TIME_SLOTS,
DAY_OF_WEEKS,
DAY_OF_WEEK_LABELS,
averages
);
}

@Transactional(readOnly = true)
public List<BLEDeviceListRes> getBLEDeviceList() {
List<BLEDevice> devices = bledeviceRepository.findAll();
List<BLEDeviceListRes> result = new ArrayList<>();

for (BLEDevice device : devices) {
Long placeId = null;
if (device.getPlace() != null) {
placeId = device.getPlace().getId();
}

BLEDeviceListRes dto = new BLEDeviceListRes(device.getId(), device.getDeviceName(), placeId, device.getCapacity());

result.add(dto);
}
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package devkor.com.teamcback.domain.common.entity;

public enum Weekday {
MON, TUE, WED, THU, FRI, SAT, SUN
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package devkor.com.teamcback.domain.course.controller;

import devkor.com.teamcback.domain.course.dto.response.GetCourseListRes;
import devkor.com.teamcback.domain.course.service.CourseService;
import devkor.com.teamcback.domain.place.dto.response.GetPlaceListRes;
import devkor.com.teamcback.global.response.CommonResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/places")
public class CourseController {
private final CourseService courseService;

@GetMapping("/{placeId}/courses")
@Operation(summary = "장소 id로 강의 리스트 검색",
description = "강의 list 반환")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."),
@ApiResponse(responseCode = "404", description = "장소를 찾을 수 없습니다.",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
@ApiResponse(responseCode = "401", description = "권한이 없습니다.",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
})
public CommonResponse<GetCourseListRes> getCourseList(@Parameter(name = "placeId", description = "장소 ID", example = "4424", required = true) @PathVariable Long placeId) {
return CommonResponse.success(courseService.getCourseList(placeId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package devkor.com.teamcback.domain.course.dto.response;

import devkor.com.teamcback.domain.common.entity.Weekday;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.util.List;
import java.util.Map;

@Schema(description = "강의 List 조회 응답 dto")
@Getter
public class GetCourseListRes {
private Long placeId;
private String placeName;
private Map<Weekday, List<GetCourseRes>> courses;

public GetCourseListRes(Long placeId, String placeName, Map<Weekday, List<GetCourseRes>> courses) {
this.placeId = placeId;
this.placeName = placeName;
this.courses = courses;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package devkor.com.teamcback.domain.course.dto.response;

import devkor.com.teamcback.domain.course.entity.Course;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

@Schema(description = "강의 응답 dto")
@Getter
public class GetCourseRes {
private Long courseId;
private int year;
private String term;
private String subject;
private int unit;
private String code;
private String section;
private String type;
private String department;
private String professor;
private String weekday;
private int classTime;

public GetCourseRes(Course course, String weekday, int classTime) {
this.courseId = course.getId();
this.year = course.getYear();
this.term = course.getTerm().toString();
this.subject = course.getSubject();
this.unit = course.getUnit();
this.code = course.getCode();
this.section = course.getSection();
this.type = course.getType();
this.department = course.getDepartment();
this.professor = course.getProfessor();
this.weekday = weekday;
this.classTime = classTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package devkor.com.teamcback.domain.course.entity;

import devkor.com.teamcback.domain.common.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Table(name = "tb_course")
@NoArgsConstructor
public class Course extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private int year;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private Term term;

@Column(nullable = false)
private String subject;

@Column(nullable = false)
private int unit;

@Column(nullable = false)
private String code;

@Column(nullable = false)
private String section;

@Column(nullable = false)
private String type;

@Column(nullable = false)
private String department;

@Column(nullable = false)
private String professor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package devkor.com.teamcback.domain.course.entity;

import devkor.com.teamcback.domain.common.entity.BaseEntity;
import devkor.com.teamcback.domain.common.entity.Weekday;
import devkor.com.teamcback.domain.place.entity.Place;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Table(name = "tb_course_detail")
@NoArgsConstructor
public class CourseDetail extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column
@Enumerated(EnumType.STRING)
private Weekday weekday;

@Column(nullable = false)
private int start;

@Column(nullable = false)
private int end;

@Column
private String placeName;

@ManyToOne
@JoinColumn(name = "course_id")
private Course course;

@Setter
@OneToOne
@JoinColumn(name = "place_id")
private Place place;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package devkor.com.teamcback.domain.course.entity;

public enum Term {
SPRING, SUMMER, FALL, WINTER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package devkor.com.teamcback.domain.course.repository;

import devkor.com.teamcback.domain.course.entity.CourseDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CourseDetailRepository extends JpaRepository<CourseDetail, Long> {
@Query(value = "SELECT c FROM CourseDetail c WHERE c.place IS NULL ORDER BY c.id asc LIMIT :count")
List<CourseDetail> findLimitByPlaceIdIsNull(int count);

List<CourseDetail> findByPlaceId(Long placeId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package devkor.com.teamcback.domain.course.repository;

import devkor.com.teamcback.domain.course.entity.Course;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CourseRepository extends JpaRepository<Course, Long> {
}
Loading
Loading