Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#23 [REFACTOR] 알람, 미션 API 수정 및 Swagger 어노테이션 추가 #29

Merged
merged 10 commits into from
Aug 23, 2023
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ out/
.vscode/

### application.yml ###
application.yml
application-local.yml
application-dev.yml
application-prod.yml
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ dependencies {
implementation 'org.apache.httpcomponents:httpcore:4.4.15'
implementation 'org.apache.httpcomponents:httpclient:4.5.13'

// health check
implementation 'org.springframework.boot:spring-boot-starter-actuator'

//implementation 'org.springframework.boot:spring-boot-starter-log4j2'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.2'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
Expand Down Expand Up @@ -78,7 +81,6 @@ dependencies {
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'

//chat

implementation 'org.webjars:sockjs-client:1.1.2'
implementation 'org.webjars:stomp-websocket:2.3.3-1'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
Expand Down
104 changes: 34 additions & 70 deletions src/main/java/com/wakeUpTogetUp/togetUp/api/alarm/AlarmController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.wakeUpTogetUp.togetUp.api.alarm;

import com.wakeUpTogetUp.togetUp.api.alarm.dto.request.DeleteAlarmReq;
import com.wakeUpTogetUp.togetUp.api.alarm.dto.request.PatchAlarmReq;
import com.wakeUpTogetUp.togetUp.api.alarm.dto.response.GetAlarmRes;
import com.wakeUpTogetUp.togetUp.api.alarm.dto.request.PostAlarmReq;
import com.wakeUpTogetUp.togetUp.api.auth.AuthUser;
import com.wakeUpTogetUp.togetUp.common.dto.BaseResponse;
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.utils.JwtService;
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.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -16,102 +19,63 @@
import javax.validation.Valid;
import java.util.List;

@Tag(name = "알람")
@Tag(name = "알람(Alarm)")
@RestController
@RequestMapping("/app/alarm")
@RequiredArgsConstructor
public class AlarmController {
private final AlarmService alarmService;
private final AlarmProvider alarmProvider;
private final JwtService jwtService;

/**
* 알람 1개 불러오기
* @param alarmId
* @return
*/
@Operation(summary = "알람 1개 불러오기")
@ApiResponse(
responseCode = "200",
description = "요청에 성공하였습니다.",
content = @Content(schema = @Schema(implementation = GetAlarmRes.class)))
@GetMapping("/{alarmId}")
public BaseResponse<GetAlarmRes> GetAlarm(@PathVariable Integer alarmId){
GetAlarmRes getAlarmRes = alarmProvider.getAlarm(alarmId);

return new BaseResponse<>(Status.SUCCESS, getAlarmRes);
return new BaseResponse<>(Status.SUCCESS, alarmProvider.getAlarm(alarmId));
}

/**
* 사용자 알람 불러오기
* @param userId
* @return
*/
@Operation(summary = "유저 알람 목록 불러오기")
@ApiResponse(
responseCode = "200",
description = "요청에 성공하였습니다.",
content = @Content(schema = @Schema(implementation = GetAlarmRes.class)))
@GetMapping("")
public BaseResponse<List<GetAlarmRes>> GetAlarmsByUserId(@RequestParam Integer userId){
List<GetAlarmRes> alarmsResList = alarmProvider.getAlarmsByUserId(userId);

return new BaseResponse<>(Status.SUCCESS, alarmsResList);
public BaseResponse<List<GetAlarmRes>> GetAlarmsByUserId(@AuthUser Integer userId){
return new BaseResponse<>(Status.SUCCESS, alarmProvider.getAlarmsByUserId(userId));
}

/**
* 알람 생성
* @param postAlarmReq
* @return
*/
@Operation(summary = "알람 생성")
@PostMapping("")
@ResponseStatus(HttpStatus.CREATED)
public BaseResponse<GetAlarmRes> createAlarm(
@Parameter(hidden = true) @AuthUser Integer userId,
@RequestBody @Valid PostAlarmReq postAlarmReq
){
Integer userId = postAlarmReq.getUserId();

if(jwtService.validateByUserId(userId))
return new BaseResponse(Status.SUCCESS_CREATED, alarmService.createAlarm(userId, postAlarmReq));
else
throw new BaseException(Status.JWT_MISMATCH);
alarmService.createAlarm(userId, postAlarmReq);
return new BaseResponse(Status.SUCCESS_CREATED);
}

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

if(jwtService.validateByUserId(userId))
return new BaseResponse<>(Status.SUCCESS, alarmService.updateAlarm(userId, alarmId, patchAlarmReq));
else
throw new BaseException(Status.JWT_MISMATCH);
alarmService.updateAlarm(userId, alarmId, patchAlarmReq);
return new BaseResponse<>(Status.SUCCESS);
}

/**
* 알람 삭제
* @param alarmId
* @return
*/
@Operation(summary = "알람 삭제")
@DeleteMapping("/{alarmId}")
public BaseResponse<Integer> deleteAlarm(
@PathVariable Integer alarmId,
@RequestBody @Valid DeleteAlarmReq deleteAlarmReq
) {
Integer userId = deleteAlarmReq.getUserId();

if(jwtService.validateByUserId(userId)) {
alarmService.deleteAlarm(alarmId);

return new BaseResponse<>(Status.SUCCESS);
} else
throw new BaseException(Status.JWT_MISMATCH);
}

/**
* test
* @return
*/
@GetMapping("/test")
public String test(){
return "success";
@Parameter(hidden = true) @AuthUser Integer userId,
@PathVariable Integer alarmId
) {
alarmService.deleteAlarm(alarmId);
return new BaseResponse<>(Status.SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public GetAlarmRes updateAlarm(Integer userId, Integer alarmId, PatchAlarmReq pa
patchAlarmReq.getThursday(),
patchAlarmReq.getFriday(),
patchAlarmReq.getSaturday(),
patchAlarmReq.getSunday());
patchAlarmReq.getSunday(),
patchAlarmReq.getIsActivated());
Alarm alarmModified = alarmRepository.save(alarm);

return EntityDtoMapper.INSTANCE.toAlarmRes(alarmModified);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,30 +1,73 @@
package com.wakeUpTogetUp.togetUp.api.alarm.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import lombok.*;

import java.sql.Time;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class PatchAlarmReq {
private Integer userId;
@Schema(description = "미션 id", example = "1")
@NotNull(message = "null 값일 수 없습니다.")
private Integer missionId;

@Schema(description = "알람 이름", example = "기상 알람")
@NotNull(message = "null 값일 수 없습니다.")
private String name;

@Schema(description = "아이콘", example = "⏰")
@NotNull(message = "null 값일 수 없습니다.")
private String icon;
private String sound;

@Schema(description = "진동 여부", example = "true")
@NotNull(message = "null 값일 수 없습니다.")
private Boolean isVibrate;
private Boolean isRoutineOn;

@Schema(description = "다시울림 간격", example = "5")
@NotNull(message = "null 값일 수 없습니다.")
private Integer snoozeInterval;

@Schema(description = "다시울림 횟수", example = "3")
@NotNull(message = "null 값일 수 없습니다.")
private Integer snoozeCnt;
private Time alarmTime;

@Schema(description = "알람 시간", example = "06:00")
@NotNull(message = "null 값일 수 없습니다.")
@Pattern(regexp = "^([01]?[0-9]|2[0-3]):[0-5][0-9]$", message = "HH:mm 형식이 아닙니다.")
private String alarmTime;

@Schema(description = "월요일 울림 여부", example = "false")
@NotNull(message = "null 값일 수 없습니다.")
private Boolean monday;

@Schema(description = "화요일 울림 여부", example = "false")
@NotNull(message = "null 값일 수 없습니다.")
private Boolean tuesday;

@Schema(description = "수요일 울림 여부", example = "false")
@NotNull(message = "null 값일 수 없습니다.")
private Boolean wednesday;

@Schema(description = "목요일 울림 여부", example = "false")
@NotNull(message = "null 값일 수 없습니다.")
private Boolean thursday;

@Schema(description = "금요일 울림 여부", example = "false")
@NotNull(message = "null 값일 수 없습니다.")
private Boolean friday;

@Schema(description = "토요일 울림 여부", example = "false")
@NotNull(message = "null 값일 수 없습니다.")
private Boolean saturday;

@Schema(description = "일요일 울림 여부", example = "false")
@NotNull(message = "null 값일 수 없습니다.")
private Boolean sunday;

@Schema(description = "알람 활성화 여부", example = "true")
@NotNull(message = "null 값일 수 없습니다.")
private Boolean isActivated;
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,65 @@
package com.wakeUpTogetUp.togetUp.api.alarm.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.Pattern;
import lombok.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.sql.Time;
import java.util.List;

@Schema(description = "알람 생성 request")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class PostAlarmReq {
@NotNull(message = "사용자 아이디를 넣어주세요.")
private Integer userId;
@Schema(description = "미션 id", example = "1")
@NotNull(message = "미션 아이디를 넣어주세요.")
private Integer missionId;

private Integer roomId;

@NotBlank(message = "알람 이름은 공백일 수 없습니다.")
private String name;

@Schema(description = "아이콘", example = "⏰")
private String icon;
private String sound;

@Schema(description = "진동 여부", example = "true")
private Boolean isVibrate;

@Schema(description = "다시울림 간격", example = "5")
private Integer snoozeInterval;

@Schema(description = "다시울림 횟수", example = "3")
private Integer snoozeCnt;
@NotNull(message = "알람 시작시는 공백일 수 없습니다.")
private Time alarmTime;

@Schema(description = "알람 시간", example = "06:00")
@NotNull(message = "알람 시간은 공백일 수 없습니다.")
@Pattern(regexp = "^([01]?[0-9]|2[0-3]):[0-5][0-9]$", message = "HH:mm 형식이 아닙니다.")
private String alarmTime;

@Schema(description = "월요일 울림 여부", example = "false")
private Boolean monday;

@Schema(description = "화요일 울림 여부", example = "false")
private Boolean tuesday;

@Schema(description = "수요일 울림 여부", example = "false")
private Boolean wednesday;

@Schema(description = "목요일 울림 여부", example = "false")
private Boolean thursday;

@Schema(description = "금요일 울림 여부", example = "false")
private Boolean friday;

@Schema(description = "토요일 울림 여부", example = "false")
private Boolean saturday;

@Schema(description = "일요일 울림 여부", example = "false")
private Boolean sunday;

@Schema(description = "알람 활성화 여부", example = "true")
private Boolean isActivated;
}
Loading