Topic and post creating, editing, and deleting

This commit is contained in:
Jeremy Ellison
2011-01-11 12:32:18 -05:00
parent b01805384d
commit 378aaac12b
36 changed files with 1169 additions and 124 deletions

View File

@@ -0,0 +1,30 @@
//
// DBPost.h
// DiscussionBoard
//
// Created by Jeremy Ellison on 1/7/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <RestKit/CoreData/CoreData.h>
@interface DBPost : RKManagedObject {
UIImage* _newAttachment;
}
@property (nonatomic, retain) NSString* attachmentContentType;
@property (nonatomic, retain) NSString* attachmentFileName;
@property (nonatomic, retain) NSNumber* attachmentFileSize;
@property (nonatomic, retain) NSString* attachmentPath;
@property (nonatomic, retain) NSDate* attachmentUpdatedAt;
@property (nonatomic, retain) NSString* body;
@property (nonatomic, retain) NSDate* createdAt;
@property (nonatomic, retain) NSNumber* topicID;
@property (nonatomic, retain) NSDate* updatedAt;
@property (nonatomic, retain) NSNumber* userID;
@property (nonatomic, retain) NSNumber* postID;
@property (nonatomic, retain) UIImage* newAttachment;
@end

View File

@@ -0,0 +1,61 @@
//
// DBPost.m
// DiscussionBoard
//
// Created by Jeremy Ellison on 1/7/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "DBPost.h"
@implementation DBPost
@dynamic attachmentContentType;
@dynamic attachmentFileName;
@dynamic attachmentFileSize;
@dynamic attachmentPath;
@dynamic attachmentUpdatedAt;
@dynamic body;
@dynamic createdAt;
@dynamic topicID;
@dynamic updatedAt;
@dynamic userID;
@dynamic postID;
@synthesize newAttachment = _newAttachment;
+ (NSDictionary*)elementToPropertyMappings {
return [NSDictionary dictionaryWithKeysAndObjects:
@"id",@"postID",
@"topic_id",@"topicID",
@"user_id",@"userID",
@"created_at",@"createdAt",
@"updated_at",@"updatedAt",
@"attachment_content_type", @"attachmentContentType",
@"attachment_file_name", @"attachmentFileName",
@"attachment_file_size", @"attachmentFileSize",
@"attachment_path", @"attachmentPath",
@"attachment_updated_at", @"attachmentUpdatedAt",
@"body", @"body",
nil];
}
+ (NSString*)primaryKeyProperty {
return @"postID";
}
- (NSDictionary*)paramsForSerialization {
RKParams* params = [RKParams params];
[params setValue:self.body forParam:@"post[body]"];
if (_newAttachment) {
NSData* data = UIImagePNGRepresentation(_newAttachment);
NSLog(@"Data Size: %d", [data length]);
[params setData:data MIMEType:@"application/octet-stream" forParam:@"topic[attachment]"];
}
// Suppress warning. todo: should this method return an <RKRequestSerializable> by default?
return (NSDictionary*)params;
}
@end

View File

@@ -0,0 +1,22 @@
//
// DBTopic.h
// DiscussionBoard
//
// Created by Daniel Hammond on 1/7/11.
// Copyright 2011 Two Toasters. All rights reserved.
//
#import <RestKit/RestKit.h>
#import <RestKit/CoreData/CoreData.h>
@interface DBTopic : RKManagedObject {
}
@property (nonatomic, retain) NSNumber* topicID;
@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) NSNumber* userID;
@property (nonatomic, retain) NSDate* createdAt;
@property (nonatomic, retain) NSDate* updatedAt;
@end

View File

@@ -0,0 +1,41 @@
//
// DBTopic.m
// DiscussionBoard
//
// Created by Daniel Hammond on 1/7/11.
// Copyright 2011 Two Toasters. All rights reserved.
//
#import "DBTopic.h"
@implementation DBTopic
@dynamic topicID;
@dynamic name;
@dynamic userID;
@dynamic createdAt;
@dynamic updatedAt;
#pragma mark RKObjectMappable methods
+ (NSDictionary*)elementToPropertyMappings {
return [NSDictionary dictionaryWithKeysAndObjects:
@"id",@"topicID",
@"name",@"name",
@"user_id",@"userID",
@"created_at",@"createdAt",
@"updated_at",@"updatedAt",
nil];
}
+ (NSString*)primaryKeyProperty {
return @"topicID";
}
- (NSDictionary*)paramsForSerialization {
return [NSDictionary dictionaryWithObjectsAndKeys:
self.name, @"topic[name]", nil];
}
@end

View File

@@ -0,0 +1,30 @@
//
// DBUser.h
// DiscussionBoard
//
// Created by Jeremy Ellison on 1/10/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <RestKit/RestKit.h>
#import <RestKit/CoreData/CoreData.h>
@interface DBUser : RKManagedObject {
// Transient. Used for login & signup
NSString* _password;
NSString* _passwordConfirmation;
}
@property (nonatomic, retain) NSString* email;
@property (nonatomic, retain) NSString* login;
// Access Token will only be populated on a logged in user.
@property (nonatomic, retain) NSString* singleAccessToken;
@property (nonatomic, retain) NSNumber* userID;
@property (nonatomic, retain) NSString* password;
@property (nonatomic, retain) NSString* passwordConfirmation;
+ (DBUser*)currentUser;
+ (void)logout;
@end

View File

@@ -0,0 +1,67 @@
//
// DBUser.m
// DiscussionBoard
//
// Created by Jeremy Ellison on 1/10/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "DBUser.h"
@implementation DBUser
@dynamic email;
@dynamic login;
@dynamic singleAccessToken;
@dynamic userID;
@synthesize password = _password;
@synthesize passwordConfirmation = _passwordConfirmation;
+ (NSDictionary*)elementToPropertyMappings {
return [NSDictionary dictionaryWithKeysAndObjects:
@"id",@"userID",
@"email",@"email",
@"login",@"login",
@"single_access_token",@"singleAccessToken",
@"password", @"password",
@"password_confirmation", @"passwordConfirmation",
nil];
}
+ (NSString*)primaryKeyProperty {
return @"userID";
}
+ (DBUser*)currentUser {
id userID = [[NSUserDefaults standardUserDefaults] objectForKey:kCurrentUserIDKey];
return [self objectWithPrimaryKeyValue:userID];
}
+ (void)logout {
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:kCurrentUserIDKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:kUserLoggedOutNotificationName object:nil];
}
- (void)dealloc {
[_password release];
[_passwordConfirmation release];
[super dealloc];
}
- (NSDictionary*)paramsForSerialization {
if (_passwordConfirmation) {
return [NSDictionary dictionaryWithObjectsAndKeys:
self.email, @"user[email]",
self.login, @"user[login]",
self.password, @"user[password]",
self.passwordConfirmation, @"user[password_confirmation]", nil];
}
return [NSDictionary dictionaryWithObjectsAndKeys:
self.login, @"user[login]",
self.password, @"user[password]", nil];
}
@end