forked from Team-Traveler/Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Team-Traveler:master' into feat/Team-Traveler#86
- Loading branch information
Showing
28 changed files
with
585 additions
and
66 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
44 changes: 0 additions & 44 deletions
44
src/main/java/com/example/traveler/controller/CommentController.java
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
src/main/java/com/example/traveler/controller/PostController.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,102 @@ | ||
package com.example.traveler.controller; | ||
|
||
|
||
import com.example.traveler.config.BaseException; | ||
import com.example.traveler.config.BaseResponse; | ||
import com.example.traveler.model.dto.CommentRequest; | ||
import com.example.traveler.model.dto.CommentResponse; | ||
import com.example.traveler.model.entity.Post; | ||
import com.example.traveler.service.CommentService; | ||
import com.example.traveler.service.PostService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/post") | ||
public class PostController { | ||
@Autowired | ||
private PostService postService; | ||
@Autowired | ||
private CommentService commentService; | ||
|
||
@PostMapping("/{pId}/comment") | ||
public BaseResponse<CommentResponse> saveComment(@RequestHeader("Authorization") String accessToken, @RequestBody CommentRequest commentRequest, @PathVariable("pId") long pId) { | ||
try { | ||
CommentResponse commentResponse = commentService.saveComment(accessToken, pId, commentRequest); | ||
return new BaseResponse<>(commentResponse); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
@GetMapping("/{pId}/comment") | ||
public BaseResponse<List<CommentResponse>> getAllComment(@PathVariable("pId") long pId) { | ||
try { | ||
List<CommentResponse> commentResponses = commentService.getAllComment(pId); | ||
return new BaseResponse<>(commentResponses); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
|
||
@GetMapping("") | ||
public BaseResponse<List<Post>> getAllPost(@RequestParam(value = "keyword", required = false) String keyword) { | ||
List<Post> postResponse; | ||
if (keyword == null) { | ||
try { | ||
postResponse = postService.getAllPost(); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} else { | ||
if (keyword.startsWith("#")) { | ||
try { | ||
postResponse = postService.searchByHashtag(keyword); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} else { | ||
try { | ||
postResponse = postService.searchByTitle(keyword); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
} | ||
return new BaseResponse<>(postResponse); | ||
|
||
} | ||
|
||
@PostMapping("/{pId}/like") | ||
public BaseResponse<String> likePost(@RequestHeader("Authorization") String accessToken, @PathVariable("pId") long pId) { | ||
try { | ||
int result = postService.likePost(accessToken, pId); | ||
if (result == 1) { | ||
return new BaseResponse<>("좋아요 취소 성공!"); | ||
} | ||
else { | ||
return new BaseResponse<>("좋아요 성공!"); | ||
} | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
@PostMapping("/{pId}/scrap") | ||
public BaseResponse<String> likeScrap(@RequestHeader("Authorization") String accessToken, @PathVariable("pId") long pId) { | ||
try { | ||
int result = postService.scrapPost(accessToken, pId); | ||
if (result == 1) { | ||
return new BaseResponse<>("찜 취소 성공!"); | ||
} | ||
else { | ||
return new BaseResponse<>("찜 성공!"); | ||
} | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
} |
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
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/traveler/model/dto/PostRequest.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,35 @@ | ||
package com.example.traveler.model.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
public class PostRequest { | ||
|
||
private String title; | ||
|
||
private List<String> hashtags; | ||
|
||
private String oneLineReview; | ||
|
||
private int what; | ||
|
||
private int hard; | ||
|
||
private int with; | ||
|
||
private double whatrating; | ||
|
||
private double hardrating; | ||
|
||
private double totalrating; | ||
|
||
private String goodPoints; | ||
|
||
private String badPoints; | ||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/example/traveler/model/dto/PostResponse.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,42 @@ | ||
package com.example.traveler.model.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
public class PostResponse { | ||
|
||
int pId; | ||
|
||
int tId; | ||
|
||
int uId; | ||
|
||
private String title; | ||
|
||
private List<String> hashtags; | ||
|
||
private String oneLineReview; | ||
|
||
private String location; | ||
|
||
private int what; | ||
|
||
private int hard; | ||
|
||
private int with; | ||
|
||
private double whatrating; | ||
|
||
private double hardrating; | ||
|
||
private double totalrating; | ||
|
||
private String goodPoints; | ||
|
||
private String badPoints; | ||
|
||
} |
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
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
Oops, something went wrong.