Permalink
Browse files

杂七杂八的一堆东西

  • Loading branch information...
1 parent 37873a9 commit f995859b580368cb5d79dd496eeeb184e380d2d3 @wendal wendal committed Feb 12, 2012
View
@@ -3,3 +3,4 @@
/.classpath
/.project
/ROOT/WEB-INF/classes/
+/conf/oauth_consumer.properties_dev
View
Binary file not shown.
@@ -0,0 +1,22 @@
+package org.nutz.ngqa.sdk;
+
+import java.util.List;
+
+import org.nutz.ngqa.bean.Answer;
+import org.nutz.ngqa.bean.Question;
+
+public interface NgqaClient {
+
+ String login(String openId);
+ void loginCallback(String code);
+ void anonymousLogin();
+ void logout();
+
+ Question createQuestion(Question question);
+ void addAnswer(int questionId, Answer answer);
+ void addTag(int questionId, String tag);
+ void removeTag(int questionId, String tag);
+
+ List<Question> listQuestions(int page, int pageSize);
+ List<Question> queryQuestions();//TODO
+}
@@ -0,0 +1,13 @@
+package org.nutz.ngqa.api;
+
+import org.nutz.ngqa.api.meta.AuthContext;
+import org.nutz.ngqa.bean.User;
+
+public interface AuthService {
+
+ boolean isAuth(AuthContext authContex);
+
+ boolean addAuth(User user, AuthContext authContext);
+
+ boolean removeAuth(User user, AuthContext authContext);
+}
@@ -0,0 +1,8 @@
+package org.nutz.ngqa.api;
+
+public interface CommonService {
+
+ public int seq(String seqNem);
+
+ void flash(Object obj);
+}
@@ -0,0 +1,5 @@
+package org.nutz.ngqa.api;
+
+public class EventService {
+
+}
@@ -0,0 +1,23 @@
+package org.nutz.ngqa.api;
+
+import java.util.List;
+
+import org.nutz.ngqa.api.meta.QuestionQuery;
+import org.nutz.ngqa.bean.Answer;
+import org.nutz.ngqa.bean.Question;
+import org.nutz.ngqa.bean.User;
+
+public interface QuestionManageService {
+
+ Question create(Question question);
+
+ void markDeleted(Question question);
+
+ List<Question> query(QuestionQuery query);
+
+ Question addAnswer(Question question, Answer answer);
+
+ void watch(Question question, User user);
+
+ void unwatch(Question question, User user);
+}
@@ -0,0 +1,12 @@
+package org.nutz.ngqa.api;
+
+import org.nutz.ngqa.bean.User;
+
+public interface UserManageService {
+
+ User find(User user);
+
+ User findOrAdd(User user);
+
+ User anonymous();
+}
@@ -0,0 +1,5 @@
+package org.nutz.ngqa.api.meta;
+
+public class AuthContext {
+
+}
@@ -0,0 +1,16 @@
+package org.nutz.ngqa.api.meta;
+
+import com.mongodb.BasicDBObject;
+
+public class QuestionQuery {
+
+ private BasicDBObject p = new BasicDBObject();
+
+
+
+ public static QuestionQuery id(int questionId){
+ QuestionQuery query = new QuestionQuery();
+ query.p.put("_id", questionId);
+ return query;
+ }
+}
@@ -0,0 +1,49 @@
+package org.nutz.ngqa.module;
+
+import java.awt.List;
+
+import org.nutz.ioc.annotation.InjectName;
+import org.nutz.ioc.loader.annotation.Inject;
+import org.nutz.ioc.loader.annotation.IocBean;
+import org.nutz.mongo.MongoDao;
+import org.nutz.mongo.util.MCur;
+import org.nutz.mongo.util.Moo;
+import org.nutz.mvc.annotation.At;
+import org.nutz.mvc.annotation.Attr;
+import org.nutz.mvc.annotation.By;
+import org.nutz.mvc.annotation.Filters;
+import org.nutz.mvc.filter.CheckSession;
+import org.nutz.ngqa.bean.Question;
+import org.nutz.ngqa.bean.User;
+import org.nutz.ngqa.service.CommonMongoService;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBRef;
+
+@IocBean(create="init")
+@InjectName
+@Filters({@By(type=CheckSession.class,args={"me", "/index.jsp"})})
+@At("/addon")
+public class AddonModule {
+
+ @At("/question/?/watch")
+ public void watch(int questionId, @Attr("me") User me) {
+ dao.update(Question.class, new BasicDBObject("_id", questionId), new BasicDBObject("$addToSet", new BasicDBObject("watchers", new DBRef(null, "user", me.getId()))));
+ }
+
+ @At("/question/?/unwatch")
+ public void unwatch(int questionId, @Attr("me") User me) {
+ dao.update(Question.class, new BasicDBObject("_id", questionId), new BasicDBObject("$pop", new BasicDBObject("watchers", new DBRef(null, "user", me.getId()))));
+ }
+
+
+
+ @Inject("java:$commons.dao()")
+ private MongoDao dao;
+
+ @Inject
+ private CommonMongoService commons;
+
+ public void init() {
+ }
+}

0 comments on commit f995859

Please sign in to comment.