Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcw1031 committed May 9, 2024
2 parents f596953 + fa69ce6 commit 69ca80b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
import ac.knu.likeknu.controller.dto.base.PageResponseDto;
import ac.knu.likeknu.domain.constants.Campus;
import ac.knu.likeknu.domain.constants.Category;
import ac.knu.likeknu.logging.domain.value.LogType;
import ac.knu.likeknu.logging.service.LoggingService;
import ac.knu.likeknu.service.AnnouncementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -25,29 +21,21 @@
public class AnnouncementController {

private final AnnouncementService announcementService;
private final LoggingService loggingService;

public AnnouncementController(AnnouncementService announcementService, LoggingService loggingService) {
public AnnouncementController(AnnouncementService announcementService) {
this.announcementService = announcementService;
this.loggingService = loggingService;
}

@GetMapping("/{category}")
public PageResponseDto<List<AnnouncementListResponse>> recentAnnouncementList(
@RequestParam("campus") Campus campus,
@RequestParam(name = "page", defaultValue = "1") int page,
@RequestParam(name = "keyword", required = false, defaultValue = "") String keyword,
@PathVariable("category") String category,
@RequestHeader(name = "Device-Id", required = false) String deviceId,
@RequestParam(name = "deviceId", required = false) String nativeDeviceId
@RequestParam(name = "deviceId", required = false) String deviceId
) {
if (StringUtils.hasText(keyword)) {
loggingService.addLog(LogType.SEARCH_ANNOUNCEMENT, deviceId, category, keyword);
}

PageDto pageDto = PageDto.of(page);
List<AnnouncementListResponse> studentNewsList =
announcementService.getAnnouncements(campus, Category.of(category), pageDto, keyword.trim(), nativeDeviceId);
announcementService.getAnnouncements(campus, Category.of(category), pageDto, deviceId);
return PageResponseDto.of(studentNewsList, pageDto);
}

Expand Down
17 changes: 3 additions & 14 deletions src/main/java/ac/knu/likeknu/controller/BusController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import ac.knu.likeknu.controller.dto.shuttlebus.ShuttleListResponse;
import ac.knu.likeknu.domain.constants.Campus;
import ac.knu.likeknu.domain.constants.RouteType;
import ac.knu.likeknu.logging.domain.value.LogType;
import ac.knu.likeknu.logging.service.LoggingService;
import ac.knu.likeknu.service.CityBusService;
import ac.knu.likeknu.service.ShuttleBusService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -25,24 +22,17 @@ public class BusController {

private final CityBusService cityBusService;
private final ShuttleBusService shuttleBusService;
private final LoggingService loggingService;

public BusController(CityBusService cityBusService, ShuttleBusService shuttleBusService, LoggingService loggingService) {
public BusController(CityBusService cityBusService, ShuttleBusService shuttleBusService) {
this.cityBusService = cityBusService;
this.shuttleBusService = shuttleBusService;
this.loggingService = loggingService;
}

@GetMapping("/city-bus/{type}")
private ResponseDto<List<CityBusesResponse>> cityBusesArrivalTime(
@RequestParam("campus") Campus campus, @PathVariable("type") String type,
@RequestParam(value = "isRefresh", required = false) boolean isRefresh,
@RequestHeader(name = "Device-Id", required = false) String deviceId
@RequestParam(value = "isRefresh", required = false) boolean isRefresh
) {
if (isRefresh) {
loggingService.addLog(LogType.REFRESH_CITY_BUS, deviceId);
}

RouteType routeType = RouteType.of(type);
List<CityBusesResponse> cityBusesArrivalTime = cityBusService.getCityBusesArrivalTime(campus, routeType);
return ResponseDto.of(cityBusesArrivalTime);
Expand All @@ -56,9 +46,8 @@ public ResponseDto<List<ShuttleListResponse>> eachRouteShuttleBuses(@RequestPara

@GetMapping("/shuttle-bus/{shuttleId}")
public ResponseDto<List<ShuttleBusesArrivalTimeResponse>> shuttleBusesArrivalTime(
@PathVariable("shuttleId") String shuttleId, @RequestHeader(name = "Device-Id", required = false) String deviceId
@PathVariable("shuttleId") String shuttleId
) {
loggingService.addLog(LogType.SELECT_SHUTTLE, deviceId, shuttleId);
List<ShuttleBusesArrivalTimeResponse> shuttleBusesArrivalTime = shuttleBusService.getShuttleBusesArrivalTime(shuttleId);
return ResponseDto.of(shuttleBusesArrivalTime);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package ac.knu.likeknu.controller.dto.device.request;

import ac.knu.likeknu.domain.constants.Campus;
import com.fasterxml.jackson.annotation.JsonAlias;

public record DeviceRegistrationRequest(
String deviceId,
@JsonAlias("platform")
String userAgent,
String platform,
String modelName,
String osVersion,
String appVersion,
Campus campus,
String themeColor,
String favoriteCafeteria
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/ac/knu/likeknu/domain/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class Device {

private String osVersion;

private String appVersion;

private String themeColor;

private String favoriteCafeteria;
Expand Down Expand Up @@ -82,22 +84,21 @@ protected Device() {
}

@Builder
public Device(String id, String fcmToken, Campus campus, LocalDateTime registeredAt, String themeColor, String favoriteCafeteria) {
public Device(String id, String fcmToken, Campus campus, LocalDateTime registeredAt, String appVersion, String themeColor, String favoriteCafeteria) {
this.id = id;
this.fcmToken = fcmToken;
this.campus = campus;
this.registeredAt = registeredAt;
this.appVersion = appVersion;
this.themeColor = themeColor;
this.favoriteCafeteria = favoriteCafeteria;
}

public static Device of(DeviceRegistrationRequest request) {
return Device.builder()
.id(request.deviceId())
.campus(Campus.CHEONAN)
.campus(Campus.SINGWAN)
.registeredAt(LocalDateTime.now())
.themeColor(request.themeColor())
.favoriteCafeteria(request.favoriteCafeteria())
.build();
}

Expand All @@ -111,7 +112,7 @@ public void updateNotification(boolean isTurnOnNotification) {
}

public void update(DeviceRegistrationRequest deviceRequest) {
this.platform = deviceRequest.userAgent();
this.platform = deviceRequest.platform();
this.campus = deviceRequest.campus();
this.themeColor = deviceRequest.themeColor();
this.favoriteCafeteria = deviceRequest.favoriteCafeteria();
Expand All @@ -123,5 +124,8 @@ public void update(DeviceRegistrationRequest deviceRequest) {
if (deviceRequest.osVersion() != null) {
this.osVersion = deviceRequest.osVersion();
}
if (deviceRequest.appVersion() != null) {
this.appVersion = deviceRequest.appVersion();
}
}
}
18 changes: 5 additions & 13 deletions src/main/java/ac/knu/likeknu/service/AnnouncementService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,19 @@ public AnnouncementService(AnnouncementRepository announcementRepository, Device
this.deviceRepository = deviceRepository;
}

public List<AnnouncementListResponse> getAnnouncements(Campus campus, Category category, PageDto pageDto, String keyword, String nativeDeviceId) {
public List<AnnouncementListResponse> getAnnouncements(Campus campus, Category category, PageDto pageDto, String deviceId) {
int requestPage = pageDto.getCurrentPage() - 1;
PageRequest pageRequest = PageRequest.of(requestPage, DEFAULT_ANNOUNCEMENT_PAGE_SIZE,
Sort.by(Order.desc("announcementDate"), Order.desc("collectedAt")));

Page<Announcement> announcementsPage;
if (keyword != null && !keyword.isEmpty()) {
announcementsPage = announcementRepository.findByCampusInAndCategoryAndAnnouncementTitleContains(
Set.of(campus, Campus.ALL), category, keyword, pageRequest
);
} else {
announcementsPage = announcementRepository.findByCampusInAndCategory(
Set.of(campus, Campus.ALL), category, pageRequest
);
}
Page<Announcement> announcementsPage =
announcementRepository.findByCampusInAndCategory(Set.of(campus, Campus.ALL), category, pageRequest);

pageDto.updateTotalPages(announcementsPage.getTotalPages());
pageDto.updateTotalElements(announcementsPage.getTotalElements());

if (nativeDeviceId != null) {
Optional<Device> findDevice = deviceRepository.findById(nativeDeviceId);
if (deviceId != null) {
Optional<Device> findDevice = deviceRepository.findById(deviceId);
if (findDevice.isEmpty()) {
return announcementsPage.stream()
.map(AnnouncementListResponse::of)
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/ac/knu/likeknu/service/DeviceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public DeviceService(DeviceRepository deviceRepository) {
}

public void registerDevice(DeviceRegistrationRequest deviceRequest) {
String userAgent = deviceRequest.userAgent();
if (userAgent.contains("Googlebot") || userAgent.contains("AdsBot") || userAgent.contains("vercel")) {
return;
}

String deviceId = deviceRequest.deviceId();
Device device = deviceRepository.findById(deviceId)
.orElseGet(() -> Device.of(deviceRequest));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE device
ADD COLUMN app_version VARCHAR(14) AFTER os_version;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ac.knu.likeknu.domain.constants.Campus;
import ac.knu.likeknu.domain.constants.Category;
import ac.knu.likeknu.domain.constants.Tag;
import ac.knu.likeknu.logging.service.LoggingService;
import ac.knu.likeknu.service.AnnouncementService;
import ac.knu.likeknu.service.SlackService;
import ac.knu.likeknu.utils.TestInstanceFactory;
Expand Down Expand Up @@ -44,8 +43,6 @@ class AnnouncementControllerTest {
private AnnouncementService announcementService;
@MockBean
private SlackService slackService;
@MockBean
private LoggingService loggingService;

@DisplayName("ํ•™์ƒ์†Œ์‹ ์กฐํšŒ API ์š”์ฒญ์— ์„ฑ๊ณตํ•œ๋‹ค.")
@Test
Expand All @@ -56,7 +53,7 @@ void fetchStudentNewsApiSuccess() throws Exception {
Announcement announcement3 = TestInstanceFactory.createAnnouncement("Test C", "https://testc.com", Tag.LIBRARY);

// when
when(announcementService.getAnnouncements(eq(Campus.CHEONAN), eq(Category.STUDENT_NEWS), any(PageDto.class), any(), any()))
when(announcementService.getAnnouncements(eq(Campus.CHEONAN), eq(Category.STUDENT_NEWS), any(PageDto.class), any()))
.thenReturn(List.of(
AnnouncementListResponse.of(announcement1),
AnnouncementListResponse.of(announcement2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ void getStudentNewsSuccess() throws Exception {
eq(Set.of(Campus.ALL, Campus.CHEONAN)), eq(Category.STUDENT_NEWS), any(Pageable.class)
)).thenReturn(new PageImpl<>(List.of(announcement1, announcement2, announcement3), PageRequest.of(0, 10), 1));
when(deviceRepository.findById(any(String.class)))
.thenReturn(Optional.of(new Device("deviceA", null, Campus.SINGWAN, LocalDateTime.now(), null, null)));
.thenReturn(Optional.of(new Device("deviceA", null, Campus.SINGWAN, LocalDateTime.now(), null, null, null)));

List<AnnouncementListResponse> announcementList =
announcementService.getAnnouncements(Campus.CHEONAN, Category.STUDENT_NEWS, pageDto, "", "");
announcementService.getAnnouncements(Campus.CHEONAN, Category.STUDENT_NEWS, pageDto, "");

// then
AnnouncementListResponse announcementResponse = announcementList.get(0);
Expand Down

0 comments on commit 69ca80b

Please sign in to comment.