Skip to content

Commit

Permalink
"tweet" button added
Browse files Browse the repository at this point in the history
  • Loading branch information
ZheniaTrochun committed May 9, 2018
1 parent 63f9a14 commit 41d385e
Show file tree
Hide file tree
Showing 22 changed files with 338 additions and 174 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
/nbdist/
/.nb-gradle/

*.log
/logs/
/db/
14 changes: 13 additions & 1 deletion front/read-more/src/components/Book.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</md-card-content>

<md-card-actions>
<md-button class="md-primary" v-if="state" @click="tweet">Tweet it!</md-button>
<md-button class="md-primary" v-if="book.id" @click="showComments = true">Comments({{book.reviewsLength}})</md-button>
<md-button class="md-primary" v-if="book.id" @click="showExtended = true">Show extended</md-button>
<md-button class="md-primary" v-if="enableProcess" @click="toStarted(book)">{{ processText }}</md-button>
Expand Down Expand Up @@ -47,7 +48,9 @@
export default {
components: {
CommentList,
BookExt},
BookExt
},
name: 'book',
props: {
Expand All @@ -74,6 +77,10 @@
deleteUrl: {
type: String,
required: false
},
state: {
type: String,
required: false
}
},
Expand Down Expand Up @@ -102,6 +109,11 @@
})
.then((res) => this.$emit('removed', book))
.catch((err) => console.error(err))
},
tweet() {
axios.post('/twitter/tweet/book?state=' + this.state + '&bookId=' + this.book.id)
.then((res) => console.log(res))
}
},
Expand Down
1 change: 1 addition & 0 deletions front/read-more/src/components/UserFinished.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
deleteUrl="/book/state/"
processText="Start"
processUrl="/book/state/finished"
state="FINISHED"
@processed="onRemoved"
@removed="onRemoved"/>
</div>
Expand Down
1 change: 1 addition & 0 deletions front/read-more/src/components/UserProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
deleteUrl="/book/state/"
processText="Finish"
processUrl="/book/state/finished"
state="IN_PROGRESS"
@processed="onRemoved"
@removed="onRemoved"/>
</div>
Expand Down
1 change: 1 addition & 0 deletions front/read-more/src/components/UserTodos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
deleteUrl="/book/state/"
processText="Start"
processUrl="/book/state/progress"
state="TODO"
@processed="onRemoved"
@removed="onRemoved"/>
</div>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
package com.yevhenii.kpi.readmore.controller;

import com.yevhenii.kpi.readmore.service.OAuthSignUpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class OAuthSignUpController {
public interface OAuthSignUpController {

private final OAuthSignUpService signUpService;

@Autowired
public OAuthSignUpController(OAuthSignUpService signUpService) {
this.signUpService = signUpService;
}

// todo add dao
@RequestMapping("/signup")
public ModelAndView signup(WebRequest request) {

if (signUpService.signup(request)) {
return new ModelAndView("redirect:/");
} else {
return new ModelAndView("redirect:/error");
}
}
ModelAndView signup(WebRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.yevhenii.kpi.readmore.controller;

import com.yevhenii.kpi.readmore.service.OAuthSignUpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class OAuthSignUpControllerImpl implements OAuthSignUpController {

private final OAuthSignUpService signUpService;

@Autowired
public OAuthSignUpControllerImpl(OAuthSignUpService signUpService) {
this.signUpService = signUpService;
}

@Autowired
@RequestMapping("/signup")
public ModelAndView signup(WebRequest request) {

return signUpService.signup(request) ?
new ModelAndView("redirect:/") : new ModelAndView("redirect:/error");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,53 +1,11 @@
package com.yevhenii.kpi.readmore.controller;

import com.yevhenii.kpi.readmore.utils.TwitterUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import com.yevhenii.kpi.readmore.model.State;
import org.springframework.http.ResponseEntity;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.twitter.api.Twitter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
public interface TwitterController {

@RestController
@RequestMapping("/twitter")
public class TwitterController {
ResponseEntity<Void> tweetList(State state);

private final Twitter twitter;

private final ConnectionRepository connectionRepository;

@Value("${spring.social.twitter.appId}")
String consumerKey;
@Value("${spring.social.twitter.appSecret}")
String consumerSecret;

private final TwitterUtils twitterUtils;

@Autowired
public TwitterController(Twitter twitter, ConnectionRepository connectionRepository, TwitterUtils twitterUtils) {
this.twitter = twitter;
this.connectionRepository = connectionRepository;
this.twitterUtils = twitterUtils;
}

@RequestMapping(method = RequestMethod.GET, value = "/friends")
public ResponseEntity<List<String>> friends() {

return ResponseEntity.ok(twitterUtils.getFriendNames());
}

// todo refactor
@RequestMapping(method = RequestMethod.GET, value = "/tweet")
public ResponseEntity<Void> tweet() {

return new ResponseEntity<>(
twitterUtils.tweet("Read More!").getText().equals("Read More!") ?
HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR
);
}
ResponseEntity<Void> tweetBook(State state, Long bookId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.yevhenii.kpi.readmore.controller;

import com.yevhenii.kpi.readmore.model.State;
import com.yevhenii.kpi.readmore.service.TwitterService;
import com.yevhenii.kpi.readmore.utils.ControllerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.twitter.api.Twitter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/twitter")
public class TwitterControllerImpl implements TwitterController {

private final Twitter twitter;

private final ConnectionRepository connectionRepository;

@Value("${spring.social.twitter.appId}")
String consumerKey;
@Value("${spring.social.twitter.appSecret}")
String consumerSecret;

private final TwitterService twitterService;

@Autowired
public TwitterControllerImpl(Twitter twitter,
ConnectionRepository connectionRepository,
TwitterService twitterService) {
this.twitter = twitter;
this.connectionRepository = connectionRepository;
this.twitterService = twitterService;
}

@RequestMapping(method = RequestMethod.GET, value = "/friends")
public ResponseEntity<List<String>> friends() {

return ResponseEntity.ok(twitterService.getFriendNames());
}

// todo refactor
@RequestMapping(method = RequestMethod.GET, value = "/tweet")
public ResponseEntity<Void> tweet() {

return new ResponseEntity<>(
twitterService.tweet("Read More!").getText().equals("Read More!") ?
HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR
);
}

@Override
@RequestMapping(method = RequestMethod.POST, value = "/tweet/list")
public ResponseEntity<Void> tweetList(@RequestParam State state) {

return ControllerUtils.okOrBadRequest(twitterService.tweetList(state));
}

@Override
@RequestMapping(method = RequestMethod.POST, value = "/tweet/book")
public ResponseEntity<Void> tweetBook(@RequestParam State state, @RequestParam Long bookId) {

return ControllerUtils.okOrBadRequest(twitterService.tweetBook(state, bookId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;

import javax.servlet.http.HttpSession;

public interface UserController {

ResponseEntity<Void> register(UserRegisterDto registerDto, BindingResult result) throws RegistrationException;
Expand All @@ -14,5 +16,5 @@ public interface UserController {

ResponseEntity<UsernameResponse> getUsername();

// ResponseEntity<Void> askTwitter(WebRequest request);
ResponseEntity<Void> logout(HttpSession session);
}
Loading

0 comments on commit 41d385e

Please sign in to comment.