Skip to content

Commit

Permalink
#46 [FIX] alarm API 수정 (#47)
Browse files Browse the repository at this point in the history
### ☀️구현 내용
- 스웨거 요청 url 순서 변경
- 알람 관련 api 반환순서 수정
- 알람 관련 api 리턴 타입 변경
  • Loading branch information
hye-on authored Sep 18, 2023
2 parents 75f7754 + 955ba8d commit 5d99bdc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ public class AlarmController {
private final AlarmService alarmService;
private final AlarmProvider alarmProvider;

@Operation(summary = "알람 생성")
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public BaseResponse createAlarm(
@Parameter(hidden = true) @AuthUser Integer userId,
@RequestBody @Valid PostAlarmReq postAlarmReq
){
alarmService.createAlarm(userId, postAlarmReq);
return new BaseResponse(Status.SUCCESS_CREATED);
}

@Operation(summary = "알람 1개 불러오기")
@ApiResponse(
responseCode = "200",
Expand All @@ -58,28 +47,36 @@ public BaseResponse<List<GetAlarmRes>> GetAlarmsByUserId(
@Parameter(description = "- 개인 : personal\n- 그룹 : group", example = "personal") String type,
@Parameter(hidden = true) @AuthUser Integer userId
){
return new BaseResponse<>(Status.SUCCESS, alarmProvider.getAlarmsByUserId(userId, type));
return new BaseResponse<>(Status.SUCCESS, alarmProvider.getAlarmsByUserIdOrderByDate(userId, type));
}

@Operation(summary = "알람 생성")
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public BaseResponse<Integer> createAlarm(
@Parameter(hidden = true) @AuthUser Integer userId,
@RequestBody @Valid PostAlarmReq postAlarmReq
){
return new BaseResponse<>(Status.SUCCESS_CREATED, alarmService.createAlarm(userId, postAlarmReq).getId());
}

@Operation(summary = "알람 수정")
@PatchMapping("/{alarmId}")
public BaseResponse updateAlarm(
public BaseResponse<Integer> updateAlarm(
@Parameter(hidden = true) @AuthUser Integer userId,
@PathVariable Integer alarmId,
@RequestBody @Valid PatchAlarmReq patchAlarmReq
) {
alarmService.updateAlarm(userId, alarmId, patchAlarmReq);
return new BaseResponse<>(Status.SUCCESS);
return new BaseResponse<>(Status.SUCCESS, alarmService.updateAlarm(userId, alarmId, patchAlarmReq).getId());
}

@Operation(summary = "알람 삭제")
@DeleteMapping("/{alarmId}")
public BaseResponse deleteAlarm(
public BaseResponse<Integer> deleteAlarm(
@Parameter(hidden = true) @AuthUser Integer userId,
@PathVariable Integer alarmId
) {
alarmService.deleteAlarm(alarmId);
return new BaseResponse<>(Status.SUCCESS);
return new BaseResponse<>(Status.SUCCESS, alarmService.deleteAlarm(alarmId));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public class AlarmProvider {
* @param userId
* @return
*/
public List<GetAlarmRes> getAlarmsByUserId(Integer userId, String type) {
public List<GetAlarmRes> getAlarmsByUserIdOrderByDate(Integer userId, String type) {
// 유저 id 유무 확인
userRepository.findById(userId).orElseThrow(
() -> new BaseException(Status.USER_NOT_FOUND));

if (type.equals(GET_ALARM_MODE_PERSONAL)) {
List<Alarm> alarmList = alarmRepository.findAllByUser_IdAndRoom_IdIsNull(userId);
List<Alarm> alarmList = alarmRepository.findAllByUser_IdAndRoom_IdIsNullOrderByAlarmTime(userId);
return EntityDtoMapper.INSTANCE.toAlarmResList(alarmList);
} else if (type.equals(GET_ALARM_MODE_GROUP)) {
List<Alarm> alarmList = alarmRepository.findAllByUser_IdAndRoom_IdIsNotNull(userId);
List<Alarm> alarmList = alarmRepository.findAllByUser_IdAndRoom_IdIsNotNullOrderByAlarmTime(userId);
return EntityDtoMapper.INSTANCE.toAlarmResList(alarmList);
} else
throw new BaseException(Status.BAD_REQUEST_PARAM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public interface AlarmRepository extends JpaRepository<Alarm, Integer> {
@Query("select a from Alarm a where a.id = :id and a.user.id = :userId")
Optional<Alarm> findById(Integer id, Integer userId);

List<Alarm> findAllByUser_IdAndRoom_IdIsNull(Integer userId);
List<Alarm> findAllByUser_IdAndRoom_IdIsNullOrderByAlarmTime(Integer userId);

List<Alarm> findAllByUser_IdAndRoom_IdIsNotNull(Integer userId);
List<Alarm> findAllByUser_IdAndRoom_IdIsNotNullOrderByAlarmTime(Integer userId);

@Modifying
@Query("update Alarm a set a.room.id = :roomId where a.id = :alarmId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ public Alarm updateAlarm(Integer userId, Integer alarmId, PatchAlarmReq patchAla

// 알람 삭제
@Transactional
public void deleteAlarm(Integer alarmId) {
public int deleteAlarm(Integer alarmId) {
Alarm alarm = alarmRepository.findById(alarmId)
.orElseThrow(() -> new BaseException(Status.ALARM_NOT_FOUND));

alarmRepository.delete(alarm);

return alarm.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class PatchAlarmReq {
@NotNull(message = "null 값일 수 없습니다.")
private Boolean isActivated;

@Schema(description = "미션 id", example = "1")
@Schema(description = "미션 id", example = "2")
@NotNull(message = "미션 아이디를 넣어주세요.")
private Integer missionId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public OpenAPI openApi() {
.description(Constant.API_DESCRIPTION);

return new OpenAPI()
.addServersItem(new Server().url("http://localhost:9010"))
.addServersItem(new Server().url("https://togetup.shop"))
.addServersItem(new Server().url("http://localhost:9010"))
.info(info)
.addSecurityItem(new SecurityRequirement().addList(Constant.BEARER))
.components(
Expand Down

0 comments on commit 5d99bdc

Please sign in to comment.