-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from GApple-T/handle-exception
π::νμκ°μ μ€λ₯ νΈλ€λ§ μΆκ°
- Loading branch information
Showing
17 changed files
with
212 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/gapple/weeingback/domain/diary/controller/DiaryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.gapple.weeingback.domain.diary.controller; | ||
|
||
import com.gapple.weeingback.domain.diary.entity.dto.request.DiarySubmitRequest; | ||
import com.gapple.weeingback.domain.diary.service.DiaryService; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/diary") | ||
@RequiredArgsConstructor | ||
public class DiaryController { | ||
private final DiaryService diaryService; | ||
@PostMapping | ||
public ResponseEntity submitDiary(@Valid @RequestBody DiarySubmitRequest request){ | ||
return diaryService.submitDiary(request); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/gapple/weeingback/domain/diary/entity/Diary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.gapple.weeingback.domain.diary.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
import java.util.UUID; | ||
|
||
@Table | ||
@Entity | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Diary { | ||
@Id | ||
@GeneratedValue(generator = "uuid2", strategy = GenerationType.IDENTITY) | ||
@GenericGenerator(name="uuid2", strategy = "uuid2") | ||
private UUID id; | ||
|
||
@Column | ||
private String title; | ||
|
||
@Column | ||
private String description; | ||
|
||
@Column | ||
private Long accessRange; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/gapple/weeingback/domain/diary/entity/dto/request/DiarySubmitRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.gapple.weeingback.domain.diary.entity.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class DiarySubmitRequest { | ||
private Long accessRange; | ||
|
||
private String title; | ||
|
||
private String description; | ||
} |
12 changes: 12 additions & 0 deletions
12
...main/java/com/gapple/weeingback/domain/diary/entity/dto/response/DiarySubmitResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.gapple.weeingback.domain.diary.entity.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class DiarySubmitResponse { | ||
private String success; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/gapple/weeingback/domain/diary/repository/DiaryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.gapple.weeingback.domain.diary.repository; | ||
|
||
import com.gapple.weeingback.domain.diary.entity.Diary; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface DiaryRepository extends JpaRepository<Diary, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/gapple/weeingback/domain/diary/service/DiaryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.gapple.weeingback.domain.diary.service; | ||
|
||
import com.gapple.weeingback.domain.diary.entity.dto.request.DiarySubmitRequest; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
public interface DiaryService { | ||
ResponseEntity submitDiary(DiarySubmitRequest request); | ||
} |
40 changes: 40 additions & 0 deletions
40
...main/java/com/gapple/weeingback/domain/diary/service/implementation/DiaryServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.gapple.weeingback.domain.diary.service.implementation; | ||
|
||
import com.gapple.weeingback.domain.diary.entity.Diary; | ||
import com.gapple.weeingback.domain.diary.entity.dto.request.DiarySubmitRequest; | ||
import com.gapple.weeingback.domain.diary.entity.dto.response.DiarySubmitResponse; | ||
import com.gapple.weeingback.domain.diary.repository.DiaryRepository; | ||
import com.gapple.weeingback.domain.diary.service.DiaryService; | ||
import com.gapple.weeingback.domain.member.entity.Member; | ||
import com.gapple.weeingback.domain.member.repository.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DiaryServiceImpl implements DiaryService { | ||
private final DiaryRepository diaryRepository; | ||
private final MemberRepository memberRepository; | ||
@Override | ||
public ResponseEntity<DiarySubmitResponse> submitDiary(DiarySubmitRequest request) { | ||
String id = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
Member member = memberRepository.findMemberById(UUID.fromString(id)); | ||
|
||
Diary diary = Diary.builder() | ||
.title(request.getTitle()) | ||
.description(request.getDescription()) | ||
.accessRange(request.getAccessRange()) | ||
.build(); | ||
|
||
member.addDiary(diary); | ||
|
||
diaryRepository.save(diary); | ||
memberRepository.save(member); | ||
|
||
return ResponseEntity.ok().body(new DiarySubmitResponse("ok")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/gapple/weeingback/global/email/service/EmailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.gapple.weeingback.global.email.service; | ||
|
||
public interface EmailService { | ||
String sendMail(String to); | ||
String sendAuth(String to); | ||
String createCode(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/gapple/weeingback/global/exception/MemberExistsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.gapple.weeingback.global.exception; | ||
|
||
public class MemberExistsException extends RuntimeException { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/gapple/weeingback/global/exception/MemberNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.gapple.weeingback.global.exception; | ||
|
||
public class MemberNotFoundException extends RuntimeException { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/gapple/weeingback/global/exception/PasswordNotMatchException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.gapple.weeingback.global.exception; | ||
|
||
public class PasswordNotMatchException extends RuntimeException { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/gapple/weeingback/global/handler/GlobalExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.gapple.weeingback.global.handler; | ||
|
||
import com.gapple.weeingback.global.exception.MemberExistsException; | ||
import com.gapple.weeingback.global.exception.MemberNotFoundException; | ||
import com.gapple.weeingback.global.exception.PasswordNotMatchException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
@ExceptionHandler(PasswordNotMatchException.class) | ||
public ResponseEntity<HttpStatus> handleMethodPasswordNotMatchException() { | ||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
@ExceptionHandler(MemberNotFoundException.class) | ||
public ResponseEntity<HttpStatus> handleMethodMemberNotFound() { | ||
return new ResponseEntity<>(HttpStatus.NOT_FOUND); | ||
} | ||
|
||
@ExceptionHandler(MemberExistsException.class) | ||
public ResponseEntity<HttpStatus> handleMethodMemberExistsException(){ | ||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
} | ||
} |