Commit 9e73a5c9 authored by Manish Kumar's avatar Manish Kumar
Browse files

conflicts resolved

parents 18b5a6f8 45031fb6
export enum DiscourseOrdering {
DEFAULT = 'default',
CREATED = 'created',
ACTIVITY = 'activity',
VIEWS = 'views',
POSTS = 'posts',
CATEGORY = 'category',
LIKES = 'likes',
OP_LIKES = 'op_likes',
POSTERS = 'posters'
}
export interface DiscourseUserSuccess {
export interface DiscourseAuthUserSuccess {
success: boolean;
active: boolean;
message: string;
......
export interface DiscourseAuthUser {
user: {
id: number;
username: string;
name: string;
last_seen_at: string;
};
}
import { DiscourseCategory } from './discourse-category';
export interface DiscourseCategoryList {
category_list: {
can_create_category: boolean,
can_create_topic: boolean,
draft: boolean,
draft_key: string,
draft_sequence: number,
categories: DiscourseCategory[]
};
}
export interface DiscourseCategory {
id: number;
name: string;
color: string;
text_color: string;
slug: string;
topic_count: number;
post_count: number;
position: number;
description: string;
description_text: string;
topic_url: string;
logo_url: string;
background_url: string;
read_restricted: boolean;
permission: number;
notification_level: string;
can_edit: boolean;
topic_template: string;
has_children: boolean;
topics_day: number;
topics_week: number;
topics_month: number;
topics_year: number;
topics_all_time: number;
description_excerpt: string;
}
import { DiscoursePost } from './discourse-post';
export interface DiscoursePostLatest {
latest_posts: DiscoursePost[];
}
export interface DiscoursePost {
id: number;
name: string;
username: string;
avatar_template: string;
created_at: string;
cooked: string;
post_number: number;
post_type: number;
updated_at: string;
reply_count: number;
reply_to_post_number: { };
quote_count: number;
avg_time: { };
incoming_link_count: number;
reads: number;
score: number;
yours: boolean;
topic_id: number;
topic_slug: string;
display_username: string;
primary_group_name: { };
primary_group_flair_url: { };
primary_group_flair_bg_color: { };
primary_group_flair_color: { };
version: number;
can_edit: boolean;
can_delete: boolean;
can_recover: boolean;
can_wiki: boolean;
user_title: { };
raw: string;
actions_summary: [
{ }
];
moderator: boolean;
admin: boolean;
staff: boolean;
user_id: number;
hidden: boolean;
hidden_reason_id: { };
trust_level: number;
deleted_at: { };
user_deleted: boolean;
edit_reason: { };
can_view_edit_history: boolean;
wiki: boolean;
}
import { DiscourseUser } from './discourse-user';
import { DiscourseTopicList } from './discourse-topic-list';
export interface DiscourseTopicCollection {
users: DiscourseUser[];
topic_list: DiscourseTopicList;
}
import { DiscourseTopic } from './discourse-topic';
export interface DiscourseTopicList {
can_create_topic: boolean;
draft: {};
draft_key: string;
draft_sequence: {};
per_page: number;
topics: DiscourseTopic[];
}
import { DiscoursePost } from './discourse-post';
export interface DiscourseTopic {
post_stream: {
posts: DiscoursePost[];
stream: [
{}
]
};
timeline_lookup: [
{
number: [
{}
]
}
];
id: number;
title: string;
fancy_title: string;
posts_count: number;
created_at: string;
views: number;
reply_count: number;
participant_count: number;
like_count: number;
last_posted_at: {};
visible: boolean;
closed: boolean;
archived: boolean;
has_summary: boolean;
archetype: string;
slug: string;
category_id: number;
word_count: {};
deleted_at: {};
user_id: number;
draft: {};
draft_key: string;
draft_sequence: {};
unpinned: {};
pinned_globally: boolean;
pinned: boolean;
pinned_at: string;
pinned_until: {};
details: {
auto_close_at: {};
auto_close_hours: {};
auto_close_based_on_last_post: boolean;
created_by: {
id: number;
username: string;
avatar_template: string
};
last_poster: {
id: number;
username: string;
avatar_template: string
};
participants: [
{
id: number;
username: string;
avatar_template: string;
post_count: number
}
];
suggested_topics: DiscourseTopic[];
notification_level: number;
can_flag_topic: boolean
};
highest_post_number: number;
deleted_by: {};
actions_summary: [
{
id: number;
count: number;
hidden: boolean;
can_act: boolean
}
];
chunk_size: number;
bookmarked: {};
}
export interface DiscourseUserBadge {
id: number;
name: string;
description: string;
grant_count: number;
allow_title: boolean;
multiple_grant: boolean;
icon: string;
image: string;
listable: boolean;
enabled: boolean;
badge_grouping_id: number;
system: boolean;
long_description: string;
slug: string;
query: string;
trigger: number;
target_posts: boolean;
auto_revoke: boolean;
show_posts: boolean;
badge_type_id: number;
}
export interface DiscourseUser {
user: {
id: number;
username: string;
name: string;
last_seen_at: string;
};
id: number;
username: string;
avatar_template: string;
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse, HttpHeaders } from '@angular/common/http';
import { DiscourseUser } from '../interfaces/discourse-user';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { DiscourseAuthUser } from '../interfaces/discourse-auth-user';
import { DiscourseError } from '../interfaces/discourse-error';
import { environment } from '../../environments/environment';
import { DiscourseUserSuccess } from '../interfaces/discourse-user-success';
import { DiscourseAuthUserSuccess } from '../interfaces/discourse-auth-user-success';
@Injectable({
providedIn: 'root'
......@@ -45,11 +45,11 @@ export class DiscourseAuthService {
'Content-Type': 'application/json'
}
}
).subscribe(
(value: HttpResponse<DiscourseUserSuccess>) => {
).subscribe({
next: (value: HttpResponse<DiscourseAuthUserSuccess>) => {
succeded = value.status === 200;
}
);
});
}
return available && succeded;
......@@ -60,23 +60,17 @@ export class DiscourseAuthService {
* @param username - The username to be checked
*/
async getUsernameAvailable(username: string): Promise<boolean> {
const headers = new HttpHeaders()
.set('Api-Key', '7ceefc9a385125dee40cac1eb48181cbbcac63863895a40ff234efe627652b67')
.set('Api-Username', 'manish')
let response: DiscourseUserSuccess | DiscourseError;
let response: DiscourseAuthUserSuccess | DiscourseError;
this.http.get(
//'https://discourse.yana.help/categories.json'
//'https://cors-anywhere.herokuapp.com/https://discourse.yana.help/admin/users/list/active.json'
'https://cors-anywhere.herokuapp.com/https://discourse.yana.help/manish.json'
, {headers: headers}).subscribe(
(data: DiscourseUserSuccess | DiscourseError) => {
`https://discourse.yana.help/${username}.json`
).subscribe({
next: (data: DiscourseAuthUserSuccess | DiscourseError) => {
response = data;
console.log(response);
}
);
});
return !true;
return !response.hasOwnProperty('user');
}
/**
......
import { TestBed } from '@angular/core/testing';
import { DiscourseContentService } from './discourse-content.service';
import { DiscourseTopic } from '../interfaces/discourse-topic';
describe('DiscourseContentService', () => {
let service: DiscourseContentService;
function isTopic(obj: DiscourseTopic | any): obj is DiscourseTopic {
return (obj as DiscourseTopic).fancy_title !== undefined;
}
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(DiscourseContentService);
......@@ -13,4 +19,8 @@ describe('DiscourseContentService', () => {
it('should be created', () => {
expect(service).toBeTruthy();
});
it('get a Topic by Id', () => {
expect(isTopic(service.getTopic(0))).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DiscourseTopic } from '../interfaces/discourse-topic';
import { DiscoursePost } from '../interfaces/discourse-post';
import { DiscourseOrdering } from '../enums/discourse-ordering.enum';
import { DiscourseTopicCollection } from '../interfaces/discourse-topic-collection';
import { DiscoursePostLatest } from '../interfaces/discourse-post-latest';
@Injectable({
providedIn: 'root'
})
export class DiscourseContentService {
/**
* Handler for Discourse Authentication within the YANA framework.
* @param http - The handler for HTTP requests.
*/
constructor(private http: HttpClient) { }
/**
* Creates a Topic
* @param title - The title of the topic.
* @param raw - TODO: Find out WTF this is for here (required)
* @param [category=0] - The category the topic is a part of.
*/
createTopic(title: string, raw: string, category: number = 0): DiscourseTopic {
let response: DiscourseTopic;
this.http.post<DiscourseTopic>(
'https://discourse.yana.help/posts.json',
{
title,
raw,
category
},
{
headers: {
'Content-Type': 'application/json'
}
}
).subscribe({
next: (data: DiscourseTopic) => { response = data; }
});
return response;
}
/**
* Creates a Post
* @param topicId - The id of the topic this post is within.
* @param raw - The text of the post.
*/
createPost(topicId: number, raw: string) {
let response: DiscoursePost;
this.http.post<DiscoursePost>(
'https://discourse.yana.help/posts.json',
{
topic_id: topicId,
raw
},
{
headers: {
'Content-Type': 'application/json'
}
}
).subscribe({
next: (data: DiscoursePost) => { response = data; }
});
return response;
}
/**
* Gets a topic using it's id.
* @param topicId - The id of the topic this post is within.
*/
getTopic(topicId: number): DiscourseTopic {
let response: DiscourseTopic;
this.http.get<DiscourseTopic>(
`https://discourse.yana.help/t/${topicId}.json`
).subscribe(
(data: DiscourseTopic) =>
response = data
);
return response;
}
/**
* Gets a collection of topics that are currently considered at the top (most active / liked)
*/
getTopTopics(): DiscourseTopicCollection {
let response: DiscourseTopicCollection;
this.http.get<DiscourseTopicCollection>(
`https://discourse.yana.help/top.json`
).subscribe(
(data: DiscourseTopicCollection) =>
response = data
);
return response;
}
/**
* Gets a collection of topics given a certain order
* @param order - The order that the topics should be gotten by (ie. "default", "created", "activity", etc.)
* @param [ascending=false] - Whether the order should be reversed.
*/
getLatestTopicsByOrder(order: DiscourseOrdering, ascending: boolean = false): DiscourseTopicCollection {
let response: DiscourseTopicCollection;
this.http.get<DiscourseTopicCollection>(
`https://discourse.yana.help/latest.json?order=${order}&ascending=${ascending}`
).subscribe(
(data: DiscourseTopicCollection) =>
response = data
);
return response;
}
/**
* Gets a collection of posts regardless of topics that have been posted.
*/
getLatestPosts(): DiscoursePostLatest {
let response: DiscoursePostLatest;
this.http.get<DiscoursePostLatest>(
`https://discourse.yana.help/posts.json`
).subscribe(
(data: DiscoursePostLatest) =>
response = data
);
return response;
}
constructor() { }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment